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()