sgattup commited on
Commit
e37e0b0
Β·
verified Β·
1 Parent(s): 879e902

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -52
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
- Deploy to a ZeroGPU Space for free GPU inference.
 
 
 
 
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("Model ready.")
48
 
49
 
50
- def ask_estella(problem: str) -> str:
51
- if not problem.strip():
52
- return "Please type a math word problem above."
 
53
 
54
  messages = [
55
- {"role": "user", "content": SYSTEM_PROMPT + f"\n\n### Math Problem:\n{problem.strip()}\n\n### Estella's Hint:"}
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 UI
80
- with gr.Blocks(title="Estella Explainer β€” Math Reading Coach") as demo:
81
- gr.Markdown("""
82
- # πŸ“š Estella Explainer
83
- ### A Math Reading Coach for Grades 3–8
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
- gr.Markdown("""
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
- submit_btn.click(fn=ask_estella, inputs=problem_input, outputs=hint_output)
123
- problem_input.submit(fn=ask_estella, inputs=problem_input, outputs=hint_output)
 
 
 
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()