File size: 1,027 Bytes
f78ddde 3d16210 378a5f3 b472b59 f78ddde cac738b f78ddde cac738b f78ddde cac738b f78ddde cac738b f78ddde |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
import gradio as gr
from transformers import T5Tokenizer, T5ForConditionalGeneration
import torch
## Load your model from Hugging Face
tokenizer = T5Tokenizer.from_pretrained("quynhthames/vietnamese-math-solver")
model = T5ForConditionalGeneration.from_pretrained("quynhthames/vietnamese-math-solver")
#Use Cuda if avalible.
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)
def solve_math_problem(problem):
# Tokenize the input
inputs = tokenizer(problem, return_tensors="pt", padding=True, truncation=True, max_length=64).to(device)
# Generate the solution
outputs = model.generate(**inputs, max_length=128)
# Decode the output
solution = tokenizer.batch_decode(outputs, skip_special_tokens=True)
return solution
# Create the Gradio interface
iface = gr.Interface(
fn=solve_math_problem,
inputs="text",
outputs="text",
title="Vietnamese Math Problem Solver",
description="Enter a math problem and get the solution."
)
iface.launch() |