File size: 2,000 Bytes
0477ea5
61733b2
 
5fa4f0c
cf97b5b
0d84e35
cf97b5b
f91ec2a
 
 
 
cf97b5b
 
 
101c61c
6d7d4df
 
 
101c61c
 
 
cf97b5b
 
 
101c61c
 
cf97b5b
114b4d3
0477ea5
cf97b5b
 
 
 
 
2402bb9
01e84e5
cf97b5b
 
 
101c61c
 
 
01e84e5
 
101c61c
 
c99576d
101c61c
cf97b5b
 
101c61c
0477ea5
101c61c
0477ea5
114b4d3
0d84e35
114b4d3
 
0477ea5
 
101c61c
 
 
 
 
 
0477ea5
5fa4f0c
0477ea5
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
import gradio as gr
from gampa.agents.function_eval import solveAgent
from gampa.setup import configure 

async def solveFun(usr_msg: str):
    try:
        response = await solveAgent().run(usr_msg)
        text = response.response.blocks[0].text
        text = text.replace("\\[", "$$").replace("\\]", "$$")
        text = text.replace("\\(", "").replace("\\)", "")
        return text
    except Exception:
        return "An error has occurred. Please try again."

EXAMPLES = [
    "Solve for f(3), given that f(x) = 4x + 1",
     "What is the value of f(3) if f(x) = 4x + 1",
    "Determine the value of f(3) for the function f(x)=4x+1",
    "Evaluate f(a,b) = 3*a + 2*b when a=2, b=5"
]

with gr.Blocks(theme=gr.themes.Soft(), title="GampaBot") as demo:
    gr.Markdown(
        """
        # GampaBot
        GampaBot is an AI mathematics assistant.
        """
    )

    with gr.Row():
        with gr.Column(scale=1):
            input_box = gr.Textbox(
                label="Enter Your Question",
                placeholder="e.g. Solve for f(3), given that f(x) = 4*x + 1",
                lines=4, 
                value=EXAMPLES[0],
                elem_id="input-box",
            )

            example_dropdown = gr.Dropdown(
                    choices=EXAMPLES,
                    label="Choose Example",
                    value=EXAMPLES[0],
                    elem_id="example-dropdown",
                    interactive=True
                )
            eval_button = gr.Button("Solve", variant="primary", elem_id="solve-btn")
                

        with gr.Column(scale=1):
            output_box = gr.Markdown("### Result will appear here...", elem_id="output-box")

    

    eval_button.click(
        fn=solveFun,
        inputs=input_box,
        outputs=output_box
    )

    example_dropdown.change(
        fn=lambda example: example,
        inputs=example_dropdown,
        outputs=input_box
    )

if __name__ == "__main__":
    configure()
    demo.launch()