quynhthames commited on
Commit
f78ddde
·
1 Parent(s): ea69eac
Files changed (2) hide show
  1. app.py +34 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import T5Tokenizer, T5ForConditionalGeneration
3
+ import torch
4
+
5
+ # Load your model from Hugging Face
6
+ tokenizer = T5Tokenizer.from_pretrained("https://huggingface.co/quynhthames/vietnamese-math-solver")
7
+ model = T5ForConditionalGeneration.from_pretrained("https://huggingface.co/quynhthames/vietnamese-math-solver")
8
+
9
+ #Use Cuda if avalible.
10
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
11
+ model.to(device)
12
+
13
+ def solve_math_problem(problem):
14
+ # Tokenize the input
15
+ inputs = tokenizer(problem, return_tensors="pt").to(device)
16
+
17
+ # Generate the solution
18
+ outputs = model.generate(**inputs)
19
+
20
+ # Decode the output
21
+ solution = tokenizer.decode(outputs[0], skip_special_tokens=True)
22
+
23
+ return solution
24
+
25
+ # Create the Gradio interface
26
+ iface = gr.Interface(
27
+ fn=solve_math_problem,
28
+ inputs="text",
29
+ outputs="text",
30
+ title="Math Problem Solver",
31
+ description="Enter a math problem and get the solution."
32
+ )
33
+
34
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ transformers
3
+ torch