File size: 4,234 Bytes
a5c06b5
 
 
 
 
 
303c618
 
 
a5c06b5
 
 
 
303c618
 
 
7a4d019
 
303c618
 
a5c06b5
7a4d019
270176f
303c618
270176f
 
303c618
270176f
 
303c618
270176f
 
 
 
 
 
 
303c618
270176f
 
 
 
 
 
303c618
270176f
 
 
 
 
 
303c618
270176f
 
 
 
 
7a4d019
 
 
 
 
a5c06b5
270176f
 
 
 
 
a5c06b5
 
303c618
 
 
270176f
a5c06b5
 
303c618
a5c06b5
303c618
 
 
 
 
 
 
 
a5c06b5
 
303c618
 
 
 
 
a5c06b5
303c618
 
a5c06b5
 
 
 
 
 
 
 
 
303c618
 
a5c06b5
 
 
 
 
303c618
 
a5c06b5
303c618
 
caada9a
303c618
a5c06b5
303c618
a5c06b5
 
 
2a624da
a5c06b5
 
 
 
270176f
303c618
 
 
a5c06b5
 
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import gradio as gr
import pandas as pd
from agents.brain import AutoWarehouseAgent

agent = AutoWarehouseAgent()

# -------------------------------------------------------------
# Convert UI DataFrame input to Pandas
# -------------------------------------------------------------
def df_from_input(df):
    return pd.DataFrame(df) if df else pd.DataFrame()


# -------------------------------------------------------------
# MAIN AGENT RUNNER
# -------------------------------------------------------------
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)

        # -----------------------------------------------------
        # NORMALIZE OUTPUT DICTIONARY
        # -----------------------------------------------------
        if isinstance(raw, str):
            # If only text returned β†’ wrap it
            result = {
                "report": raw,
                "route_image": None,
                "slotting_table": pd.DataFrame(),
            }

        elif isinstance(raw, dict):
            # Normalize missing fields
            result = {
                "report": raw.get("report", "No report generated."),
                "route_image": raw.get("route_image", None),
                "slotting_table": raw.get("slotting_table", pd.DataFrame()),
            }
        else:
            # Unexpected type
            result = {
                "report": "⚠️ Invalid agent output format.",
                "route_image": None,
                "slotting_table": pd.DataFrame(),
            }

        # UI expects EXACTLY 3 outputs
        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(),
        )


# -------------------------------------------------------------
# BUILD UI
# -------------------------------------------------------------
def build_ui():
    with gr.Blocks() as demo:

        # Title
        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>
            """
        )

        # User input
        query = gr.Textbox(
            label="Enter your warehouse request",
            placeholder="Examples: 'Rebalance inventory', 'Forecast next 7 days', 'Optimize slotting', 'How many workers needed?'"
        )

        # Slotting input table
        gr.Markdown("### πŸ“¦ Slotting Data (SKU Master)")
        slot_df = gr.Dataframe(
            headers=["SKU", "Velocity", "Frequency"],
            value=[
                ["A123", "Fast", 120],
                ["B555", "Medium", 60],
                ["C888", "Slow", 8],
            ],
        )

        # Picking input table
        gr.Markdown("### 🚚 Picking Data")
        pick_df = gr.Dataframe(
            headers=["Aisle", "Rack"],
            value=[[5, 14], [3, 10], [12, 7]],
        )

        # Run button
        btn = gr.Button("Run Warehouse Agent", variant="primary")

        # Outputs
        out_report = gr.Markdown(label="πŸ“„ Report")
        out_route = gr.Image(label="πŸ“Š Charts / Diagrams",type="pil")
        out_slot = gr.Dataframe(label="πŸ“˜ Output Table")

        # Execution wiring
        btn.click(
            run_agent,
            inputs=[query, slot_df, pick_df],
            outputs=[out_report, out_route, out_slot],
        )

    return demo


# -------------------------------------------------------------
# LAUNCH APP
# -------------------------------------------------------------
demo = build_ui()
demo.launch()