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()