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==============================
|
| 8 |
+
# WAREHOUSE MODEL PARAMETERS
|
| 9 |
+
# ==============================
|
| 10 |
+
NUM_AISLES = 30
|
| 11 |
+
NUM_RACKS = 20
|
| 12 |
+
|
| 13 |
+
FAST_ZONE = range(1, 6) # aisles 1β5
|
| 14 |
+
MID_ZONE = range(6, 16) # aisles 6β15
|
| 15 |
+
SLOW_ZONE = range(16, 31) # aisles 16β30
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
# ==============================
|
| 19 |
+
# SLOT RECOMMENDATION ENGINE
|
| 20 |
+
# ==============================
|
| 21 |
+
def recommend_slot(velocity):
|
| 22 |
+
"""
|
| 23 |
+
Assign aisle zone based on SKU velocity.
|
| 24 |
+
"""
|
| 25 |
+
velocity = str(velocity).lower()
|
| 26 |
+
|
| 27 |
+
if velocity in ["fast", "high", "f"]:
|
| 28 |
+
aisle = np.random.choice(list(FAST_ZONE))
|
| 29 |
+
reason = "Fast-moving SKU β Assigned close to dispatch to reduce pick time."
|
| 30 |
+
|
| 31 |
+
elif velocity in ["medium", "mid", "m"]:
|
| 32 |
+
aisle = np.random.choice(list(MID_ZONE))
|
| 33 |
+
reason = "Medium-moving SKU β Assigned to middle zone to balance travel distance."
|
| 34 |
+
|
| 35 |
+
else:
|
| 36 |
+
aisle = np.random.choice(list(SLOW_ZONE))
|
| 37 |
+
reason = "Slow-moving SKU β Assigned to back aisles to avoid congestion."
|
| 38 |
+
|
| 39 |
+
rack = np.random.randint(1, NUM_RACKS + 1)
|
| 40 |
+
|
| 41 |
+
return aisle, rack, reason
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
# ==============================
|
| 45 |
+
# MAIN OPTIMIZATION FUNCTION
|
| 46 |
+
# ==============================
|
| 47 |
+
def optimize_slotting(df):
|
| 48 |
+
if df is None or len(df) == 0:
|
| 49 |
+
return None, "β οΈ Please upload SKU data."
|
| 50 |
+
|
| 51 |
+
results = []
|
| 52 |
+
|
| 53 |
+
for _, row in df.iterrows():
|
| 54 |
+
sku = row["SKU"]
|
| 55 |
+
velocity = row["Velocity"]
|
| 56 |
+
frequency = row.get("Frequency", "")
|
| 57 |
+
|
| 58 |
+
aisle, rack, reason = recommend_slot(velocity)
|
| 59 |
+
|
| 60 |
+
results.append({
|
| 61 |
+
"SKU": sku,
|
| 62 |
+
"Velocity": velocity,
|
| 63 |
+
"Frequency": frequency,
|
| 64 |
+
"Suggested Aisle": aisle,
|
| 65 |
+
"Suggested Rack": rack,
|
| 66 |
+
"Reason": reason
|
| 67 |
+
})
|
| 68 |
+
|
| 69 |
+
output_df = pd.DataFrame(results)
|
| 70 |
+
return output_df, "β
Optimization Completed"
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
# ==============================
|
| 74 |
+
# GRADIO UI
|
| 75 |
+
# ==============================
|
| 76 |
+
def build_interface():
|
| 77 |
+
|
| 78 |
+
with gr.Blocks(css=".gr-button {background-color: %s !important;}" % PRIMARY_COLOR) as demo:
|
| 79 |
+
|
| 80 |
+
gr.Markdown(
|
| 81 |
+
"<h1 style='color:%s'>Procelevate Inventory Slotting Optimizer</h1>"
|
| 82 |
+
"<h3>AI-powered SKU placement engine to reduce picking time & congestion.</h3>"
|
| 83 |
+
% PRIMARY_COLOR
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
gr.Markdown("### π¦ Upload SKU File or Enter Data")
|
| 87 |
+
|
| 88 |
+
template_df = pd.DataFrame({
|
| 89 |
+
"SKU": ["A123", "B555", "C888"],
|
| 90 |
+
"Velocity": ["Fast", "Medium", "Slow"],
|
| 91 |
+
"Frequency": [120, 60, 5]
|
| 92 |
+
})
|
| 93 |
+
|
| 94 |
+
sku_table = gr.Dataframe(
|
| 95 |
+
value=template_df,
|
| 96 |
+
headers=["SKU", "Velocity", "Frequency"],
|
| 97 |
+
row_count=5,
|
| 98 |
+
col_count=3,
|
| 99 |
+
wrap=True
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
optimize_btn = gr.Button("Optimize Slotting", size="lg")
|
| 103 |
+
|
| 104 |
+
result_table = gr.Dataframe(
|
| 105 |
+
headers=["SKU", "Velocity", "Frequency",
|
| 106 |
+
"Suggested Aisle", "Suggested Rack", "Reason"],
|
| 107 |
+
row_count=5
|
| 108 |
+
)
|
| 109 |
+
|
| 110 |
+
business_insight = gr.Markdown("")
|
| 111 |
+
|
| 112 |
+
def run(df):
|
| 113 |
+
result, status = optimize_slotting(df)
|
| 114 |
+
if result is None:
|
| 115 |
+
return None, status
|
| 116 |
+
|
| 117 |
+
# Business insight summary
|
| 118 |
+
fast = len(result[result["Velocity"].str.lower() == "fast"])
|
| 119 |
+
medium = len(result[result["Velocity"].str.lower() == "medium"])
|
| 120 |
+
slow = len(result[result["Velocity"].str.lower() == "slow"])
|
| 121 |
+
|
| 122 |
+
insight = f"""
|
| 123 |
+
### π Business Insight Summary
|
| 124 |
+
|
| 125 |
+
- **Fast Movers:** {fast} SKUs moved closest to dispatch for quicker turnaround.
|
| 126 |
+
- **Medium Movers:** {medium} SKUs distributed in central aisles to balance traffic.
|
| 127 |
+
- **Slow Movers:** {slow} SKUs placed in far aisles to reduce congestion.
|
| 128 |
+
|
| 129 |
+
This improves:
|
| 130 |
+
- πΆ **Walking distance reduction**
|
| 131 |
+
- π **Faster order fulfillment**
|
| 132 |
+
- π― **Better space utilization**
|
| 133 |
+
- π **Lower aisle congestion**
|
| 134 |
+
"""
|
| 135 |
+
|
| 136 |
+
return result, insight
|
| 137 |
+
|
| 138 |
+
optimize_btn.click(run, inputs=[sku_table], outputs=[result_table, business_insight])
|
| 139 |
+
|
| 140 |
+
return demo
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
demo = build_interface()
|
| 144 |
+
demo.launch()
|