Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -50,7 +50,7 @@ def split_string_into_max_six_chunks(input_str: str) -> list[str]:
|
|
50 |
return []
|
51 |
|
52 |
# Define the maximum number of chunks desired
|
53 |
-
max_chunks =
|
54 |
|
55 |
# If the number of lines is already within the limit, return the lines as they are
|
56 |
if num_lines <= max_chunks:
|
@@ -84,10 +84,27 @@ print("Ednd dowload")
|
|
84 |
# Loading the tokenizer once, because re-loading it takes about 1.5 seconds each time
|
85 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
86 |
|
87 |
-
|
88 |
# Only assign GPU if cache not used
|
89 |
@spaces.GPU
|
90 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
all_judge = ""
|
92 |
reasoning_chunk = split_string_into_max_six_chunks(input_cot)
|
93 |
previsous_step_string = ""
|
@@ -96,23 +113,11 @@ def translate(input_question,input_cot):
|
|
96 |
cur_step = "Step {}: ".format(index) + r
|
97 |
input_string = template.format(input_question,previsous_step_string,cur_step)
|
98 |
print(input_string)
|
99 |
-
|
100 |
-
tokenizer(input_string, return_tensors="pt")
|
101 |
-
.input_ids[0]
|
102 |
-
.cpu()
|
103 |
-
.numpy()
|
104 |
-
.tolist()
|
105 |
-
)
|
106 |
-
translated_chunk = model.generate(
|
107 |
-
input_ids=torch.tensor([input_tokens]).to(device),
|
108 |
-
max_length=len(input_tokens) + 2048,
|
109 |
-
num_return_sequences=1,
|
110 |
-
)
|
111 |
-
full_output = tokenizer.decode(translated_chunk[0], skip_special_tokens=True)
|
112 |
-
full_output = full_output.replace(input_string,"")
|
113 |
previsous_step_string += "\n" + input_string
|
114 |
-
all_judge += "Step {}: ".format(index) +
|
115 |
-
print(
|
|
|
116 |
return all_judge
|
117 |
|
118 |
|
@@ -137,7 +142,7 @@ with gr.Blocks() as demo:
|
|
137 |
with gr.Row():
|
138 |
output = gr.Textbox(label="Output Text", lines=6)
|
139 |
btn.click(
|
140 |
-
|
141 |
inputs=[input_question,input_cot],
|
142 |
outputs=output,
|
143 |
)
|
|
|
50 |
return []
|
51 |
|
52 |
# Define the maximum number of chunks desired
|
53 |
+
max_chunks = 5
|
54 |
|
55 |
# If the number of lines is already within the limit, return the lines as they are
|
56 |
if num_lines <= max_chunks:
|
|
|
84 |
# Loading the tokenizer once, because re-loading it takes about 1.5 seconds each time
|
85 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
86 |
|
87 |
+
|
88 |
# Only assign GPU if cache not used
|
89 |
@spaces.GPU
|
90 |
+
def working(input_text):
|
91 |
+
input_tokens = (
|
92 |
+
tokenizer(input_text, return_tensors="pt")
|
93 |
+
.input_ids[0]
|
94 |
+
.cpu()
|
95 |
+
.numpy()
|
96 |
+
.tolist()
|
97 |
+
)
|
98 |
+
translated_chunk = model.generate(
|
99 |
+
input_ids=torch.tensor([input_tokens]).to(device),
|
100 |
+
max_length=len(input_tokens) + 2048,
|
101 |
+
num_return_sequences=1,
|
102 |
+
)
|
103 |
+
full_output = tokenizer.decode(translated_chunk[0], skip_special_tokens=True)
|
104 |
+
full_output = full_output.replace(input_text,"")
|
105 |
+
return full_output
|
106 |
+
|
107 |
+
def Judge(input_question,input_cot):
|
108 |
all_judge = ""
|
109 |
reasoning_chunk = split_string_into_max_six_chunks(input_cot)
|
110 |
previsous_step_string = ""
|
|
|
113 |
cur_step = "Step {}: ".format(index) + r
|
114 |
input_string = template.format(input_question,previsous_step_string,cur_step)
|
115 |
print(input_string)
|
116 |
+
output = working(input_string)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
previsous_step_string += "\n" + input_string
|
118 |
+
all_judge += "Step {}: ".format(index) + output + "\n\n"
|
119 |
+
print(output)
|
120 |
+
print("============================\n\n")
|
121 |
return all_judge
|
122 |
|
123 |
|
|
|
142 |
with gr.Row():
|
143 |
output = gr.Textbox(label="Output Text", lines=6)
|
144 |
btn.click(
|
145 |
+
Judge,
|
146 |
inputs=[input_question,input_cot],
|
147 |
outputs=output,
|
148 |
)
|