Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
| 3 |
+
|
| 4 |
+
# Load the model and tokenizer
|
| 5 |
+
model_name = "google/flan-t5-base" # Free LLM from Hugging Face
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
| 8 |
+
|
| 9 |
+
def solve_math_problem(problem):
|
| 10 |
+
inputs = tokenizer.encode(problem, return_tensors="pt")
|
| 11 |
+
outputs = model.generate(inputs, max_length=500)
|
| 12 |
+
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 13 |
+
|
| 14 |
+
# Breaking it down to step-by-step
|
| 15 |
+
steps = "Step-by-Step: " + result
|
| 16 |
+
return steps
|
| 17 |
+
|
| 18 |
+
# Gradio interface
|
| 19 |
+
iface = gr.Interface(
|
| 20 |
+
fn=solve_math_problem,
|
| 21 |
+
inputs="text",
|
| 22 |
+
outputs="text",
|
| 23 |
+
title="Maths Step-by-Step Solver with LLM",
|
| 24 |
+
description="Enter a maths problem and get a step-by-step solution using LLM."
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
iface.launch()
|