MBG0903 commited on
Commit
00bb337
·
verified ·
1 Parent(s): dd9d1b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +90 -50
app.py CHANGED
@@ -1,77 +1,114 @@
1
  import gradio as gr
 
 
2
  from agents.planner import interpret_user_intent
3
- from agents.reasoner import generate_final_response
4
  from tools.slotting import run_slotting
5
  from tools.picking import run_picking
6
  from tools.heatmap import generate_heatmap
7
  from tools.insights import generate_insights
8
- from tools.report import build_report
 
 
9
 
10
 
11
- # ---------------------------
12
- # ROUTER — CALL CORRECT TOOL
13
- # ---------------------------
14
  def agent_controller(user_message, slotting_df, picking_df):
15
- """
16
- Main agent controller logic:
17
- 1. Understand user request
18
- 2. Decide which tool(s) to run
19
- 3. Compose multi-step response
20
- """
21
 
22
  intent = interpret_user_intent(user_message)
23
 
24
- response_blocks = []
25
-
 
26
  if intent == "slotting":
27
  slotting_result = run_slotting(slotting_df)
28
- heatmap = generate_heatmap(slotting_result)
29
- insight = generate_insights(slotting_result)
30
-
31
- final = generate_final_response(
32
- user_message,
33
- steps=["Slotting Optimization Performed"],
34
- results={"slotting": slotting_result.to_dict(), "insight": insight}
 
 
35
  )
36
 
37
- return final, heatmap, insight
38
 
 
 
 
39
  elif intent == "picking":
40
- picking_result, plot = run_picking(picking_df)
41
-
42
- final = generate_final_response(
43
- user_message,
44
- steps=["Picking Route Optimized"],
45
- results={"picking": "Route optimized"}
 
 
46
  )
47
 
48
- return final, plot, None
49
 
 
 
 
50
  elif intent == "report":
51
- report_text = build_report()
52
- return report_text, None, None
 
 
53
 
 
 
 
 
 
 
 
 
 
54
  else:
55
  return (
56
- "I'm not sure what you want me to optimize. Try saying:\n"
57
  "- 'Optimize slotting for fast movers'\n"
58
- "- 'Optimize today's pick route'\n"
59
- "- 'Generate warehouse insights report'",
60
- None,
61
  None
62
  )
63
 
64
 
65
- # ---------------------------
66
- # UI SETUP
67
- # ---------------------------
68
  def build_ui():
69
 
70
- with gr.Blocks() as demo:
71
- gr.Markdown("<h1 style='color:#FF6A00'>Procelevate Autonomous Warehouse Operator</h1>"
72
- "<p>Agentic AI that plans, optimizes, and explains warehouse decisions.</p>")
73
-
74
- user_input = gr.Textbox(label="Ask the Warehouse Operator", placeholder="e.g., Optimize slotting for fast movers")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
 
76
  with gr.Row():
77
  slotting_df = gr.DataFrame(
@@ -79,27 +116,30 @@ def build_ui():
79
  value=[
80
  ["A123", "Fast", 120],
81
  ["B555", "Medium", 60],
82
- ["C888", "Slow", 5],
83
  ],
84
  label="Slotting Data"
85
  )
86
 
87
  picking_df = gr.DataFrame(
88
  headers=["Aisle", "Rack"],
89
- value=[[5, 14], [3, 10], [12, 7]],
 
 
 
 
90
  label="Picking Path Data"
91
  )
92
 
93
- run_btn = gr.Button("Run Agent")
94
 
95
- output_text = gr.Markdown(label="Agent Response")
96
- output_image = gr.Image(label="Visualization", type="pil")
97
- output_insight = gr.Markdown(label="Insights")
98
 
99
  run_btn.click(
100
- agent_controller,
101
  inputs=[user_input, slotting_df, picking_df],
102
- outputs=[output_text, output_image, output_insight]
103
  )
104
 
105
  return demo
 
1
  import gradio as gr
2
+ import pandas as pd
3
+
4
  from agents.planner import interpret_user_intent
5
+ from agents.reasoner import generate_consulting_report
6
  from tools.slotting import run_slotting
7
  from tools.picking import run_picking
8
  from tools.heatmap import generate_heatmap
9
  from tools.insights import generate_insights
10
+ from tools.report import build_full_report
11
+
12
+ PRIMARY_COLOR = "#0f2c59"
13
 
14
 
15
+ # ---------------------------------------------------------
16
+ # MAIN AGENT CONTROLLER — DECIDES & EXECUTES ACTIONS
17
+ # ---------------------------------------------------------
18
  def agent_controller(user_message, slotting_df, picking_df):
 
 
 
 
 
 
19
 
20
  intent = interpret_user_intent(user_message)
21
 
22
+ # ---------------------------------------------------------
23
+ # SLOTING REQUEST
24
+ # ---------------------------------------------------------
25
  if intent == "slotting":
26
  slotting_result = run_slotting(slotting_df)
27
+ heatmap_img = generate_heatmap(slotting_result)
28
+ insights = generate_insights(slotting_result)
29
+
30
+ final_report = generate_consulting_report(
31
+ task="Slotting Optimization",
32
+ slotting=slotting_result,
33
+ picking=None,
34
+ heatmap=True,
35
+ insights=insights
36
  )
37
 
38
+ return final_report, heatmap_img
39
 
40
+ # ---------------------------------------------------------
41
+ # PICKING ROUTE REQUEST
42
+ # ---------------------------------------------------------
43
  elif intent == "picking":
44
+ picking_result, picking_plot = run_picking(picking_df)
45
+
46
+ final_report = generate_consulting_report(
47
+ task="Picking Route Optimization",
48
+ slotting=None,
49
+ picking=picking_result,
50
+ heatmap=False,
51
+ insights=None
52
  )
53
 
54
+ return final_report, picking_plot
55
 
56
+ # ---------------------------------------------------------
57
+ # FULL WAREHOUSE REPORT
58
+ # ---------------------------------------------------------
59
  elif intent == "report":
60
+ slotting_result = run_slotting(slotting_df)
61
+ heatmap_img = generate_heatmap(slotting_result)
62
+ picking_result, picking_plot = run_picking(picking_df)
63
+ insights = generate_insights(slotting_result)
64
 
65
+ full_report = build_full_report(
66
+ slotting_result, picking_result, insights
67
+ )
68
+
69
+ return full_report, heatmap_img
70
+
71
+ # ---------------------------------------------------------
72
+ # UNKNOWN INTENT
73
+ # ---------------------------------------------------------
74
  else:
75
  return (
76
+ "Unable to determine the warehouse task. Try examples like:\n"
77
  "- 'Optimize slotting for fast movers'\n"
78
+ "- 'Show picking route'\n"
79
+ "- 'Generate full warehouse report'",
 
80
  None
81
  )
82
 
83
 
84
+ # ---------------------------------------------------------
85
+ # ENTERPRISE UI LAYOUT
86
+ # ---------------------------------------------------------
87
  def build_ui():
88
 
89
+ with gr.Blocks(css=f"""
90
+ h1 {{
91
+ color: {PRIMARY_COLOR};
92
+ font-weight: 700;
93
+ }}
94
+ .procelevate-box {{
95
+ border: 2px solid {PRIMARY_COLOR};
96
+ border-radius: 8px;
97
+ padding: 12px;
98
+ }}
99
+ """) as demo:
100
+
101
+ gr.Markdown("""
102
+ <h1>Procelevate Autonomous Warehouse Operator</h1>
103
+ <p style='font-size:16px;'>
104
+ Enterprise-grade Agentic AI system that optimizes slotting, picking, and warehouse operations.
105
+ </p>
106
+ """)
107
+
108
+ user_input = gr.Textbox(
109
+ label="Ask the Warehouse Operator",
110
+ placeholder="Example: Optimize slotting for fast movers",
111
+ )
112
 
113
  with gr.Row():
114
  slotting_df = gr.DataFrame(
 
116
  value=[
117
  ["A123", "Fast", 120],
118
  ["B555", "Medium", 60],
119
+ ["C888", "Slow", 8],
120
  ],
121
  label="Slotting Data"
122
  )
123
 
124
  picking_df = gr.DataFrame(
125
  headers=["Aisle", "Rack"],
126
+ value=[
127
+ [5, 14],
128
+ [3, 10],
129
+ [12, 7],
130
+ ],
131
  label="Picking Path Data"
132
  )
133
 
134
+ run_btn = gr.Button("Run Agent", variant="primary")
135
 
136
+ report_output = gr.Markdown(label="Procelevate Analysis Report")
137
+ visual_output = gr.Image(type="pil", label="Visualization")
 
138
 
139
  run_btn.click(
140
+ fn=agent_controller,
141
  inputs=[user_input, slotting_df, picking_df],
142
+ outputs=[report_output, visual_output]
143
  )
144
 
145
  return demo