-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
87 lines (66 loc) · 2.78 KB
/
Copy pathapp.py
File metadata and controls
87 lines (66 loc) · 2.78 KB
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
82
83
84
85
86
87
# app.py
import gradio as gr
from agents.planner_agent import plan_task
from agents.solver_agent import solve_task, get_last_generated_code
from agents.explainer_agent import explain_solution
# --- Tab 1: MILP Solver Pipeline ---
def milp_solver_ui():
with gr.Blocks() as demo:
gr.Markdown("# 🧠 Agentic MILP Solver")
gr.Markdown("Enter your MILP optimization problem. Agents will plan, solve, and explain.")
with gr.Row():
user_input = gr.Textbox(label="📥 MILP Problem", lines=8, placeholder="e.g.\nMaximize: 3x + 5y\nSubject to: 4x + 3y <= 240...")
run_btn = gr.Button("🚀 Run Agents")
with gr.Accordion("🧩 Planner Output", open=False):
planner_output = gr.Textbox(label="MILP Plan", lines=6)
with gr.Accordion("🛠 Solver Output", open=False):
solver_output = gr.Textbox(label="MILP Solution", lines=6)
with gr.Accordion("📖 Explanation", open=False):
explanation_output = gr.Textbox(label="Solution Explanation", lines=6)
def run_pipeline(problem_text):
plan = plan_task(problem_text)
solution = solve_task(plan)
explanation = explain_solution(solution, plan)
return plan, solution, explanation
run_btn.click(fn=run_pipeline, inputs=[user_input], outputs=[planner_output, solver_output, explanation_output])
return demo
# --- Tab 2: View Code ---
def code_view_ui():
with gr.Blocks() as code_tab:
gr.Markdown("# 🧾 View Generated Code")
gr.Markdown("This is the raw Python (PuLP) code generated by the Solver Agent.")
code_output = gr.Code(label="Python Code", language="python")
refresh_btn = gr.Button("🔄 Refresh Code")
refresh_btn.click(fn=get_last_generated_code, outputs=code_output)
return code_tab
# --- Tab 3: About ---
def about_tab_ui():
with gr.Blocks() as about:
gr.Markdown("# 📄 About This App")
gr.Markdown("""
This is an AI-powered MILP solver assistant using agent-based architecture.
- Planner Agent: Converts natural language to MILP formulation
- Solver Agent: Uses Gemini + PuLP to generate & run code
- Explainer Agent: Explains results simply
- Powered by Google Gemini + Gradio
💡 Example:
```
Maximize profit: 3x + 5y
Subject to:
4x + 3y <= 240
2x + 5y <= 100
x, y >= 0 and integer
```
""")
return about
# Combine all into tabbed interface
demo = gr.TabbedInterface(
interface_list=[
milp_solver_ui(),
code_view_ui(),
about_tab_ui()
],
tab_names=["🔢 Solve MILP", "🧾 View Code", "📄 About"]
)
if __name__ == "__main__":
demo.launch(share=True)