Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,12 @@
|
|
| 1 |
"""
|
| 2 |
-
Estella Explainer β HuggingFace Spaces Demo
|
| 3 |
A math reading coach for grades 3β8, based on Usable Math (usablemath.org)
|
| 4 |
-
Model: sgattup/EstellaExplainerLLM (Gemma 4 E4B fine-tuned)
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
"""
|
| 8 |
|
| 9 |
import gradio as gr
|
|
@@ -35,7 +38,6 @@ EXAMPLES = [
|
|
| 35 |
"The perimeter of a square is 36 inches. What is the length of one side?",
|
| 36 |
]
|
| 37 |
|
| 38 |
-
# Load model once at startup
|
| 39 |
print(f"Loading {MODEL_ID}...")
|
| 40 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
|
| 41 |
model = AutoModelForCausalLM.from_pretrained(
|
|
@@ -44,15 +46,16 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
| 44 |
device_map="auto"
|
| 45 |
)
|
| 46 |
model.eval()
|
| 47 |
-
print("
|
| 48 |
|
| 49 |
|
| 50 |
-
def ask_estella(
|
| 51 |
-
|
| 52 |
-
|
|
|
|
| 53 |
|
| 54 |
messages = [
|
| 55 |
-
{"role": "user", "content": SYSTEM_PROMPT + f"\n\n### Math Problem:\n{
|
| 56 |
]
|
| 57 |
text = tokenizer.apply_chat_template(
|
| 58 |
messages,
|
|
@@ -76,50 +79,18 @@ def ask_estella(problem: str) -> str:
|
|
| 76 |
return hint
|
| 77 |
|
| 78 |
|
| 79 |
-
# Gradio
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
*"My job is to explain math questions clearly so you know what you are supposed to do to solve the problem."*
|
| 86 |
-
|
| 87 |
-
Estella helps students **understand** what a math problem is asking β without solving it.
|
| 88 |
-
Based on [Usable Math](https://usablemath.org), an open educational resource from UMass Amherst.
|
| 89 |
-
|
| 90 |
-
---
|
| 91 |
-
""")
|
| 92 |
-
|
| 93 |
-
with gr.Row():
|
| 94 |
-
with gr.Column(scale=2):
|
| 95 |
-
problem_input = gr.Textbox(
|
| 96 |
-
label="Math Word Problem",
|
| 97 |
-
placeholder="Type or paste a math problem here...",
|
| 98 |
-
lines=4
|
| 99 |
-
)
|
| 100 |
-
submit_btn = gr.Button("Ask Estella", variant="primary")
|
| 101 |
-
|
| 102 |
-
with gr.Column(scale=2):
|
| 103 |
-
hint_output = gr.Textbox(
|
| 104 |
-
label="Estella's Hint",
|
| 105 |
-
lines=4,
|
| 106 |
-
interactive=False
|
| 107 |
-
)
|
| 108 |
-
|
| 109 |
-
gr.Examples(
|
| 110 |
-
examples=EXAMPLES,
|
| 111 |
-
inputs=problem_input,
|
| 112 |
-
label="Try these examples"
|
| 113 |
-
)
|
| 114 |
|
| 115 |
-
|
| 116 |
-
---
|
| 117 |
-
**Model:** [sgattup/EstellaExplainerLLM](https://huggingface.co/sgattup/EstellaExplainerLLM) Β· Fine-tuned Gemma 4 E4B via QLoRA
|
| 118 |
-
**Project:** [Usable Math](https://usablemath.org) Β· UMass Amherst College of Education
|
| 119 |
-
**Note:** Estella explains problems β she does not solve them or show answers.
|
| 120 |
-
""")
|
| 121 |
|
| 122 |
-
|
| 123 |
-
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
demo.launch()
|
|
|
|
| 1 |
"""
|
| 2 |
+
Estella Explainer β HuggingFace Spaces / Lightning AI Demo
|
| 3 |
A math reading coach for grades 3β8, based on Usable Math (usablemath.org)
|
|
|
|
| 4 |
|
| 5 |
+
Developed by Sai Gattupalli, PhD
|
| 6 |
+
College of Education, University of Massachusetts Amherst
|
| 7 |
+
Principal Scientist, Society and AI Research Group
|
| 8 |
+
|
| 9 |
+
Model: sgattup/EstellaExplainerLLM (Gemma 4 E4B fine-tuned)
|
| 10 |
"""
|
| 11 |
|
| 12 |
import gradio as gr
|
|
|
|
| 38 |
"The perimeter of a square is 36 inches. What is the length of one side?",
|
| 39 |
]
|
| 40 |
|
|
|
|
| 41 |
print(f"Loading {MODEL_ID}...")
|
| 42 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
|
| 43 |
model = AutoModelForCausalLM.from_pretrained(
|
|
|
|
| 46 |
device_map="auto"
|
| 47 |
)
|
| 48 |
model.eval()
|
| 49 |
+
print("Estella is ready.")
|
| 50 |
|
| 51 |
|
| 52 |
+
def ask_estella(message: str, history: list) -> str:
|
| 53 |
+
"""Chat function β history is kept for UI display only; Estella gives one hint per problem."""
|
| 54 |
+
if not message.strip():
|
| 55 |
+
return "Please type a math word problem and I'll help explain what it's asking!"
|
| 56 |
|
| 57 |
messages = [
|
| 58 |
+
{"role": "user", "content": SYSTEM_PROMPT + f"\n\n### Math Problem:\n{message.strip()}\n\n### Estella's Hint:"}
|
| 59 |
]
|
| 60 |
text = tokenizer.apply_chat_template(
|
| 61 |
messages,
|
|
|
|
| 79 |
return hint
|
| 80 |
|
| 81 |
|
| 82 |
+
# Gradio ChatInterface
|
| 83 |
+
demo = gr.ChatInterface(
|
| 84 |
+
fn=ask_estella,
|
| 85 |
+
title="π Estella Explainer β Math Reading Coach",
|
| 86 |
+
description="""**"My job is to explain math questions clearly so you know what you are supposed to do to solve the problem."**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
+
Type any math word problem (grades 3β8) and Estella will help you understand what it's asking β without solving it.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
+
*Developed by [Sai Gattupalli, PhD](https://huggingface.co/sgattup) Β· UMass Amherst College of Education Β· [Society and AI Research Group](https://societyandai.org) Β· Based on [Usable Math](https://usablemath.org)*""",
|
| 91 |
+
examples=EXAMPLES,
|
| 92 |
+
cache_examples=False,
|
| 93 |
+
type="messages",
|
| 94 |
+
)
|
| 95 |
|
| 96 |
demo.launch()
|