Spaces:
Sleeping
Sleeping
Commit
·
ff39ced
1
Parent(s):
25bc683
Basic interface
Browse files
app.py
CHANGED
@@ -1,7 +1,42 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
demo = gr.Interface(fn=test, inputs="text", outputs="text")
|
7 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
4 |
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("georgiyozhegov/calculator-8m")
|
6 |
+
model = AutoModelForCausalLM.from_pretrained("georgiyozhegov/calculator-8m")
|
7 |
+
|
8 |
+
def solve(problem):
|
9 |
+
prompt = f"find {problem}\nstep"
|
10 |
+
inputs = tokenizer(prompt, return_tensors="pt", return_token_type_ids=False)
|
11 |
+
|
12 |
+
with torch.no_grad():
|
13 |
+
outputs = model.generate(
|
14 |
+
input_ids=inputs["input_ids"],
|
15 |
+
attention_mask=inputs["attention_mask"],
|
16 |
+
max_length=32,
|
17 |
+
do_sample=True,
|
18 |
+
top_k=50,
|
19 |
+
top_p=0.98
|
20 |
+
)
|
21 |
+
|
22 |
+
count = 0
|
23 |
+
for index, token in enumerate(outputs[0]):
|
24 |
+
if token == 6: count += 1
|
25 |
+
if count >= 2: break
|
26 |
+
|
27 |
+
output = tokenizer.decode(outputs[0][:index])
|
28 |
+
return output
|
29 |
+
|
30 |
+
examples = [
|
31 |
+
["2 + 3"],
|
32 |
+
["10 / 0.5"],
|
33 |
+
]
|
34 |
+
|
35 |
+
demo = gr.Interface(
|
36 |
+
fn=solve,
|
37 |
+
inputs=gr.Textbox(lines=5, label="Problem"),
|
38 |
+
outputs=gr.Textbox(label="Solution"),
|
39 |
+
examples=examples,
|
40 |
+
)
|
41 |
|
|
|
42 |
demo.launch()
|