File size: 3,210 Bytes
689f341
6578264
 
 
 
 
 
3990846
6578264
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3990846
918ee22
6578264
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import gradio as gr
from solver import (
    generate_polynomial_template,
    solve_polynomial,
    solve_linear_system
)
from llm_utils import explain_with_llm
from image import image_tab  # โœ… Now handles Pix2Text internally

with gr.Blocks() as demo:
    gr.Markdown("# ๐Ÿ”ข Math Solver Suite")
    gr.Markdown("Solve polynomials and systems of linear equations step-by-step with visualizations and explanations.")

    with gr.Tabs():
        with gr.TabItem("๐Ÿ“ Polynomial Solver"):
            with gr.Row():
                degree_slider = gr.Slider(1, 8, value=3, step=1, label="Degree of Polynomial")
                template_display = gr.Textbox(label="Polynomial Template (auto-updated)", interactive=False)

            coeff_input = gr.Textbox(
                label="Enter Coefficients (space-separated, supports pi, e, sqrt(2), I)",
                placeholder="e.g. 1 -3 sqrt(2) -pi"
            )
            llm_url = gr.Textbox(label="LLM Microservice URL (optional)", placeholder="https://your-llm-url.ngrok.app")

            steps_md = gr.Markdown()
            plot_output = gr.Plot()
            error_box = gr.Textbox(visible=False)
            poly_solution_txt = gr.Textbox(visible=False)

            with gr.Row():
                solve_button = gr.Button("Plot Polynomial", variant="primary")
                explain_button = gr.Button("Explain Polynomial with LLM")

            degree_slider.change(
                fn=generate_polynomial_template,
                inputs=degree_slider,
                outputs=template_display
            )

            solve_button.click(
                fn=solve_polynomial,
                inputs=[degree_slider, coeff_input],
                outputs=[steps_md, plot_output, error_box, poly_solution_txt]
            )

            explain_button.click(
                fn=lambda sol, url: explain_with_llm(sol, "polynomial", url),
                inputs=[poly_solution_txt, llm_url],
                outputs=steps_md
            )

        with gr.TabItem("๐Ÿงฎ Linear Equation Solver"):
            eq1_input = gr.Textbox(label="Equation 1 (in x and y)", placeholder="e.g. 2*x + 3*y - 6")
            eq2_input = gr.Textbox(label="Equation 2 (in x and y)", placeholder="e.g. -x + y - 2")
            llm_url_linear = gr.Textbox(label="LLM Microservice URL (optional)", placeholder="https://your-llm-url.ngrok.app")

            sys_steps = gr.Markdown()
            sys_plot = gr.Plot()
            sys_solution_txt = gr.Textbox(visible=False)

            with gr.Row():
                solve_sys_button = gr.Button("Solve Linear System", variant="primary")
                explain_sys_button = gr.Button("Explain Linear System with LLM")

            solve_sys_button.click(
                fn=solve_linear_system,
                inputs=[eq1_input, eq2_input],
                outputs=[sys_steps, sys_plot, sys_solution_txt]
            )

            explain_sys_button.click(
                fn=lambda sol, url: explain_with_llm(sol, "linear", url),
                inputs=[sys_solution_txt, llm_url_linear],
                outputs=sys_steps
            )

        image_tab()  # โœ… Now no argument required

    demo.launch()