MasteredUltraInstinct commited on
Commit
6578264
·
verified ·
1 Parent(s): a70b95a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +77 -0
app.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from solver import (
3
+ generate_polynomial_template,
4
+ solve_polynomial,
5
+ solve_linear_system
6
+ )
7
+ from llm_utils import explain_with_llm
8
+
9
+ with gr.Blocks() as demo:
10
+ gr.Markdown("# 🔢 Math Solver Suite")
11
+ gr.Markdown("Solve polynomials and systems of linear equations step-by-step with visualizations and explanations.")
12
+
13
+ with gr.Tabs():
14
+ with gr.TabItem("📐 Polynomial Solver"):
15
+ with gr.Row():
16
+ degree_slider = gr.Slider(1, 8, value=3, step=1, label="Degree of Polynomial")
17
+ template_display = gr.Textbox(label="Polynomial Template (auto-updated)", interactive=False)
18
+
19
+ coeff_input = gr.Textbox(
20
+ label="Enter Coefficients (space-separated, supports pi, e, sqrt(2), I)",
21
+ placeholder="e.g. 1 -3 sqrt(2) -pi"
22
+ )
23
+ llm_url = gr.Textbox(label="LLM Microservice URL (optional)", placeholder="https://your-llm-url.ngrok.app")
24
+
25
+ steps_md = gr.Markdown()
26
+ plot_output = gr.Plot()
27
+ error_box = gr.Textbox(visible=False)
28
+ poly_solution_txt = gr.Textbox(visible=False)
29
+
30
+ with gr.Row():
31
+ solve_button = gr.Button("Plot Polynomial", variant="primary")
32
+ explain_button = gr.Button("Explain Polynomial with LLM")
33
+
34
+ degree_slider.change(
35
+ fn=generate_polynomial_template,
36
+ inputs=degree_slider,
37
+ outputs=template_display
38
+ )
39
+
40
+ solve_button.click(
41
+ fn=solve_polynomial,
42
+ inputs=[degree_slider, coeff_input],
43
+ outputs=[steps_md, plot_output, error_box, poly_solution_txt]
44
+ )
45
+
46
+ explain_button.click(
47
+ fn=lambda sol, url: explain_with_llm(sol, "polynomial", url),
48
+ inputs=[poly_solution_txt, llm_url],
49
+ outputs=steps_md
50
+ )
51
+
52
+ with gr.TabItem("🧮 Linear Equation Solver"):
53
+ eq1_input = gr.Textbox(label="Equation 1 (in x and y)", placeholder="e.g. 2*x + 3*y - 6")
54
+ eq2_input = gr.Textbox(label="Equation 2 (in x and y)", placeholder="e.g. -x + y - 2")
55
+ llm_url_linear = gr.Textbox(label="LLM Microservice URL (optional)", placeholder="https://your-llm-url.ngrok.app")
56
+
57
+ sys_steps = gr.Markdown()
58
+ sys_plot = gr.Plot()
59
+ sys_solution_txt = gr.Textbox(visible=False)
60
+
61
+ with gr.Row():
62
+ solve_sys_button = gr.Button("Solve Linear System", variant="primary")
63
+ explain_sys_button = gr.Button("Explain Linear System with LLM")
64
+
65
+ solve_sys_button.click(
66
+ fn=solve_linear_system,
67
+ inputs=[eq1_input, eq2_input],
68
+ outputs=[sys_steps, sys_plot, sys_solution_txt]
69
+ )
70
+
71
+ explain_sys_button.click(
72
+ fn=lambda sol, url: explain_with_llm(sol, "linear", url),
73
+ inputs=[sys_solution_txt, llm_url_linear],
74
+ outputs=sys_steps
75
+ )
76
+
77
+ demo.launch()