MasteredUltraInstinct commited on
Commit
f555e00
ยท
verified ยท
1 Parent(s): 0ae7b15

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -11
app.py CHANGED
@@ -174,20 +174,47 @@ def wrapped_solver(img, url):
174
  return result, cleaned
175
 
176
  with gr.Blocks() as demo:
177
- llm_url = gr.Textbox(label="๐Ÿ”— Enter LLM Microservice URL (from Colab)", placeholder="https://xxxx.ngrok-free.app")
178
- image_input = gr.Image(type="pil", label="๐Ÿ“ท Upload Image of Polynomial")
179
- hidden_latex = gr.Textbox(visible=False)
 
180
 
181
- output_box = gr.Markdown(label="๐Ÿ“‹ Step-by-step Solution")
182
- submit_btn = gr.Button("๐Ÿ” Solve")
183
- submit_btn.click(fn=wrapped_solver, inputs=[image_input, llm_url], outputs=[output_box, hidden_latex])
184
 
185
- explain_box = gr.Markdown(label="๐Ÿ—ฃ๏ธ Human-style Explanation")
186
- explain_btn = gr.Button("๐Ÿง  Explain Human-Solution")
187
- explain_btn.click(fn=request_llm_explanation, inputs=[hidden_latex, llm_url], outputs=explain_box)
188
 
189
- demo.title = "๐Ÿง  Polynomial Solver from Image"
190
- demo.description = "Upload a polynomial image (typed or handwritten). View symbolic steps and human-style explanation."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
 
192
  if __name__ == "__main__":
193
  demo.launch()
 
174
  return result, cleaned
175
 
176
  with gr.Blocks() as demo:
177
+ with gr.Tab("๐Ÿ–ผ๏ธ Parse from Image"):
178
+ llm_url = gr.Textbox(label="๐Ÿ”— Enter LLM Microservice URL (from Colab)", placeholder="https://xxxx.ngrok-free.app")
179
+ image_input = gr.Image(type="pil", label="๐Ÿ“ท Upload Image of Polynomial")
180
+ hidden_latex = gr.Textbox(visible=False)
181
 
182
+ output_box = gr.Markdown(label="๐Ÿ“‹ Step-by-step Solution")
183
+ submit_btn = gr.Button("๐Ÿ” Solve")
184
+ submit_btn.click(fn=wrapped_solver, inputs=[image_input, llm_url], outputs=[output_box, hidden_latex])
185
 
186
+ explain_box = gr.Markdown(label="๐Ÿ—ฃ๏ธ Human-style Explanation")
187
+ explain_btn = gr.Button("๐Ÿง  Explain Human-Solution")
188
+ explain_btn.click(fn=request_llm_explanation, inputs=[hidden_latex, llm_url], outputs=explain_box)
189
 
190
+ demo.title = "๐Ÿง  Polynomial Solver from Image"
191
+ demo.description = "Upload a polynomial image (typed or handwritten). View symbolic steps and human-style explanation."
192
+
193
+ with demo:
194
+ with gr.Tab("๐Ÿงฎ Solve by Coefficients"):
195
+ degree_input = gr.Number(label="Enter Degree of Polynomial (e.g. 3)")
196
+ coeffs_input = gr.Textbox(label="Enter Coefficients (comma-separated)", placeholder="e.g. 1, 2, 0, -4")
197
+ roots_output = gr.Markdown(label="โœ… Roots")
198
+
199
+ def solve_from_coeffs(degree, coeff_str):
200
+ try:
201
+ coeffs = [float(c.strip()) for c in coeff_str.split(",")]
202
+ if len(coeffs) != int(degree) + 1:
203
+ return f"โŒ You entered {len(coeffs)} coefficients, but degree {degree} needs {int(degree)+1}."
204
+
205
+ x = sp.Symbol("x")
206
+ poly_expr = sum(coeffs[i] * x**(int(degree) - i) for i in range(len(coeffs)))
207
+ roots = sp.solve(poly_expr, x)
208
+
209
+ result = "### Roots:\n"
210
+ for i, r in enumerate(roots, 1):
211
+ result += f"- Root {i}: $${sp.latex(sp.N(r, 6))}$$\n"
212
+ return result
213
+ except Exception as e:
214
+ return f"โŒ Error: {str(e)}"
215
+
216
+ coeff_btn = gr.Button("๐Ÿ“Œ Solve")
217
+ coeff_btn.click(fn=solve_from_coeffs, inputs=[degree_input, coeffs_input], outputs=roots_output)
218
 
219
  if __name__ == "__main__":
220
  demo.launch()