|
|
import gradio as gr |
|
|
import pandas as pd |
|
|
from agents.brain import AutoWarehouseAgent |
|
|
|
|
|
agent = AutoWarehouseAgent() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def df_from_input(df): |
|
|
return pd.DataFrame(df) if df else pd.DataFrame() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def run_agent(message, slotting_df, picking_df): |
|
|
print("π₯ INPUT MESSAGE:", message) |
|
|
print("π¦ SLOT DATA RECEIVED:", slotting_df) |
|
|
print("π PICKING DATA RECEIVED:", picking_df) |
|
|
|
|
|
try: |
|
|
raw = agent.run(message, slotting_df, picking_df) |
|
|
print("π RAW RESULT FROM AGENT:", raw) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if isinstance(raw, str): |
|
|
|
|
|
result = { |
|
|
"report": raw, |
|
|
"route_image": None, |
|
|
"slotting_table": pd.DataFrame(), |
|
|
} |
|
|
|
|
|
elif isinstance(raw, dict): |
|
|
|
|
|
result = { |
|
|
"report": raw.get("report", "No report generated."), |
|
|
"route_image": raw.get("route_image", None), |
|
|
"slotting_table": raw.get("slotting_table", pd.DataFrame()), |
|
|
} |
|
|
else: |
|
|
|
|
|
result = { |
|
|
"report": "β οΈ Invalid agent output format.", |
|
|
"route_image": None, |
|
|
"slotting_table": pd.DataFrame(), |
|
|
} |
|
|
|
|
|
|
|
|
return ( |
|
|
result["report"], |
|
|
result["route_image"], |
|
|
result["slotting_table"], |
|
|
) |
|
|
|
|
|
except Exception as e: |
|
|
import traceback |
|
|
print("β ERROR OCCURRED:") |
|
|
traceback.print_exc() |
|
|
|
|
|
return ( |
|
|
f"### β Error\n{str(e)}", |
|
|
None, |
|
|
pd.DataFrame(), |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def build_ui(): |
|
|
with gr.Blocks() as demo: |
|
|
|
|
|
|
|
|
gr.Markdown( |
|
|
""" |
|
|
<h1 style='color:#FF6A00;text-align:center;'> |
|
|
Procelevate Autonomous Warehouse Operator (v2.0) |
|
|
</h1> |
|
|
<p style='text-align:center;font-size:16px;'> |
|
|
Slotting β’ Picking β’ Forecasting β’ Replenishment β’ Rebalancing β’ Workforce β’ Dock Scheduling |
|
|
</p> |
|
|
""" |
|
|
) |
|
|
|
|
|
|
|
|
query = gr.Textbox( |
|
|
label="Enter your warehouse request", |
|
|
placeholder="Examples: 'Rebalance inventory', 'Forecast next 7 days', 'Optimize slotting', 'How many workers needed?'" |
|
|
) |
|
|
|
|
|
|
|
|
gr.Markdown("### π¦ Slotting Data (SKU Master)") |
|
|
slot_df = gr.Dataframe( |
|
|
headers=["SKU", "Velocity", "Frequency"], |
|
|
value=[ |
|
|
["A123", "Fast", 120], |
|
|
["B555", "Medium", 60], |
|
|
["C888", "Slow", 8], |
|
|
], |
|
|
) |
|
|
|
|
|
|
|
|
gr.Markdown("### π Picking Data") |
|
|
pick_df = gr.Dataframe( |
|
|
headers=["Aisle", "Rack"], |
|
|
value=[[5, 14], [3, 10], [12, 7]], |
|
|
) |
|
|
|
|
|
|
|
|
btn = gr.Button("Run Warehouse Agent", variant="primary") |
|
|
|
|
|
|
|
|
out_report = gr.Markdown(label="π Report") |
|
|
out_route = gr.Image(label="π Charts / Diagrams",type="pil") |
|
|
out_slot = gr.Dataframe(label="π Output Table") |
|
|
|
|
|
|
|
|
btn.click( |
|
|
run_agent, |
|
|
inputs=[query, slot_df, pick_df], |
|
|
outputs=[out_report, out_route, out_slot], |
|
|
) |
|
|
|
|
|
return demo |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
demo = build_ui() |
|
|
demo.launch() |
|
|
|