Pro-Coder commited on
Commit
2d9a408
·
verified ·
1 Parent(s): eec41e6

Upload 43 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,7 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ assets/intent_confusion_matrix.png filter=lfs diff=lfs merge=lfs -text
37
+ assets/sensor_distributions.png filter=lfs diff=lfs merge=lfs -text
38
+ assets/vision_sample_annotated.png filter=lfs diff=lfs merge=lfs -text
39
+ assets/vision_sample_raw.png filter=lfs diff=lfs merge=lfs -text
DEPLOY.md CHANGED
@@ -117,3 +117,14 @@ reproducible ML work rather than just a UI demo. Since everything here is
117
  built on synthetic, self-generated data, this same Space link works as-is
118
  for applications to multiple companies — no company-specific data or
119
  branding needs to change.
 
 
 
 
 
 
 
 
 
 
 
 
117
  built on synthetic, self-generated data, this same Space link works as-is
118
  for applications to multiple companies — no company-specific data or
119
  branding needs to change.
120
+
121
+ ## Optional secrets
122
+
123
+ | Secret | Purpose |
124
+ |---|---|
125
+ | `HF_TOKEN` (or `Smart_Warehouse`, see `src/llm_client.py`) | Enables LLM-generated answers (otherwise retrieval-only fallback) |
126
+ | `SLACK_WEBHOOK_URL` | Makes the Predictive Maintenance "Send Slack alert" option actually post to Slack (otherwise it shows a labelled preview) |
127
+
128
+ **Dependency note:** `requirements.txt` pins `pydantic==2.10.6`. Gradio 5.9.1's API-schema generation
129
+ crashes on newer pydantic releases (`TypeError: argument of type 'bool' is not iterable`), which would
130
+ make the Space fail to start after a rebuild. Don't remove the pin unless you also upgrade Gradio.
README.md CHANGED
@@ -8,8 +8,9 @@ sdk_version: 5.9.1
8
  app_file: app.py
9
  pinned: false
10
  license: mit
11
- short_description: LLM warehouse copilot with predictive maintenance
12
  ---
 
13
  # 🏭 Smart Warehouse AI Assistant
14
 
15
  An LLM-powered, retrieval-grounded AI copilot for automated warehouse
@@ -24,26 +25,21 @@ metrics on held-out test data.
24
 
25
  ## Tabs
26
 
27
- 1. **💬 AI Assistant** — ask free-text warehouse-ops questions; answers are
28
- grounded via TF-IDF retrieval over a small knowledge base and generated
29
- by a hosted LLM (Hugging Face Inference API, with a multi-model fallback
30
- chain), with a transparent retrieval-only fallback and a built-in
31
- **"Test LLM connection" diagnostics button** if no API key is configured
32
- or the call fails. Includes an "About the data" panel explaining the
33
- knowledge base and training data.
34
- 2. **📦 Inventory & Order Query** — natural-language queries over synthetic
35
- inventory / order tables (SKU, zone, order-id extraction), with an
36
- "About the data" panel describing the synthetic tables.
37
- 3. **⚠️ Predictive Maintenance** — Isolation Forest anomaly detector over
38
- conveyor/crane motor sensor readings (temperature, vibration, current,
39
- belt speed), with an "About the data" panel describing the synthetic
40
- sensor dataset and failure patterns.
41
- 4. **📊 Model Evaluation** — accuracy, macro-F1, confusion matrices,
42
- ROC-AUC, retrieval hit-rate, and latency benchmarks, all computed on
43
- held-out data by `build_artifacts.py` and rendered as charts (bar
44
- charts, confusion matrices, ROC curve, feature-distribution histograms)
45
- alongside the underlying tables.
46
- 5. **ℹ️ About** — project write-up, architecture diagram, tech stack.
47
 
48
  ## Quick start (local)
49
 
@@ -89,6 +85,8 @@ smart-warehouse-ai/
89
  ├── build_artifacts.py # generates data, trains models, evaluates, saves plots
90
  ├── requirements.txt
91
  ├── src/
 
 
92
  │ ├── data_generation.py # synthetic intent / inventory / sensor datasets
93
  │ ├── knowledge_base.py # warehouse-ops knowledge base (RAG source docs)
94
  │ ├── retriever.py # TF-IDF retriever
@@ -115,7 +113,8 @@ benchmark). Headline numbers from the included run:
115
  | Anomaly detector | Recall | ~97% |
116
  | Anomaly detector | F1 | ~98% |
117
  | Anomaly detector | ROC-AUC | ~1.00 |
118
- | RAG retriever | Hit-rate@2 | 100% |
 
119
 
120
  *(Computed on synthetic, held-out test data — see the Evaluation tab for
121
  methodology notes.)*
@@ -150,3 +149,12 @@ is about honestly picking the cutoff, not about detection ability.
150
  ## License
151
 
152
  MIT — feel free to fork and adapt.
 
 
 
 
 
 
 
 
 
 
8
  app_file: app.py
9
  pinned: false
10
  license: mit
11
+ short_description: LLM warehouse copilot, predictive maintenance & CV
12
  ---
13
+
14
  # 🏭 Smart Warehouse AI Assistant
15
 
16
  An LLM-powered, retrieval-grounded AI copilot for automated warehouse
 
25
 
26
  ## Tabs
27
 
28
+ 1. **💬 AI Assistant** — free-text warehouse-ops Q&A. Intent classification → TF-IDF retrieval over a
29
+ 17-article knowledge base (RAG) → hosted LLM, with **multi-turn memory** (follow-ups like
30
+ *"what about Zone D instead?"* work), a multi-model fallback chain, a retrieval-only fallback, and a
31
+ "Test LLM connection" diagnostics button.
32
+ 2. **📦 Inventory & Order Query** — natural-language queries over synthetic inventory / order tables.
33
+ 3. **⚠️ Predictive Maintenance** — Isolation Forest anomaly detector (calibrated threshold). Single
34
+ readings via sliders, **CSV batch scoring** (sample file provided), and optional **Slack alerts**
35
+ (real if `SLACK_WEBHOOK_URL` is set, otherwise a clearly-labelled preview — never claimed as sent).
36
+ 4. **📷 Visual Inventory Scan** — a *classical* (non-deep-learning) OpenCV pipeline that counts boxes and
37
+ estimates rack occupancy on synthetic rack images, with an adjustable noise slider.
38
+ 5. **📊 Model Evaluation** — graphical, held-out metrics for every component, including the vision
39
+ pipeline's accuracy-vs-noise curve.
40
+ 6. **ℹ️ About** — dataset provenance, model function table, architecture, how to test.
41
+
42
+ A **🌐 Language / 言語** selector switches the explanatory text between English and 日本語.
 
 
 
 
 
43
 
44
  ## Quick start (local)
45
 
 
85
  ├── build_artifacts.py # generates data, trains models, evaluates, saves plots
86
  ├── requirements.txt
87
  ├── src/
88
+ │ ├── vision_model.py # classical-CV rack scanner (+ synthetic scene generator)
89
+ │ ├── alerting.py # Slack alert (real webhook or preview) + email preview
90
  │ ├── data_generation.py # synthetic intent / inventory / sensor datasets
91
  │ ├── knowledge_base.py # warehouse-ops knowledge base (RAG source docs)
92
  │ ├── retriever.py # TF-IDF retriever
 
113
  | Anomaly detector | Recall | ~97% |
114
  | Anomaly detector | F1 | ~98% |
115
  | Anomaly detector | ROC-AUC | ~1.00 |
116
+ | RAG retriever | Hit-rate@1 / @2 | 88% / 100% |
117
+ | Vision (box counting, noise 0.4) | Exact count match | ~88% (100% clean → ~77% at max noise) |
118
 
119
  *(Computed on synthetic, held-out test data — see the Evaluation tab for
120
  methodology notes.)*
 
149
  ## License
150
 
151
  MIT — feel free to fork and adapt.
152
+
153
+ ## Vision pipeline — honest evaluation notes
154
+
155
+ The first detector (Canny edges + dilation) merged every box into one blob; it was replaced with
156
+ colour-distance segmentation. On clean renders it then hit a suspicious 100%, so a `noise_level`
157
+ (pixel noise, brightness/contrast jitter, per-box colour variation) was added and the headline number is
158
+ reported at a moderate noise level alongside a full noise-sweep chart. Occupancy was also redefined from
159
+ padded pixel area to *occupied grid cells* to match how ground truth is defined. All scenes are synthetic —
160
+ a real deployment would fine-tune a detector (e.g. YOLO) on real photos.
app.py CHANGED
@@ -27,6 +27,8 @@ import pandas as pd
27
  from src.anomaly_model import FEATURES as SENSOR_FEATURES
28
  from src.anomaly_model import load_artifacts as load_anomaly_artifacts
29
  from src.anomaly_model import score_reading
 
 
30
  from src.data_generation import generate_inventory_db, generate_orders_db
31
  from src.intent_model import INTENT_DESCRIPTIONS, load_pipeline, predict as intent_predict
32
  from src.inventory_db import query_inventory, query_orders
@@ -104,6 +106,7 @@ intent_eval = _load_json("intent_eval.json")
104
  anomaly_eval = _load_json("anomaly_eval.json")
105
  retrieval_eval = _load_json("retrieval_eval.json")
106
  latency_eval = _load_json("latency_eval.json")
 
107
 
108
  HF_TOKEN_SET = bool(_get_hf_token())
109
 
@@ -136,7 +139,9 @@ except ImportError:
136
 
137
  def chat_fn(message, history):
138
  intent = intent_predict(intent_pipeline, message)
139
- response = answer_query(message, retriever)
 
 
140
 
141
  intent_label = INTENT_DESCRIPTIONS.get(intent.intent, intent.intent)
142
  meta_lines = [f"**Detected intent:** {intent_label} ({intent.confidence:.0%} confidence)"]
@@ -215,20 +220,17 @@ def inventory_query_fn(text):
215
  # TAB 3 -- Predictive Maintenance / Anomaly Detection
216
  # ==========================================================================
217
 
218
- def anomaly_fn(motor_temp, vibration, current, belt_speed):
219
  reading = {
220
- "motor_temp_c": motor_temp,
221
- "vibration_mm_s": vibration,
222
- "current_amps": current,
223
- "belt_speed_mps": belt_speed,
224
  }
225
  result = score_reading(anomaly_model, anomaly_scaler, reading, threshold=anomaly_threshold)
226
  verdict = "🔴 ANOMALY DETECTED" if result.is_anomaly else "🟢 Normal operating range"
227
  detail = (
228
  f"### {verdict}\n\n"
229
  f"**Anomaly score:** {result.anomaly_score:.2f} / 1.00\n\n"
230
- f"| Sensor | Value | Typical normal range |\n"
231
- f"|---|---|---|\n"
232
  f"| Motor temperature | {motor_temp:.1f} °C | 47–63 °C |\n"
233
  f"| Vibration | {vibration:.2f} mm/s | 1.2–3.2 mm/s |\n"
234
  f"| Motor current | {current:.1f} A | 9–15 A |\n"
@@ -241,6 +243,14 @@ def anomaly_fn(motor_temp, vibration, current, belt_speed):
241
  "wear, belt misalignment, or motor overload -- schedule maintenance before "
242
  "the next shift to avoid an unplanned stoppage."
243
  )
 
 
 
 
 
 
 
 
244
  return detail
245
 
246
 
@@ -255,6 +265,60 @@ def load_preset(name):
255
  return ANOMALY_PRESETS[name]
256
 
257
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
258
  # ==========================================================================
259
  # TAB 4 -- Model Evaluation
260
  # ==========================================================================
@@ -327,7 +391,11 @@ Modern warehouse automation platforms — automated storage & retrieval
327
  systems (AS/RS), conveyor & sortation lines, AGVs/AMRs, and the WMS/WCS
328
  software that orchestrates them — generate huge volumes of operational
329
  data: equipment telemetry, transactions, safety logs, and ad-hoc questions
330
- from floor staff."
 
 
 
 
331
 
332
  ## What this demonstrates
333
 
@@ -350,12 +418,12 @@ being realistic enough to demonstrate the underlying ML techniques properly.
350
 
351
  | Dataset | What it is | Size | How it's generated |
352
  |---|---|---|---|
353
- | **Knowledge base** | Original, hand-written articles on generic warehouse-automation concepts (AS/RS, AGV/AMR, WMS, sortation, picking strategy, predictive maintenance, safety, inventory accuracy, KPIs, energy efficiency) | 10 articles | Written by the developer specifically for this project |
354
  | **Intent queries** | Example free-text operational questions/requests across 8 categories | ~480 examples | ~8 templates per category with randomised SKU codes, zone names, order IDs, and equipment IDs slotted in |
355
  | **Inventory table** | SKU records with category, zone, on-hand units, reorder point, unit cost | 60 SKUs | Randomised within realistic ranges (fixed seed) |
356
  | **Orders table** | Order records with status, line count, priority, zone | 80 orders | Randomised within realistic ranges (fixed seed) |
357
  | **Sensor readings** | Conveyor/crane motor telemetry: temperature, vibration, current, belt speed | 1,000 readings (900 normal + 100 anomalous) | Normal readings drawn from realistic operating ranges; anomalies simulate known failure signatures (elevated temp/vibration/current + reduced belt speed) |
358
- | **Retrieval eval set** | Hand-labelled (question → expected knowledge-base article) pairs | 10 pairs | Written by the developer to check retrieval accuracy |
359
 
360
  ## How each model works (function)
361
 
@@ -441,11 +509,19 @@ chosen to be as simple as it can be while still doing that job well and
441
  being honestly evaluated, rather than reaching for the biggest available
442
  model by default.
443
 
 
 
 
 
 
 
 
 
444
  ## Limitations & next steps
445
 
446
  - All data here is **synthetic**, for portfolio/demo purposes — a production
447
  version would connect to real WMS/WCS APIs and historical sensor logs.
448
- - The intent set (8 classes) and knowledge base (10 articles) are intentionally
449
  small to keep the demo fast and auditable; both are easy to extend.
450
  - The anomaly detector uses 4 hand-picked features; a production system would
451
  likely use a richer multivariate sensor set and a supervised or
@@ -476,15 +552,175 @@ CUSTOM_CSS = """
476
  .data-badge b { color: #1e3a8a; }
477
  """
478
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
479
  def data_badge(html: str) -> str:
480
  return f'<div class="data-badge">{html}</div>'
481
 
482
  with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue"), css=CUSTOM_CSS, title="Smart Warehouse AI Assistant") as demo:
483
- gr.Markdown(
484
- "<h1 id='title-banner'>🏭 Smart Warehouse AI Assistant</h1>"
485
- "<p style='text-align:center; color:gray;'>LLM-powered intralogistics copilot · "
486
- "intent routing · predictive maintenance · retrieval-grounded Q&A</p>"
487
- )
488
  if not HF_TOKEN_SET:
489
  gr.Markdown(
490
  "> ⚠️ **No HF token secret detected.** The AI Assistant tab will run in "
@@ -494,22 +730,8 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue"), css=CUSTOM_CSS, title="
494
  )
495
 
496
  with gr.Tab("💬 AI Assistant"):
497
- with gr.Accordion("ℹ️ About this AI Assistant & Data Source", open=False):
498
- gr.HTML(data_badge(
499
- "🧪 <b>Source:</b> hand-written by the developer — 10 original knowledge-base "
500
- "articles on warehouse operations (AS/RS, AGV/AMR, WMS, sortation, picking, "
501
- "maintenance, safety) plus ~480 template-generated example queries. "
502
- "Not scraped or sourced from any real company.<br>"
503
-
504
- "<b>What it describes:</b> generic intralogistics/automation concepts and "
505
- "operational scenarios (equipment faults, safety incidents, order/inventory "
506
- "questions) — general domain knowledge, not any specific facility's live data.<br>"
507
-
508
- "<b>Function:</b> answers free-text warehouse-ops questions by first classifying "
509
- "the query's intent, retrieving the most relevant knowledge-base passage(s) "
510
- "(RAG), then generating a grounded answer with a hosted LLM — falling back to "
511
- "showing the retrieved passages directly if no LLM is available."
512
- ))
513
  gr.ChatInterface(
514
  fn=chat_fn,
515
  type="messages",
@@ -528,27 +750,10 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue"), css=CUSTOM_CSS, title="
528
  test_llm_btn.click(test_llm_fn, inputs=None, outputs=test_llm_output)
529
 
530
  with gr.Tab("📦 Inventory & Order Query"):
531
- with gr.Accordion("ℹ️ About Data & Query System", open=False):
532
- gr.HTML(data_badge(
533
- f"🧪 <b>Source:</b> randomly generated by the developer's code "
534
- f"(<code>src/data_generation.py</code>, fixed seed) — "
535
- f"{len(inventory_df)} synthetic SKU records and "
536
- f"{len(orders_df)} synthetic orders. "
537
- "Not exported from any real company's WMS.<br>"
538
-
539
- "<b>What it describes:</b> a stand-in inventory table "
540
- "(SKU, category, zone, on-hand units, reorder point, unit cost) "
541
- "and orders table (order ID, status, line count, priority, zone) — "
542
- "realistic in shape and ranges, but fictional records, not live "
543
- "warehouse data.<br>"
544
-
545
- "<b>Function:</b> classifies whether a query is about inventory or "
546
- "order status, extracts SKU/order-ID/zone identifiers with regex, "
547
- "and filters the corresponding table — a lightweight stand-in "
548
- "for a natural-language WMS query tool."
549
- ))
550
  with gr.Row():
551
- inv_input = gr.Textbox(label="Query", placeholder="How many units of SKU-1042 are in Zone C?", scale=4)
552
  inv_btn = gr.Button("Search", variant="primary", scale=1)
553
  inv_note = gr.Markdown()
554
  inv_result = gr.Dataframe(label="Results", wrap=True)
@@ -557,11 +762,11 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue"), css=CUSTOM_CSS, title="
557
 
558
  gr.Examples(
559
  examples=[
560
- "How many units of SKU-1042 are in Zone C?",
561
  "What's the status of order #10007?",
562
  "Show me low stock items",
563
  "Any delayed orders?",
564
- "Is SKU-1015 in stock at Zone D?",
565
  "Do we have enough SKU-1030 to fulfill 200 units?",
566
  "Track order #10021 for me",
567
  "Show the fulfillment status of #10045",
@@ -575,20 +780,8 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue"), css=CUSTOM_CSS, title="
575
  gr.Dataframe(orders_df, wrap=True)
576
 
577
  with gr.Tab("⚠️ Predictive Maintenance"):
578
- with gr.Accordion("ℹ️ About Data & Predictive System", open=False):
579
- gr.HTML(data_badge(
580
- "🧪 <b>Source:</b> randomly generated by the developer's code "
581
- "(`src/data_generation.py`, fixed seed) — 1,000 synthetic sensor readings "
582
- "(900 normal + 100 simulated-fault). Not logged from real equipment.<br>"
583
- "<b>What it describes:</b> conveyor/crane motor sensor readings — temperature, "
584
- "vibration, current draw, and belt speed — with the 'anomaly' readings modelled "
585
- "on realistic failure signatures (elevated temp/vibration/current with reduced "
586
- "belt speed, as seen with bearing wear or motor overload).<br>"
587
- "<b>Function:</b> an Isolation Forest model trained unsupervised (it never sees "
588
- "an anomaly label) learns what 'normal' sensor behaviour looks like, then flags "
589
- "any new reading — like the ones you enter below — that deviates from it, as an "
590
- "early-warning signal before an unplanned equipment stoppage."
591
- ))
592
  preset_dropdown = gr.Dropdown(
593
  choices=list(ANOMALY_PRESETS.keys()), label="Load a preset reading", value="Normal reading"
594
  )
@@ -598,6 +791,9 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue"), css=CUSTOM_CSS, title="
598
  with gr.Row():
599
  current_in = gr.Slider(5, 30, value=12, step=0.5, label="Motor current (A)")
600
  belt_speed_in = gr.Slider(0.1, 2.5, value=1.5, step=0.05, label="Belt speed (m/s)")
 
 
 
601
  check_btn = gr.Button("Check for anomaly", variant="primary")
602
  anomaly_output = gr.Markdown()
603
 
@@ -607,16 +803,50 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue"), css=CUSTOM_CSS, title="
607
  )
608
  check_btn.click(
609
  anomaly_fn,
610
- inputs=[motor_temp_in, vibration_in, current_in, belt_speed_in],
611
  outputs=anomaly_output,
612
  )
613
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
614
  with gr.Tab("📊 Model Evaluation"):
615
- with gr.Accordion("ℹ️ About Model Evaluation", open=False):
616
- gr.HTML(data_badge(
617
- "🧪 All charts below are computed on <b>held-out test data</b> "
618
- "by <code>build_artifacts.py</code> — fully reproducible."
619
- ))
620
 
621
  gr.Markdown("### 1. Intent Classifier — accuracy: **{:.1%}** · macro F1: **{:.1%}**".format(
622
  intent_eval.get("accuracy", 0), intent_eval.get("macro_f1", 0)
@@ -643,6 +873,16 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue"), css=CUSTOM_CSS, title="
643
  gr.Markdown("### 4. Latency Benchmark (CPU, local components)")
644
  gr.Image(os.path.join(ASSETS_DIR, "latency_bar.png"), show_label=False, container=False)
645
 
 
 
 
 
 
 
 
 
 
 
646
  with gr.Accordion("📋 Full metrics tables & methodology notes", open=False):
647
  gr.Markdown(eval_intent_section_md())
648
  gr.Markdown(eval_anomaly_section_md())
@@ -651,7 +891,25 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue"), css=CUSTOM_CSS, title="
651
  gr.Markdown(EVAL_METHODOLOGY_MD)
652
 
653
  with gr.Tab("ℹ️ About"):
654
- gr.Markdown(ABOUT_MD)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
655
 
656
 
657
 
@@ -665,6 +923,6 @@ if __name__ == "__main__":
665
  # the Space if so.
666
  launch_kwargs = dict(server_name="0.0.0.0", server_port=int(os.environ.get("PORT", 7860)))
667
  try:
668
- demo.launch(**launch_kwargs, ssr=False)
669
  except TypeError:
670
  demo.launch(**launch_kwargs)
 
27
  from src.anomaly_model import FEATURES as SENSOR_FEATURES
28
  from src.anomaly_model import load_artifacts as load_anomaly_artifacts
29
  from src.anomaly_model import score_reading
30
+ from src.alerting import send_anomaly_alert
31
+ from src.vision_model import generate_rack_scene, detect_boxes
32
  from src.data_generation import generate_inventory_db, generate_orders_db
33
  from src.intent_model import INTENT_DESCRIPTIONS, load_pipeline, predict as intent_predict
34
  from src.inventory_db import query_inventory, query_orders
 
106
  anomaly_eval = _load_json("anomaly_eval.json")
107
  retrieval_eval = _load_json("retrieval_eval.json")
108
  latency_eval = _load_json("latency_eval.json")
109
+ vision_eval = _load_json("vision_eval.json")
110
 
111
  HF_TOKEN_SET = bool(_get_hf_token())
112
 
 
139
 
140
  def chat_fn(message, history):
141
  intent = intent_predict(intent_pipeline, message)
142
+ # `history` (Gradio messages format) is passed through so the LLM can handle
143
+ # follow-ups like "what about Zone D instead?" (bounded/cleaned in llm_client).
144
+ response = answer_query(message, retriever, history=history)
145
 
146
  intent_label = INTENT_DESCRIPTIONS.get(intent.intent, intent.intent)
147
  meta_lines = [f"**Detected intent:** {intent_label} ({intent.confidence:.0%} confidence)"]
 
220
  # TAB 3 -- Predictive Maintenance / Anomaly Detection
221
  # ==========================================================================
222
 
223
+ def anomaly_fn(motor_temp, vibration, current, belt_speed, zone_label="", send_alert=False):
224
  reading = {
225
+ "motor_temp_c": motor_temp, "vibration_mm_s": vibration,
226
+ "current_amps": current, "belt_speed_mps": belt_speed,
 
 
227
  }
228
  result = score_reading(anomaly_model, anomaly_scaler, reading, threshold=anomaly_threshold)
229
  verdict = "🔴 ANOMALY DETECTED" if result.is_anomaly else "🟢 Normal operating range"
230
  detail = (
231
  f"### {verdict}\n\n"
232
  f"**Anomaly score:** {result.anomaly_score:.2f} / 1.00\n\n"
233
+ f"| Sensor | Value | Typical normal range |\n|---|---|---|\n"
 
234
  f"| Motor temperature | {motor_temp:.1f} °C | 47–63 °C |\n"
235
  f"| Vibration | {vibration:.2f} mm/s | 1.2–3.2 mm/s |\n"
236
  f"| Motor current | {current:.1f} A | 9–15 A |\n"
 
243
  "wear, belt misalignment, or motor overload -- schedule maintenance before "
244
  "the next shift to avoid an unplanned stoppage."
245
  )
246
+ if send_alert:
247
+ alert = send_anomaly_alert(zone_label or "Unspecified zone", reading, result.anomaly_score)
248
+ if alert.sent:
249
+ detail += "\n\n---\n✅ **Alert sent to Slack.**"
250
+ else:
251
+ why = alert.error or "no `SLACK_WEBHOOK_URL` secret configured"
252
+ detail += (f"\n\n---\n📋 **Alert preview (NOT actually sent — {why}):**\n"
253
+ f"```\n{alert.message_preview}\n```")
254
  return detail
255
 
256
 
 
265
  return ANOMALY_PRESETS[name]
266
 
267
 
268
+ def anomaly_batch_fn(csv_file):
269
+ """CSV batch mode: run anomaly detection over many readings at once
270
+ (e.g. an export of the last shift's sensor logs)."""
271
+ if csv_file is None:
272
+ return "Upload a CSV first.", None, None
273
+ try:
274
+ batch_df = pd.read_csv(csv_file.name if hasattr(csv_file, "name") else csv_file)
275
+ except Exception as e: # noqa: BLE001
276
+ return f"Could not read CSV: {type(e).__name__}: {e}", None, None
277
+ missing = [c for c in SENSOR_FEATURES if c not in batch_df.columns]
278
+ if missing:
279
+ return (f"CSV is missing column(s): {', '.join(missing)}. Expected: "
280
+ f"{', '.join(SENSOR_FEATURES)} (optionally plus an `id` column).", None, None)
281
+ rows = []
282
+ for _, row in batch_df.iterrows():
283
+ reading = {f: float(row[f]) for f in SENSOR_FEATURES}
284
+ r = score_reading(anomaly_model, anomaly_scaler, reading, threshold=anomaly_threshold)
285
+ rows.append({**({"id": row["id"]} if "id" in batch_df.columns else {}),
286
+ **reading, "anomaly_score": round(r.anomaly_score, 3), "is_anomaly": r.is_anomaly})
287
+ out = pd.DataFrame(rows)
288
+ n_bad = int(out["is_anomaly"].sum())
289
+ summary = f"**Processed {len(out)} readings** — {n_bad} flagged anomalous ({n_bad / max(len(out), 1):.1%})."
290
+ path = os.path.join("/tmp", "anomaly_batch_results.csv")
291
+ out.to_csv(path, index=False)
292
+ return summary, out, path
293
+
294
+
295
+ SAMPLE_BATCH_CSV = os.path.join(DATA_DIR, "sample_sensor_batch.csv")
296
+ if not os.path.exists(SAMPLE_BATCH_CSV): # self-heal if the packaged sample is ever missing
297
+ import build_artifacts
298
+ build_artifacts.build_sample_batch_csv()
299
+
300
+
301
+ # ==========================================================================
302
+ # TAB 4 -- Visual Inventory Scan (classical computer vision)
303
+ # ==========================================================================
304
+
305
+ def vision_scan_fn(fill_density, noise_level, seed_state):
306
+ seed = int(seed_state) if seed_state is not None else 1
307
+ scene = generate_rack_scene(fill_prob=fill_density, seed=seed, noise_level=noise_level)
308
+ result = detect_boxes(scene.image)
309
+ diff = abs(result.detected_count - scene.true_box_count)
310
+ verdict = "✅ Exact match" if diff == 0 else f"⚠️ Off by {diff}"
311
+ summary = (
312
+ f"### Detected **{result.detected_count} boxes** · estimated occupancy **{result.estimated_occupancy:.0%}**\n\n"
313
+ f"| | CV pipeline | Ground truth |\n|---|---|---|\n"
314
+ f"| Box count | {result.detected_count} | {scene.true_box_count} |\n"
315
+ f"| Occupancy | {result.estimated_occupancy:.0%} | {scene.true_occupancy:.0%} |\n\n"
316
+ f"**{verdict}** — ground truth exists only because this scene is synthetic; "
317
+ f"a real deployment wouldn't have it."
318
+ )
319
+ return scene.image, result.annotated_image, summary, seed + 1
320
+
321
+
322
  # ==========================================================================
323
  # TAB 4 -- Model Evaluation
324
  # ==========================================================================
 
391
  systems (AS/RS), conveyor & sortation lines, AGVs/AMRs, and the WMS/WCS
392
  software that orchestrates them — generate huge volumes of operational
393
  data: equipment telemetry, transactions, safety logs, and ad-hoc questions
394
+ from floor staff. This project is a compact, end-to-end example of how an
395
+ AI layer can sit on top of that kind of system: routing requests correctly,
396
+ answering from real operational context instead of guessing, catching
397
+ equipment problems early, and doing all of it with **honest, reproducible
398
+ evaluation** rather than a demo that just "looks like it works."
399
 
400
  ## What this demonstrates
401
 
 
418
 
419
  | Dataset | What it is | Size | How it's generated |
420
  |---|---|---|---|
421
+ | **Knowledge base** | Original, hand-written articles on generic warehouse-automation concepts (AS/RS, AGV/AMR, WMS, sortation, picking strategy, predictive maintenance, safety, inventory accuracy, KPIs, energy efficiency, cross-docking, returns, RFID, dock scheduling, slotting, security, labor management) | 17 articles | Written by the developer specifically for this project |
422
  | **Intent queries** | Example free-text operational questions/requests across 8 categories | ~480 examples | ~8 templates per category with randomised SKU codes, zone names, order IDs, and equipment IDs slotted in |
423
  | **Inventory table** | SKU records with category, zone, on-hand units, reorder point, unit cost | 60 SKUs | Randomised within realistic ranges (fixed seed) |
424
  | **Orders table** | Order records with status, line count, priority, zone | 80 orders | Randomised within realistic ranges (fixed seed) |
425
  | **Sensor readings** | Conveyor/crane motor telemetry: temperature, vibration, current, belt speed | 1,000 readings (900 normal + 100 anomalous) | Normal readings drawn from realistic operating ranges; anomalies simulate known failure signatures (elevated temp/vibration/current + reduced belt speed) |
426
+ | **Retrieval eval set** | Hand-labelled (question → expected knowledge-base article) pairs | 17 pairs | Written by the developer to check retrieval accuracy |
427
 
428
  ## How each model works (function)
429
 
 
509
  being honestly evaluated, rather than reaching for the biggest available
510
  model by default.
511
 
512
+ ## Extended capabilities
513
+
514
+ - **Multi-turn conversation** — the assistant keeps the last few turns, so follow-ups like *"what about Zone D instead?"* work.
515
+ - **📷 Visual Inventory Scan** — a classical (non-deep-learning) computer-vision pipeline counts boxes and estimates occupancy on synthetic rack images. Evaluated honestly: **100%** on clean renders, but it degrades as simulated photographic noise rises, so the headline number is reported at a moderate noise level (see Model Evaluation).
516
+ - **Batch CSV scoring** — upload a CSV of sensor readings (a sample is provided) to score a whole shift's logs at once, and download the results.
517
+ - **Slack alerting** — anomalies can trigger a Slack alert. Real if a `SLACK_WEBHOOK_URL` secret is set; otherwise a clearly-labelled preview that is *never* presented as sent.
518
+ - **Bilingual UI** — switch the explanatory text between English and 日本語 with the selector at the top. (Charts and metric tables stay in English; the assistant answers in whatever language you ask in.)
519
+
520
  ## Limitations & next steps
521
 
522
  - All data here is **synthetic**, for portfolio/demo purposes — a production
523
  version would connect to real WMS/WCS APIs and historical sensor logs.
524
+ - The intent set (8 classes) and knowledge base (17 articles) are intentionally
525
  small to keep the demo fast and auditable; both are easy to extend.
526
  - The anomaly detector uses 4 hand-picked features; a production system would
527
  likely use a richer multivariate sensor set and a supervised or
 
552
  .data-badge b { color: #1e3a8a; }
553
  """
554
 
555
+
556
+ # ==========================================================================
557
+ # Bilingual (English / 日本語) static content
558
+ # ==========================================================================
559
+ # Static explanatory text (subtitle, per-tab data/function panels, About tab)
560
+ # is switchable via the language selector. Dynamic content (charts, metric
561
+ # tables, the LLM's answers) stays in English; the assistant itself will
562
+ # answer in whatever language the question is asked in, since the hosted LLM
563
+ # is multilingual.
564
+
565
+ from src.knowledge_base import KNOWLEDGE_BASE
566
+ _N_KB = len(KNOWLEDGE_BASE)
567
+ I18N = {
568
+ "subtitle": {
569
+ "en": "<p style='text-align:center; color:gray;'>LLM-powered intralogistics copilot · intent routing · "
570
+ "multi-turn RAG · predictive maintenance · computer vision</p>",
571
+ "ja": "<p style='text-align:center; color:gray;'>LLM搭載の物流オペレーション支援AI · 意図分類 · "
572
+ "マルチターン対話(RAG) · 予知保全 · コンピュータビジョン</p>",
573
+ },
574
+ "badge_assistant": {
575
+ "en": "🧪 <b>Source:</b> hand-written by the developer — %d original knowledge-base articles on warehouse "
576
+ "operations (AS/RS, AGV/AMR, WMS, sortation, picking, maintenance, safety, cross-docking, RFID, slotting, "
577
+ "labor management…) plus ~480 template-generated example queries. Not scraped or sourced from any real company.<br>"
578
+ "<b>What it describes:</b> generic intralogistics/automation concepts and operational scenarios (equipment "
579
+ "faults, safety incidents, order/inventory questions) — general domain knowledge, not any specific facility's live data.<br>"
580
+ "<b>Function:</b> answers free-text warehouse-ops questions by classifying the query's intent, retrieving the "
581
+ "most relevant knowledge-base passage(s) (RAG), then generating a grounded answer with a hosted LLM. It keeps the "
582
+ "last few turns of the conversation, so follow-ups like “what about Zone D instead?” work. If no LLM is available, "
583
+ "it falls back to showing the retrieved passages directly." % _N_KB,
584
+ "ja": "🧪 <b>データの出典:</b>開発者が手書きした倉庫運用ナレッジ記事%d本(AS/RS、AGV/AMR、WMS、仕分け、ピッキング、保全、安全、"
585
+ "クロスドッキング、RFID、スロッティング、労務管理など)と、テンプレートから生成した約480件の問い合わせ例。"
586
+ "実在企業のデータは使用していません。<br>"
587
+ "<b>内容:</b>物流・自動化に関する一般的な概念と運用シナリオ(設備故障、安全インシデント、在庫・注文の問い合わせ等)であり、"
588
+ "特定施設のリアルタイムデータではありません。<br>"
589
+ "<b>機能:</b>自由入力の質問に対して、①意図分類 → ②ナレッジ検索(RAG)→ ③ホスト型LLMによる回答生成の順に処理します。"
590
+ "直近の会話履歴も保持するため、「Zone Dの場合は?」のような追加質問にも対応します。LLMが利用できない場合は、"
591
+ "検索結果をそのまま表示します。" % _N_KB,
592
+ },
593
+ "badge_inventory": {
594
+ "en": f"🧪 <b>Source:</b> randomly generated by the developer's code (<code>src/data_generation.py</code>, fixed seed) — "
595
+ f"{len(inventory_df)} synthetic SKU records and {len(orders_df)} synthetic orders. Not exported from any real company's WMS.<br>"
596
+ "<b>What it describes:</b> a stand-in inventory table (SKU, category, zone, on-hand units, reorder point, unit cost) and "
597
+ "orders table (order ID, status, line count, priority, zone) — realistic in shape, but fictional records.<br>"
598
+ "<b>Function:</b> classifies whether a query is about inventory or order status, extracts SKU / order-ID / zone "
599
+ "identifiers with regex, and filters the matching table — a lightweight stand-in for a natural-language WMS query tool.",
600
+ "ja": f"🧪 <b>データの出典:</b>開発者のコード(<code>src/data_generation.py</code>、乱数シード固定)で生成した合成データ"
601
+ f"(SKU {len(inventory_df)}件、注文 {len(orders_df)}件)。実在企業のWMSから出力したものではありません。<br>"
602
+ "<b>内容:</b>在庫テーブル(SKU・カテゴリ・ゾーン・在庫数・発注点・単価)と注文テーブル(注文ID・ステータス・明細数・優先度・ゾーン)。"
603
+ "形式は現実的ですが、内容は架空のレコードです。<br>"
604
+ "<b>機能:</b>問い合わせが在庫か注文状況かを分類し、SKU・注文ID・ゾーンを正規表現で抽出して該当テーブルを絞り込みます。"
605
+ "自然言語によるWMS照会ツールの簡易版です。",
606
+ },
607
+ "badge_predictive": {
608
+ "en": "🧪 <b>Source:</b> randomly generated by the developer's code (<code>src/data_generation.py</code>, fixed seed) — 1,000 synthetic "
609
+ "sensor readings (900 normal + 100 simulated-fault). Not logged from real equipment.<br>"
610
+ "<b>What it describes:</b> conveyor/crane motor readings — temperature, vibration, current draw, belt speed — with 'anomaly' "
611
+ "readings modelled on failure signatures (elevated temp/vibration/current with reduced belt speed, as with bearing wear or overload).<br>"
612
+ "<b>Function:</b> an Isolation Forest is fit unsupervised (it never sees an anomaly label while fitting); its decision threshold "
613
+ "is then calibrated on a small labelled calibration set (never on test data). Check one reading with the sliders, or upload a CSV "
614
+ "to score a whole shift's logs. Anomalies can trigger a Slack alert (real if a <code>SLACK_WEBHOOK_URL</code> secret is set, "
615
+ "otherwise a clearly-labelled preview).",
616
+ "ja": "🧪 <b>データの出典:</b>開発者のコード(<code>src/data_generation.py</code>、乱数シード固定)で生成した合成センサーデータ1,000件"
617
+ "(正常900+故障模擬100)。実機のログではありません。<br>"
618
+ "<b>内容:</b>コンベヤ/クレーンのモーター計測値(温度・振動・電流・ベルト速度)。異常データは、ベアリング摩耗や過負荷に見られる"
619
+ "故障パターン(温度・振動・電流の上昇とベルト速度の低下)を模して作成しています。<br>"
620
+ "<b>機能:</b>Isolation Forestを教師なしで学習し(学習時に異常ラベルは使用しません)、判定しきい値は少量のラベル付き較正データで調整します"
621
+ "(テストデータは使用しません)。スライダーで1件を判定するほか、CSVをアップロードしてシフト全体のログを一括判定できます。"
622
+ "異常時はSlack通知が可能です(<code>SLACK_WEBHOOK_URL</code>設定時は実送信、未設定時はプレビュー表示)。",
623
+ },
624
+ "badge_vision": {
625
+ "en": "🧪 <b>Source:</b> synthetic rack-scene images generated by the developer's code (<code>src/vision_model.py</code>) — not real "
626
+ "warehouse photos (none were available to license).<br>"
627
+ "<b>What it describes:</b> a simplified front view of a 3-row × 6-column storage rack with randomly placed box-like shapes "
628
+ "standing in for pallets/cartons, plus adjustable simulated photographic noise.<br>"
629
+ "<b>Function:</b> a <i>classical</i> (non-deep-learning) computer-vision pipeline — colour-based background/shelf segmentation, "
630
+ "morphological cleanup, connected components, geometric filtering — counts boxes and estimates rack occupancy. Deliberately the "
631
+ "opposite of a pretrained detector: zero model downloads, fully explainable, instant on CPU. The Model Evaluation tab shows how "
632
+ "accuracy degrades as noise rises.",
633
+ "ja": "🧪 <b>データの出典:</b>開発者のコード(<code>src/vision_model.py</code>)で生成した合成のラック画像。実際の倉庫写真ではありません"
634
+ "(利用可能なライセンス素材がないため)。<br>"
635
+ "<b>内容:</b>3段×6列の保管ラックを正面から見た簡易画像で、パレット/ケースに見立てた箱がランダムに配置されます。"
636
+ "撮影ノイズの強さも調整できます。<br>"
637
+ "<b>機能:</b>深層学習を使わない<i>古典的</i>な画像処理パイプライン(色によるラック背景の分離 → モルフォロジー処理 → 連結成分抽出 → "
638
+ "形状フィルタ)で、箱の数と棚の占有率を推定します。学習済みモデルのダウンロードが不要で、処理過程を説明でき、CPUで即時に動作します。"
639
+ "ノイズ増加時の精度低下は「Model Evaluation」タブで確認できます。",
640
+ },
641
+ "badge_eval": {
642
+ "en": "🧪 All charts below are computed on <b>held-out test data</b> by <code>build_artifacts.py</code> — fully reproducible, not cherry-picked.",
643
+ "ja": "🧪 以下の図表はすべて、<code>build_artifacts.py</code>が<b>ホールドアウトしたテストデータ</b>で算出したものです。再現可能で、結果の取捨選択は行っていません。",
644
+ },
645
+ }
646
+
647
+
648
+ def about_ja() -> str:
649
+ return f"""
650
+ # 🏭 スマート倉庫AIアシスタント
651
+
652
+ **物流・倉庫自動化の運用を題材に、実務的なAI活用を示すポートフォリオプロジェクトです。**
653
+
654
+ AS/RS、コンベヤ・仕分け、AGV/AMR、WMS/WCSといった倉庫自動化の現場では、設備テレメトリ、取引データ、安全記録、現場からの問い合わせなど
655
+ 大量の運用データが生まれます。本プロジェクトは、その上にAIレイヤーを載せる最小構成の実装例です。依頼を正しく振り分け、推測ではなく
656
+ 根拠のある情報で回答し、設備の異常を早期に検出し、さらに**再現可能で誠実な評価**を行うことを重視しています。
657
+
658
+ ## 機能一覧
659
+
660
+ | 機能 | タブ | 主な技術 |
661
+ |---|---|---|
662
+ | ナレッジに基づく**LLM対話アシスタント**(RAG/マルチターン会話対応) | AI Assistant | TF-IDF検索 + ホスト型LLM |
663
+ | **意図分類**による問い合わせの振り分け(8カテゴリ) | AI Assistant / Inventory | TF-IDF + ロジスティック回帰 |
664
+ | 在庫・注文の**自然文照会** | Inventory & Order Query | 正規表現によるスロット抽出 + 意図分類 |
665
+ | センサーデータの**予知保全**(1件判定/CSV一括判定/Slack通知) | Predictive Maintenance | Isolation Forest(教師なし)+ 較正済みしきい値 |
666
+ | ラック画像の**箱数カウントと占有率推定** | Visual Inventory Scan | 古典的画像処理(OpenCV) |
667
+ | 全コンポーネントの**再現可能な評価** | Model Evaluation | scikit-learn指標、ホールドアウト検証 |
668
+
669
+ ## データセットの概要
670
+
671
+ **本プロジェクトのデータはすべて、自作コードによる合成データです。**実在企業のシステムからの取得・流用は一切ありません。
672
+ プライバシーやライセンスの懸念なく、誰でも再現・共有できます。
673
+
674
+ | データ | 内容 | 件数 | 生成方法 |
675
+ |---|---|---|---|
676
+ | ナレッジベース | 倉庫自動化の一般的概念を解説した手書き記事 | {_N_KB}記事 | 本プロジェクトのために作成 |
677
+ | 意図分類クエリ | 8カテゴリの問い合わせ例 | 約480件 | テンプレートにSKU・ゾーン・設備IDなどをランダムに埋め込み |
678
+ | 在庫テーブル | SKU・カテゴリ・ゾーン・在庫数・発注点・単価 | 60 SKU | 現実的な範囲でランダム生成(シード固定) |
679
+ | 注文テーブル | ステータス・明細数・優先度・ゾーン | 80件 | 現実的な範囲でランダム生成(シード固定) |
680
+ | センサーデータ | 温度・振動・電流・ベルト速度 | 1,000件(正常900/異常100) | 正常は運転範囲から、異常は故障パターンを模して生成 |
681
+ | ラック画像 | 箱の配置が既知の合成画像 | 随時生成 | PILで描画。ノイズ強度を調整可能 |
682
+ | 検索評価セット | 質問と正解記事のペア | {_N_KB}組 | 検索精度確認のため手作業で作成 |
683
+
684
+ ## 各モデルの役割
685
+
686
+ | モデル | 目的 | アルゴリズム | 入力 → 出力 |
687
+ |---|---|---|---|
688
+ | 意図分類器 | 問い合わせの種類を判定 | TF-IDF + ロジスティック回帰 | 文章 → 意図ラベル + 確信度 |
689
+ | 検索(RAG) | 回答の根拠となる記事を取得 | TF-IDF + コサイン類似度 | 文章 → 関連記事の上位k件 |
690
+ | LLMアシスタント | 根拠に基づく自然な回答を生成 | ホスト型LLM(複数モデルのフォールバック) | 質問 + 根拠 + 会話履歴 → 回答 |
691
+ | 在庫・注文照会 | 質問をテーブル検索に変換 | 正規表現 + 意図分類 | 文章 → 絞り込み結果 |
692
+ | 異常検知 | 設備の異常な計測値を早期に検出 | Isolation Forest + 較正済みしきい値 | 4つのセンサー値 → 正常/異常 + スコア |
693
+ | ラックスキャナ | 箱の数と占有率を推定 | 色分離 + 輪郭抽出(古典的画像処理) | 画像 → 箱数 + 占有率 + 検出枠 |
694
+
695
+ ## 試し方
696
+
697
+ 1. **AI Assistant** — 例の質問を選ぶか自由に入力します。続けて「Zone Dの場合は?」などと尋ねると、直前の文脈を踏まえて回答します。
698
+ 2. **Inventory & Order Query** — 「SKU-1042 は Zone B に何個ある?」「注文 #10007 の状況は?」などを試します。
699
+ 3. **Predictive Maintenance** — プリセットまたはスライダーで1件を判定します。「CSV一括判定」でサンプルCSVをダウンロードし、そのままアップロードして一括判定も試せます。
700
+ 4. **Visual Inventory Scan** — 「新しいラック画像を生成」を押し、ノイズを上げて検出が難しくなる様子を確認します。
701
+ 5. **Model Evaluation** — すべての図表はテストデータで算出しており、`build_artifacts.py`を再実行すれば同じ数値を再現できます。
702
+
703
+ ## 評価の信頼性について
704
+
705
+ 開発中に2件のデータリーク(意図分類での学習/テスト間の文面重複、異常検知でのしきい値への正解率の混入)を発見・修正しました。
706
+ 修正後の指標は、意図分類 正解率 {intent_eval.get('accuracy', 0):.1%}、異常検知 F1 {anomaly_eval.get('f1', 0):.1%} です。
707
+ 画像パイプラインも、ノイズなしでは100%となるため、ノイズを加えた条件(標準ノイズ0.4で完全一致率 {vision_eval.get('exact_match_rate', 0):.0%})を報告しています。
708
+
709
+ ## 制約と今後の課題
710
+
711
+ - データはすべて**合成**です。実運用ではWMS/WCSのAPIや実際のセンサーログに接続します。
712
+ - 画像は単純化した合成ラックであり、実写真への適用には学習済み検出器(YOLO等)の微調整が現実的です。
713
+ - Slack通知は`SLACK_WEBHOOK_URL`未設定の場合はプレビューのみで、実際には送信されません。
714
+ """
715
+
716
+
717
  def data_badge(html: str) -> str:
718
  return f'<div class="data-badge">{html}</div>'
719
 
720
  with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue"), css=CUSTOM_CSS, title="Smart Warehouse AI Assistant") as demo:
721
+ gr.Markdown("<h1 id='title-banner'>🏭 Smart Warehouse AI Assistant</h1>")
722
+ subtitle_md = gr.Markdown(I18N["subtitle"]["en"])
723
+ lang_radio = gr.Radio(["English", "日本語"], value="English", label="🌐 Language / 言語", interactive=True)
 
 
724
  if not HF_TOKEN_SET:
725
  gr.Markdown(
726
  "> ⚠️ **No HF token secret detected.** The AI Assistant tab will run in "
 
730
  )
731
 
732
  with gr.Tab("💬 AI Assistant"):
733
+ with gr.Accordion("🧪 About this data & function / データ・機能について", open=False):
734
+ badge_assistant = gr.HTML(data_badge(I18N["badge_assistant"]["en"]))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
735
  gr.ChatInterface(
736
  fn=chat_fn,
737
  type="messages",
 
750
  test_llm_btn.click(test_llm_fn, inputs=None, outputs=test_llm_output)
751
 
752
  with gr.Tab("📦 Inventory & Order Query"):
753
+ with gr.Accordion("🧪 About this data & function / データ・機能について", open=False):
754
+ badge_inventory = gr.HTML(data_badge(I18N["badge_inventory"]["en"]))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
755
  with gr.Row():
756
+ inv_input = gr.Textbox(label="Query", placeholder="How many units of SKU-1042 are in Zone B?", scale=4)
757
  inv_btn = gr.Button("Search", variant="primary", scale=1)
758
  inv_note = gr.Markdown()
759
  inv_result = gr.Dataframe(label="Results", wrap=True)
 
762
 
763
  gr.Examples(
764
  examples=[
765
+ "How many units of SKU-1042 are in Zone B?",
766
  "What's the status of order #10007?",
767
  "Show me low stock items",
768
  "Any delayed orders?",
769
+ "Is SKU-1015 in stock at Zone A?",
770
  "Do we have enough SKU-1030 to fulfill 200 units?",
771
  "Track order #10021 for me",
772
  "Show the fulfillment status of #10045",
 
780
  gr.Dataframe(orders_df, wrap=True)
781
 
782
  with gr.Tab("⚠️ Predictive Maintenance"):
783
+ with gr.Accordion("🧪 About this data & function / データ・機能について", open=False):
784
+ badge_predictive = gr.HTML(data_badge(I18N["badge_predictive"]["en"]))
 
 
 
 
 
 
 
 
 
 
 
 
785
  preset_dropdown = gr.Dropdown(
786
  choices=list(ANOMALY_PRESETS.keys()), label="Load a preset reading", value="Normal reading"
787
  )
 
791
  with gr.Row():
792
  current_in = gr.Slider(5, 30, value=12, step=0.5, label="Motor current (A)")
793
  belt_speed_in = gr.Slider(0.1, 2.5, value=1.5, step=0.05, label="Belt speed (m/s)")
794
+ with gr.Row():
795
+ zone_label_in = gr.Textbox(label="Equipment / zone label (used in alerts)", placeholder="e.g. Conveyor-14, Zone C", scale=3)
796
+ send_alert_in = gr.Checkbox(label="Send Slack alert if anomalous", value=False, scale=1)
797
  check_btn = gr.Button("Check for anomaly", variant="primary")
798
  anomaly_output = gr.Markdown()
799
 
 
803
  )
804
  check_btn.click(
805
  anomaly_fn,
806
+ inputs=[motor_temp_in, vibration_in, current_in, belt_speed_in, zone_label_in, send_alert_in],
807
  outputs=anomaly_output,
808
  )
809
 
810
+ with gr.Accordion("📋 Batch mode: upload a CSV of sensor readings", open=False):
811
+ gr.Markdown(
812
+ f"Upload a CSV with columns `{'`, `'.join(SENSOR_FEATURES)}` (optionally an `id` column) to run "
813
+ "detection over many readings at once — e.g. an export of the last shift's sensor logs. "
814
+ "Don't have one? Download the sample below and upload it back."
815
+ )
816
+ gr.File(value=SAMPLE_BATCH_CSV, label="Sample CSV (40 readings, ~15% faulty)", interactive=False)
817
+ batch_csv_in = gr.File(label="Your sensor readings CSV", file_types=[".csv"])
818
+ batch_btn = gr.Button("Run batch detection")
819
+ batch_summary = gr.Markdown()
820
+ batch_results = gr.Dataframe(label="Results", wrap=True)
821
+ batch_download = gr.File(label="Download results CSV")
822
+ batch_btn.click(anomaly_batch_fn, inputs=batch_csv_in,
823
+ outputs=[batch_summary, batch_results, batch_download])
824
+
825
+ with gr.Tab("📷 Visual Inventory Scan"):
826
+ with gr.Accordion("🧪 About this data & function / データ・機能について", open=False):
827
+ badge_vision = gr.HTML(data_badge(I18N["badge_vision"]["en"]))
828
+ gr.Markdown(
829
+ "Generate a synthetic rack photo and watch the pipeline count boxes and estimate "
830
+ "occupancy. Raise the noise slider to see detection get harder, the way a dim or "
831
+ "grainy real photo would."
832
+ )
833
+ with gr.Row():
834
+ fill_density_in = gr.Slider(0.1, 0.95, value=0.6, step=0.05, label="Rack fill density (scene generation)")
835
+ noise_in = gr.Slider(0.0, 1.0, value=0.3, step=0.05, label="Simulated photographic noise")
836
+ vision_seed_state = gr.State(value=1)
837
+ new_scene_btn = gr.Button("🎲 Generate new rack scene", variant="primary")
838
+ with gr.Row():
839
+ vision_raw_img = gr.Image(label="Rack photo (input)", type="pil")
840
+ vision_annotated_img = gr.Image(label="Detected boxes (output)", type="pil")
841
+ vision_summary = gr.Markdown()
842
+ _vision_io = dict(inputs=[fill_density_in, noise_in, vision_seed_state],
843
+ outputs=[vision_raw_img, vision_annotated_img, vision_summary, vision_seed_state])
844
+ new_scene_btn.click(vision_scan_fn, **_vision_io)
845
+ demo.load(vision_scan_fn, **_vision_io)
846
+
847
  with gr.Tab("📊 Model Evaluation"):
848
+ with gr.Accordion("🧪 About this data & function / データ・機能について", open=False):
849
+ badge_eval = gr.HTML(data_badge(I18N["badge_eval"]["en"]))
 
 
 
850
 
851
  gr.Markdown("### 1. Intent Classifier — accuracy: **{:.1%}** · macro F1: **{:.1%}**".format(
852
  intent_eval.get("accuracy", 0), intent_eval.get("macro_f1", 0)
 
873
  gr.Markdown("### 4. Latency Benchmark (CPU, local components)")
874
  gr.Image(os.path.join(ASSETS_DIR, "latency_bar.png"), show_label=False, container=False)
875
 
876
+ gr.Markdown("### 5. Visual Inventory Scan — exact box-count match: **{:.0%}** (noise={}) · count MAE: **{:.2f}** boxes".format(
877
+ vision_eval.get("exact_match_rate", 0), vision_eval.get("standard_noise_level", "?"), vision_eval.get("count_mae", 0)
878
+ ))
879
+ with gr.Row():
880
+ gr.Image(os.path.join(ASSETS_DIR, "vision_metrics_bar.png"), show_label=False, container=False)
881
+ gr.Image(os.path.join(ASSETS_DIR, "vision_noise_robustness.png"), show_label=False, container=False)
882
+ with gr.Row():
883
+ gr.Image(os.path.join(ASSETS_DIR, "vision_sample_raw.png"), label="Sample input", container=True)
884
+ gr.Image(os.path.join(ASSETS_DIR, "vision_sample_annotated.png"), label="Sample detection", container=True)
885
+
886
  with gr.Accordion("📋 Full metrics tables & methodology notes", open=False):
887
  gr.Markdown(eval_intent_section_md())
888
  gr.Markdown(eval_anomaly_section_md())
 
891
  gr.Markdown(EVAL_METHODOLOGY_MD)
892
 
893
  with gr.Tab("ℹ️ About"):
894
+ about_md = gr.Markdown(ABOUT_MD)
895
+
896
+ def set_language(lang):
897
+ k = "ja" if lang == "日本語" else "en"
898
+ return (
899
+ I18N["subtitle"][k],
900
+ data_badge(I18N["badge_assistant"][k]),
901
+ data_badge(I18N["badge_inventory"][k]),
902
+ data_badge(I18N["badge_predictive"][k]),
903
+ data_badge(I18N["badge_vision"][k]),
904
+ data_badge(I18N["badge_eval"][k]),
905
+ about_ja() if k == "ja" else ABOUT_MD,
906
+ )
907
+
908
+ lang_radio.change(
909
+ set_language, inputs=lang_radio,
910
+ outputs=[subtitle_md, badge_assistant, badge_inventory, badge_predictive,
911
+ badge_vision, badge_eval, about_md],
912
+ )
913
 
914
 
915
 
 
923
  # the Space if so.
924
  launch_kwargs = dict(server_name="0.0.0.0", server_port=int(os.environ.get("PORT", 7860)))
925
  try:
926
+ demo.launch(**launch_kwargs, ssr_mode=False)
927
  except TypeError:
928
  demo.launch(**launch_kwargs)
assets/anomaly_confusion_matrix.png CHANGED
assets/anomaly_metrics_bar.png CHANGED
assets/anomaly_roc_curve.png CHANGED
assets/intent_confusion_matrix.png CHANGED

Git LFS Details

  • SHA256: 68d9a6c328c2185ac0743e1dda41b95809d210a8185ead73da76720c3f85b4a3
  • Pointer size: 131 Bytes
  • Size of remote file: 102 kB
assets/intent_dataset_composition.png CHANGED
assets/intent_per_class_bar.png CHANGED
assets/latency_bar.png CHANGED
assets/retrieval_hitrate_bar.png CHANGED
assets/sensor_distributions.png CHANGED

Git LFS Details

  • SHA256: c6aba3db587759d8c735aa19fdf5cdd8d09c98d9fd63f77af33c2d5ba81aa2d2
  • Pointer size: 131 Bytes
  • Size of remote file: 100 kB
assets/vision_metrics_bar.png ADDED
assets/vision_noise_robustness.png ADDED
assets/vision_sample_annotated.png ADDED

Git LFS Details

  • SHA256: 130febd51d07b8b7ddb384969b8b6e76238131fa12eb03f15bc3d2bb8e507667
  • Pointer size: 131 Bytes
  • Size of remote file: 429 kB
assets/vision_sample_raw.png ADDED

Git LFS Details

  • SHA256: 15bb7f8e95bebe1ebd4ce6e880b1599787732f2ee36d219cafac0f57654e642e
  • Pointer size: 131 Bytes
  • Size of remote file: 439 kB
build_artifacts.py CHANGED
@@ -446,10 +446,83 @@ def build_latency_benchmark(intent_metrics, anomaly_metrics):
446
  plt.close(fig)
447
 
448
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
449
  if __name__ == "__main__":
450
  intent_metrics = build_intent_classifier()
451
  anomaly_metrics = build_anomaly_detector()
452
  build_retrieval_eval()
453
  build_inventory_and_orders()
454
  build_latency_benchmark(intent_metrics, anomaly_metrics)
 
 
455
  print("\nAll artifacts built successfully.")
 
446
  plt.close(fig)
447
 
448
 
449
+ def build_sample_batch_csv():
450
+ """A small downloadable CSV (40 readings, ~15% faulty) for demoing the app's
451
+ batch-upload mode. Fresh seed -> not drawn from the model's training data."""
452
+ from src.data_generation import generate_sensor_dataset
453
+ df = generate_sensor_dataset(n_normal=34, n_anomaly=6, seed=7)
454
+ out = df[FEATURES].round(2)
455
+ out.insert(0, "id", [f"R{i + 1:03d}" for i in range(len(out))])
456
+ out.to_csv(os.path.join(DATA_DIR, "sample_sensor_batch.csv"), index=False)
457
+ print(f"sample batch CSV written ({len(out)} rows)")
458
+
459
+
460
+ def build_vision_evaluation():
461
+ """Evaluate the classical-CV rack scanner on synthetic scenes with known ground
462
+ truth: headline metrics at a moderate noise level (0.4) plus a noise sweep, so
463
+ the result isn't a suspiciously perfect number measured on clean renders only."""
464
+ print("== Vision: rack box-counting / occupancy ==")
465
+ from src.vision_model import generate_rack_scene, detect_boxes
466
+
467
+ STD, N = 0.4, 100
468
+ exact, cerr, oerr = 0, [], []
469
+ for i in range(N):
470
+ sc = generate_rack_scene(0.25 + (i % 8) * 0.08, 1000 + i, STD)
471
+ r = detect_boxes(sc.image)
472
+ exact += int(r.detected_count == sc.true_box_count)
473
+ cerr.append(abs(r.detected_count - sc.true_box_count))
474
+ oerr.append(abs(r.estimated_occupancy - sc.true_occupancy))
475
+ exact_rate, count_mae, occ_mae = exact / N, float(np.mean(cerr)), float(np.mean(oerr))
476
+ print(f"[noise={STD}] exact_match={exact_rate:.3f} count_MAE={count_mae:.3f} occ_MAE={occ_mae:.4f}")
477
+
478
+ levels = [0.0, 0.2, 0.4, 0.6, 0.8, 1.0]
479
+ sweep = []
480
+ for nz in levels:
481
+ n, m = 60, 0
482
+ for i in range(n):
483
+ sc = generate_rack_scene(0.3 + (i % 7) * 0.1, 2000 + i, nz)
484
+ m += int(detect_boxes(sc.image).detected_count == sc.true_box_count)
485
+ sweep.append(m / n)
486
+ print(f" sweep noise={nz:.1f} exact_match={m / n:.3f}")
487
+
488
+ fig, ax = plt.subplots(figsize=(6.5, 4.5))
489
+ ax.plot(levels, [v * 100 for v in sweep], marker="o", color="#7c3aed", linewidth=2, markersize=7)
490
+ ax.set_xlabel("Simulated photographic noise level"); ax.set_ylabel("Exact box-count match rate (%)")
491
+ ax.set_title("Vision Pipeline: Accuracy vs. Noise Level"); ax.set_ylim(0, 105); ax.grid(alpha=0.3)
492
+ fig.tight_layout(); fig.savefig(os.path.join(ASSETS_DIR, "vision_noise_robustness.png"), dpi=150); plt.close(fig)
493
+
494
+ # three separately-scaled panels (percent / boxes / percentage points are not comparable)
495
+ fig, axes = plt.subplots(1, 3, figsize=(9, 4))
496
+ panels = [("Exact count\nmatch rate", exact_rate * 100, "%", 100, "#7c3aed"),
497
+ ("Count MAE", count_mae, "boxes", max(1, count_mae * 2), "#f59e0b"),
498
+ ("Occupancy MAE", occ_mae * 100, "pp", max(5, occ_mae * 200), "#10b981")]
499
+ for ax, (name, val, unit, ymax, color) in zip(axes, panels):
500
+ ax.bar([name], [val], color=color, width=0.5); ax.set_ylim(0, ymax * 1.25); ax.set_ylabel(unit)
501
+ ax.text(0, val, f"{val:.2f}", ha="center", va="bottom", fontsize=11, fontweight="bold")
502
+ ax.grid(axis="y", alpha=0.3)
503
+ fig.suptitle(f"Vision Pipeline Metrics (noise={STD})")
504
+ fig.tight_layout(); fig.savefig(os.path.join(ASSETS_DIR, "vision_metrics_bar.png"), dpi=150); plt.close(fig)
505
+
506
+ demo_scene = generate_rack_scene(0.55, 42, STD)
507
+ detect_boxes(demo_scene.image).annotated_image.save(os.path.join(ASSETS_DIR, "vision_sample_annotated.png"))
508
+ demo_scene.image.save(os.path.join(ASSETS_DIR, "vision_sample_raw.png"))
509
+
510
+ metrics = {"standard_noise_level": STD, "n_test": N, "exact_match_rate": exact_rate,
511
+ "count_mae": count_mae, "occupancy_mae": occ_mae,
512
+ "noise_sweep_levels": levels, "noise_sweep_exact_match_rates": sweep,
513
+ "method": "Classical CV: color-distance segmentation -> morphology -> connected "
514
+ "components -> geometric filtering. No pretrained weights."}
515
+ with open(os.path.join(DATA_DIR, "vision_eval.json"), "w") as f:
516
+ json.dump(metrics, f, indent=2)
517
+ return metrics
518
+
519
+
520
  if __name__ == "__main__":
521
  intent_metrics = build_intent_classifier()
522
  anomaly_metrics = build_anomaly_detector()
523
  build_retrieval_eval()
524
  build_inventory_and_orders()
525
  build_latency_benchmark(intent_metrics, anomaly_metrics)
526
+ build_vision_evaluation()
527
+ build_sample_batch_csv()
528
  print("\nAll artifacts built successfully.")
data/intent_dataset.csv CHANGED
@@ -1,141 +1,141 @@
1
  text,intent
2
- What's the fastest picking route for order #45024?,picking_optimization
3
  Pause AGV-12 until the aisle in Zone E is clear,agv_navigation
4
- Is order #22400 delayed?,order_status
5
  Report unsafe pallet stacking in Zone F,safety_incident
6
- What's the status of order #63485?,order_status
7
  What's the current uptime percentage for Zone D?,system_status
8
  Check system health for the receiving dock,system_status
9
  "A spill was reported near Crane-05 in the receiving dock, needs cleanup",safety_incident
10
  What's the most efficient picking sequence for the receiving dock today?,picking_optimization
11
  Schedule maintenance for Sorter-06,equipment_maintenance
12
  Explain how an AS/RS works,general_faq
13
- When will order #89219 be delivered?,order_status
14
  The sorter in Zone A keeps jamming,equipment_maintenance
15
- Track order #54338 for me,order_status
16
  Report unsafe pallet stacking in the shipping dock,safety_incident
17
  Why is inventory accuracy important?,general_faq
18
  Crane Crane-05 reported a fault code,equipment_maintenance
19
  Would zone picking work better than batch picking for the cross-dock area?,picking_optimization
20
- Is order #77592 delayed?,order_status
21
- Has order #53283 shipped yet?,order_status
22
- Do we have enough SKU-5135 to fulfill 200 units?,inventory_check
23
  Send the next available AGV to picking station 22,agv_navigation
24
- What is the current stock level for SKU-8720?,inventory_check
25
  Check system health for Zone A,system_status
26
- Give me stock levels across all zones for SKU-3794,inventory_check
27
  Report vibration issue on Sorter-06,equipment_maintenance
28
  There was a near collision between AGV-12 and a pedestrian in Zone F,safety_incident
29
  Send AGV Sorter-06 to the mezzanine,agv_navigation
30
  What does WCS stand for?,general_faq
31
  Report vibration issue on Crane-09,equipment_maintenance
32
  Is the sorter in the shipping dock running normally?,system_status
33
- What's the status of order #89060?,order_status
34
- Show me the on-hand quantity of SKU-5201,inventory_check
35
  File an incident report for Zone F,safety_incident
36
  A forklift near-miss was reported in the mezzanine,safety_incident
37
  Explain the difference between discrete and batch picking,general_faq
38
- Show the fulfillment status of #47829,order_status
39
  "Belt Crane-03 stopped unexpectedly, please check",equipment_maintenance
40
  File an incident report for Zone C,safety_incident
41
  Is the WCS connection to AGV-12 stable?,system_status
42
- Why hasn't order #25483 left the dock yet?,order_status
43
  What is the current location of Conveyor-14?,agv_navigation
44
- What's the fastest picking route for order #35250?,picking_optimization
45
  What is the uptime for AGV-18 today?,system_status
46
  Send AGV Crane-09 to Zone D,agv_navigation
47
- When will order #74019 be delivered?,order_status
48
- Has order #58303 shipped yet?,order_status
49
- Give me stock levels across all zones for SKU-5710,inventory_check
50
  "Someone bypassed the safety gate near Crane-05, please log this",safety_incident
51
  Is the sorter in the receiving dock running normally?,system_status
52
  Is the WCS connection to AGV-18 stable?,system_status
53
  Sorter-02 motor temperature seems high,equipment_maintenance
54
- Is SKU-5530 in stock at the cross-dock area?,inventory_check
55
  Is the WCS connection to Crane-05 stable?,system_status
56
- What is the current stock level for SKU-7401?,inventory_check
57
- Is order #21158 delayed?,order_status
58
  Redirect AMR-33 around the blocked aisle in the mezzanine,agv_navigation
59
- What is the current stock level for SKU-5428?,inventory_check
60
- Do we have enough SKU-8451 to fulfill 200 units?,inventory_check
61
- What's the fastest picking route for order #18411?,picking_optimization
62
  Log a safety incident involving Conveyor-14,safety_incident
63
- How many units of SKU-1876 are in Zone F?,inventory_check
64
  Suggest a wave picking plan for Zone B,picking_optimization
65
- Track order #93554 for me,order_status
66
  Route Sorter-06 to picking station 18,agv_navigation
67
  How should we sequence orders to minimize walking distance in Zone D?,picking_optimization
68
  What is the uptime for Crane-05 today?,system_status
69
  Is Crane-05 operational?,system_status
70
  Is the WCS connection to Crane-03 stable?,system_status
71
- What is the current stock level for SKU-2802?,inventory_check
72
  Reassign Conveyor-21 to charging station,agv_navigation
73
  Why is AGV-07 stuck near Zone E?,agv_navigation
74
- Show the fulfillment status of #48732,order_status
75
- Check inventory count for SKU-2453 in the shipping dock,inventory_check
76
  How should we sequence orders to minimize walking distance in Zone A?,picking_optimization
77
  What is wave picking?,general_faq
78
  Schedule maintenance for AGV-12,equipment_maintenance
79
  How does zone picking work?,general_faq
80
  The sorter in the cross-dock area keeps jamming,equipment_maintenance
81
  Suggest a wave picking plan for the cross-dock area,picking_optimization
82
- Show me the on-hand quantity of SKU-3511,inventory_check
83
- How much inventory is left for SKU-8368?,inventory_check
84
- Has order #23679 shipped yet?,order_status
85
  What is dock-to-stock time?,general_faq
86
  Would zone picking work better than batch picking for the mezzanine?,picking_optimization
87
- Why hasn't order #32065 left the dock yet?,order_status
88
- Do we have enough SKU-2451 to fulfill 200 units?,inventory_check
89
  Has Sorter-02 reported any faults today?,system_status
90
- How many units of SKU-8103 are in Zone F?,inventory_check
91
- What is the current stock level for SKU-6671?,inventory_check
92
- Has order #42390 shipped yet?,order_status
93
  Schedule maintenance for Conveyor-21,equipment_maintenance
94
  Should we batch pick these orders together?,picking_optimization
95
- How much inventory is left for SKU-9364?,inventory_check
96
- Has order #91136 shipped yet?,order_status
97
  Check system health for the mezzanine,system_status
98
  What's the current uptime percentage for the mezzanine?,system_status
99
  Are all cranes online in Zone C?,system_status
100
- Track order #27557 for me,order_status
101
  "AMR-21 seems to be idle near Zone E, please reroute it",agv_navigation
102
  How do warehouses reduce energy use during peak hours?,general_faq
103
  There was a near collision between Sorter-02 and a pedestrian in the cross-dock area,safety_incident
104
  A forklift near-miss was reported in the receiving dock,safety_incident
105
  The conveyor belt in Zone E is making noise,equipment_maintenance
106
  Schedule maintenance for Sorter-02,equipment_maintenance
107
- How many units of SKU-9688 are in the shipping dock?,inventory_check
108
- Do we have enough SKU-3923 to fulfill 200 units?,inventory_check
109
  Report vibration issue on AGV-12,equipment_maintenance
110
  Reassign Crane-09 to charging station,agv_navigation
111
  What's the current uptime percentage for Zone A?,system_status
112
  What's the most efficient picking sequence for Zone A today?,picking_optimization
113
- Show me the on-hand quantity of SKU-7889,inventory_check
114
  What's the current uptime percentage for the shipping dock?,system_status
115
  How is a WMS different from a WCS?,general_faq
116
  Log a safety incident involving Sorter-02,safety_incident
117
- Give me stock levels across all zones for SKU-3949,inventory_check
118
- Is SKU-2427 in stock at Zone C?,inventory_check
119
  Please log a near-miss between a pedestrian and Conveyor-14 in the shipping dock,safety_incident
120
- Is order #56061 delayed?,order_status
121
  Has Conveyor-14 reported any faults today?,system_status
122
  "Belt Crane-09 stopped unexpectedly, please check",equipment_maintenance
123
- Show the fulfillment status of #15957,order_status
124
- Has order #93050 shipped yet?,order_status
125
- What's the fastest picking route for order #11120?,picking_optimization
126
  How do sortation systems decide where to route a parcel?,general_faq
127
- Show me the on-hand quantity of SKU-6360,inventory_check
128
  Is Sorter-06 operational?,system_status
129
- What's the fastest picking route for order #22509?,picking_optimization
130
  Can you dispatch AGV-07 to the shipping dock right away?,agv_navigation
131
- Is SKU-8354 in stock at Zone D?,inventory_check
132
- Show me the on-hand quantity of SKU-7894,inventory_check
133
  Is AGV-18 operational?,system_status
134
- What's the status of order #48496?,order_status
135
  What is the current location of AMR-33?,agv_navigation
136
  What is the uptime for Crane-03 today?,system_status
137
- Why hasn't order #79143 left the dock yet?,order_status
138
- Show the fulfillment status of #94756,order_status
139
  Are all cranes online in Zone A?,system_status
140
  Is the sorter in the mezzanine running normally?,system_status
141
  Log a safety incident involving Sorter-06,safety_incident
@@ -148,21 +148,21 @@ There was a near collision between AGV-18 and a pedestrian in Zone B,safety_inci
148
  What is the current location of AGV-07?,agv_navigation
149
  "A spill was reported near Conveyor-21 in the receiving dock, needs cleanup",safety_incident
150
  "AGV-07 seems to be idle near the receiving dock, please reroute it",agv_navigation
151
- Why hasn't order #33808 left the dock yet?,order_status
152
  Redirect Conveyor-14 around the blocked aisle in the receiving dock,agv_navigation
153
  Crane Sorter-02 reported a fault code,equipment_maintenance
154
  Pause AGV-18 until the aisle in Zone A is clear,agv_navigation
155
  Conveyor-14 motor temperature seems high,equipment_maintenance
156
  How should we sequence orders to minimize walking distance in the shipping dock?,picking_optimization
157
  "Sorter-02 seems to be idle near Zone C, please reroute it",agv_navigation
158
- Has order #39634 shipped yet?,order_status
159
  Reassign AMR-21 to charging station,agv_navigation
160
  "A spill was reported near AMR-21 in the shipping dock, needs cleanup",safety_incident
161
- Why hasn't order #91189 left the dock yet?,order_status
162
  What is the current location of AMR-21?,agv_navigation
163
  Schedule maintenance for AGV-18,equipment_maintenance
164
  Reassign AMR-33 to charging station,agv_navigation
165
- What's the status of order #91647?,order_status
166
  How should we sequence orders to minimize walking distance in Zone E?,picking_optimization
167
  What is the uptime for Conveyor-14 today?,system_status
168
  Are all cranes online in Zone F?,system_status
@@ -172,28 +172,28 @@ Can you dispatch Conveyor-21 to Zone F right away?,agv_navigation
172
  How can we reduce travel time for pickers in Zone C?,picking_optimization
173
  Is the sorter in Zone E running normally?,system_status
174
  Report unsafe pallet stacking in Zone E,safety_incident
175
- What is the current stock level for SKU-3351?,inventory_check
176
  The sorter in Zone D keeps jamming,equipment_maintenance
177
  "A worker slipped near AGV-18, please log it",safety_incident
178
  Check system health for Zone F,system_status
179
- What's the fastest picking route for order #90047?,picking_optimization
180
  Would zone picking work better than batch picking for Zone C?,picking_optimization
181
- How much inventory is left for SKU-3784?,inventory_check
182
- Track order #84987 for me,order_status
183
  Route Crane-05 to picking station 18,agv_navigation
184
  Has AGV-12 reported any faults today?,system_status
185
- Give me stock levels across all zones for SKU-7202,inventory_check
186
  Is AMR-21 operational?,system_status
187
  A forklift near-miss was reported in Zone D,safety_incident
188
  "Belt Conveyor-21 stopped unexpectedly, please check",equipment_maintenance
189
  "Belt Sorter-06 stopped unexpectedly, please check",equipment_maintenance
190
  Report vibration issue on Conveyor-14,equipment_maintenance
191
  Reassign Crane-05 to charging station,agv_navigation
192
- Give me stock levels across all zones for SKU-7317,inventory_check
193
  Has AGV-18 reported any faults today?,system_status
194
- Track order #50655 for me,order_status
195
- When will order #53538 be delivered?,order_status
196
- Check inventory count for SKU-6466 in the receiving dock,inventory_check
197
  What's the most efficient picking sequence for the shipping dock today?,picking_optimization
198
  Log a breakdown for Crane-09 in Zone F,equipment_maintenance
199
  Has Sorter-06 reported any faults today?,system_status
@@ -203,34 +203,34 @@ What's the most efficient picking sequence for Zone B today?,picking_optimizatio
203
  Route Sorter-06 to picking station 3,agv_navigation
204
  Is the sorter in Zone D running normally?,system_status
205
  What is the current location of Sorter-02?,agv_navigation
206
- Has order #69853 shipped yet?,order_status
207
  Please log a near-miss between a pedestrian and Crane-03 in Zone E,safety_incident
208
  Log a breakdown for Conveyor-21 in Zone C,equipment_maintenance
209
  How should we sequence orders to minimize walking distance in Zone C?,picking_optimization
210
  The conveyor belt in Zone B is making noise,equipment_maintenance
211
- What is the current stock level for SKU-9826?,inventory_check
212
- When will order #89131 be delivered?,order_status
213
  File an incident report for Zone E,safety_incident
214
- Show the fulfillment status of #85726,order_status
215
  Report unsafe pallet stacking in the receiving dock,safety_incident
216
  Crane Crane-09 reported a fault code,equipment_maintenance
217
  "A worker slipped near AMR-33, please log it",safety_incident
218
- When will order #38397 be delivered?,order_status
219
  Report vibration issue on Crane-03,equipment_maintenance
220
  Log a safety incident involving AMR-33,safety_incident
221
  Please log a near-miss between a pedestrian and AGV-12 in the shipping dock,safety_incident
222
  How can we reduce travel time for pickers in Zone A?,picking_optimization
223
- Why hasn't order #98736 left the dock yet?,order_status
224
  What's the most efficient picking sequence for Zone E today?,picking_optimization
225
- Why hasn't order #11185 left the dock yet?,order_status
226
- Is SKU-5595 in stock at Zone A?,inventory_check
227
- Is SKU-6953 in stock at Zone B?,inventory_check
228
  The conveyor belt in Zone A is making noise,equipment_maintenance
229
  Crane-09 motor temperature seems high,equipment_maintenance
230
  Suggest a wave picking plan for Zone D,picking_optimization
231
  Reassign Crane-03 to charging station,agv_navigation
232
  Send the next available AGV to picking station 12,agv_navigation
233
- Is order #43653 delayed?,order_status
234
  Can you dispatch AGV-12 to the receiving dock right away?,agv_navigation
235
  Is Conveyor-14 operational?,system_status
236
  Would zone picking work better than batch picking for the shipping dock?,picking_optimization
@@ -241,10 +241,10 @@ What's the most efficient picking sequence for Zone F today?,picking_optimizatio
241
  Crane AGV-18 reported a fault code,equipment_maintenance
242
  AMR-21 motor temperature seems high,equipment_maintenance
243
  Please log a near-miss between a pedestrian and Crane-09 in the mezzanine,safety_incident
244
- What's the fastest picking route for order #98965?,picking_optimization
245
  Reassign AGV-12 to charging station,agv_navigation
246
  "Conveyor-21 seems to be idle near Zone B, please reroute it",agv_navigation
247
- When will order #36922 be delivered?,order_status
248
  Is Sorter-02 operational?,system_status
249
  Pause Crane-05 until the aisle in the receiving dock is clear,agv_navigation
250
  Crane Conveyor-21 reported a fault code,equipment_maintenance
@@ -257,94 +257,94 @@ Log a safety incident involving Conveyor-21,safety_incident
257
  Please log a near-miss between a pedestrian and Crane-09 in Zone A,safety_incident
258
  What's the current uptime percentage for the cross-dock area?,system_status
259
  There was a near collision between Crane-05 and a pedestrian in Zone F,safety_incident
260
- Has order #87574 shipped yet?,order_status
261
  Log a breakdown for Sorter-02 in Zone B,equipment_maintenance
262
  Recommend a picking strategy for high-velocity SKUs,picking_optimization
263
- What's the fastest picking route for order #95679?,picking_optimization
264
  How should we sequence orders to minimize walking distance in Zone F?,picking_optimization
265
  What's the difference between AGV and AMR?,general_faq
266
  "A worker slipped near Crane-03, please log it",safety_incident
267
  "AGV-18 seems to be idle near Zone E, please reroute it",agv_navigation
268
- What's the fastest picking route for order #57683?,picking_optimization
269
  The conveyor belt in the mezzanine is making noise,equipment_maintenance
270
  "Belt AMR-21 stopped unexpectedly, please check",equipment_maintenance
271
  Redirect AMR-33 around the blocked aisle in Zone F,agv_navigation
272
  Would zone picking work better than batch picking for Zone A?,picking_optimization
273
  Why is Conveyor-14 stuck near the receiving dock?,agv_navigation
274
- Has order #18536 shipped yet?,order_status
275
  Log a breakdown for Crane-05 in Zone F,equipment_maintenance
276
  Why is AGV-07 stuck near Zone B?,agv_navigation
277
  There was a near collision between Conveyor-21 and a pedestrian in Zone D,safety_incident
278
- What's the fastest picking route for order #71673?,picking_optimization
279
  "Belt AMR-33 stopped unexpectedly, please check",equipment_maintenance
280
  Is the sorter in Zone C running normally?,system_status
281
- Is order #24576 delayed?,order_status
282
  Check system health for the shipping dock,system_status
283
  Crane Conveyor-14 reported a fault code,equipment_maintenance
284
  There was a near collision between AGV-12 and a pedestrian in Zone D,safety_incident
285
- Is SKU-3206 in stock at Zone E?,inventory_check
286
  Check system health for Zone D,system_status
287
- Has order #43891 shipped yet?,order_status
288
  Would zone picking work better than batch picking for Zone D?,picking_optimization
289
- When will order #71729 be delivered?,order_status
290
  Suggest a wave picking plan for Zone C,picking_optimization
291
  Can you dispatch AGV-07 to Zone F right away?,agv_navigation
292
  The conveyor belt in the cross-dock area is making noise,equipment_maintenance
293
- How many units of SKU-7671 are in the receiving dock?,inventory_check
294
- Show me the on-hand quantity of SKU-3702,inventory_check
295
- Check inventory count for SKU-6108 in Zone D,inventory_check
296
  Crane Crane-03 reported a fault code,equipment_maintenance
297
  Schedule maintenance for Crane-05,equipment_maintenance
298
  Report unsafe pallet stacking in Zone D,safety_incident
299
  "Someone bypassed the safety gate near Crane-09, please log this",safety_incident
300
  "AMR-21 seems to be idle near Zone B, please reroute it",agv_navigation
301
- Why hasn't order #86242 left the dock yet?,order_status
302
- Is SKU-8367 in stock at the receiving dock?,inventory_check
303
  Would zone picking work better than batch picking for the receiving dock?,picking_optimization
304
  What is a mini-load system?,general_faq
305
  "A spill was reported near Conveyor-14 in the receiving dock, needs cleanup",safety_incident
306
  Report vibration issue on Sorter-02,equipment_maintenance
307
- Do we have enough SKU-8061 to fulfill 200 units?,inventory_check
308
  Why do warehouses use cycle counting instead of annual counts?,general_faq
309
  Route Crane-05 to picking station 12,agv_navigation
310
- What's the fastest picking route for order #75527?,picking_optimization
311
  Suggest a wave picking plan for the mezzanine,picking_optimization
312
  Is the WCS connection to AGV-07 stable?,system_status
313
- Do we have enough SKU-5257 to fulfill 200 units?,inventory_check
314
  How should we sequence orders to minimize walking distance in the cross-dock area?,picking_optimization
315
  Is the sorter in the cross-dock area running normally?,system_status
316
- Track order #48287 for me,order_status
317
  Pause Sorter-06 until the aisle in Zone E is clear,agv_navigation
318
  Check system health for Zone B,system_status
319
  Pause Crane-03 until the aisle in the cross-dock area is clear,agv_navigation
320
  The sorter in Zone F keeps jamming,equipment_maintenance
321
- What's the status of order #28439?,order_status
322
  Optimize the pick path for Zone F,picking_optimization
323
  Send AGV AMR-21 to Zone D,agv_navigation
324
- Show the fulfillment status of #43413,order_status
325
- Check inventory count for SKU-9277 in Zone C,inventory_check
326
- What is the current stock level for SKU-3569?,inventory_check
327
  What's the most efficient picking sequence for the cross-dock area today?,picking_optimization
328
  "AMR-33 seems to be idle near Zone E, please reroute it",agv_navigation
329
  Has AMR-33 reported any faults today?,system_status
330
- Give me stock levels across all zones for SKU-8037,inventory_check
331
  What is the uptime for AMR-33 today?,system_status
332
  Route Crane-03 to picking station 18,agv_navigation
333
  How can we reduce travel time for pickers in Zone F?,picking_optimization
334
- What's the fastest picking route for order #96033?,picking_optimization
335
  Report vibration issue on AMR-33,equipment_maintenance
336
  Check system health for Zone E,system_status
337
  "Belt AGV-07 stopped unexpectedly, please check",equipment_maintenance
338
- Is order #42584 delayed?,order_status
339
  The sorter in the shipping dock keeps jamming,equipment_maintenance
340
  Report vibration issue on Conveyor-21,equipment_maintenance
341
- Give me stock levels across all zones for SKU-3437,inventory_check
342
  "A spill was reported near AMR-21 in the cross-dock area, needs cleanup",safety_incident
343
- Show the fulfillment status of #57239,order_status
344
  Please log a near-miss between a pedestrian and Conveyor-21 in the receiving dock,safety_incident
345
- Is SKU-9655 in stock at the cross-dock area?,inventory_check
346
  "Belt Conveyor-14 stopped unexpectedly, please check",equipment_maintenance
347
- What is the current stock level for SKU-5360?,inventory_check
348
  Are all cranes online in Zone B?,system_status
349
  "A worker slipped near AMR-21, please log it",safety_incident
350
  What is the current location of AGV-18?,agv_navigation
@@ -364,30 +364,30 @@ There was a near collision between AMR-33 and a pedestrian in Zone C,safety_inci
364
  Would zone picking work better than batch picking for Zone E?,picking_optimization
365
  Send the next available AGV to picking station 3,agv_navigation
366
  Crane-03 motor temperature seems high,equipment_maintenance
367
- Is SKU-6320 in stock at the receiving dock?,inventory_check
368
  Why is AGV-12 stuck near the shipping dock?,agv_navigation
369
  Send the next available AGV to picking station 5,agv_navigation
370
  Please log a near-miss between a pedestrian and AGV-18 in Zone C,safety_incident
371
  What's the most efficient picking sequence for Zone C today?,picking_optimization
372
- Track order #96525 for me,order_status
373
- Is SKU-3798 in stock at Zone A?,inventory_check
374
- Do we have enough SKU-4449 to fulfill 200 units?,inventory_check
375
  How does regenerative braking work on an AS/RS crane?,general_faq
376
- Give me stock levels across all zones for SKU-1650,inventory_check
377
- When will order #90343 be delivered?,order_status
378
  Why is AGV-12 stuck near the receiving dock?,agv_navigation
379
- Give me stock levels across all zones for SKU-8956,inventory_check
380
  Optimize the pick path for Zone D,picking_optimization
381
  Give me the current status of the WMS integration,system_status
382
- When will order #89814 be delivered?,order_status
383
  A forklift near-miss was reported in Zone F,safety_incident
384
- What is the current stock level for SKU-6339?,inventory_check
385
  "Someone bypassed the safety gate near AMR-21, please log this",safety_incident
386
  How can we reduce travel time for pickers in Zone D?,picking_optimization
387
  How can we reduce travel time for pickers in the shipping dock?,picking_optimization
388
- Give me stock levels across all zones for SKU-3877,inventory_check
389
  "A spill was reported near AGV-12 in Zone F, needs cleanup",safety_incident
390
- Track order #95296 for me,order_status
391
  Are all cranes online in Zone E?,system_status
392
  Would zone picking work better than batch picking for Zone B?,picking_optimization
393
  The sorter in the mezzanine keeps jamming,equipment_maintenance
@@ -397,24 +397,24 @@ What is a WMS?,general_faq
397
  A forklift near-miss was reported in Zone A,safety_incident
398
  What is predictive maintenance?,general_faq
399
  There was a near collision between Conveyor-14 and a pedestrian in Zone B,safety_incident
400
- What's the fastest picking route for order #27906?,picking_optimization
401
- Do we have enough SKU-5448 to fulfill 200 units?,inventory_check
402
  Are all cranes online in the mezzanine?,system_status
403
- Do we have enough SKU-4957 to fulfill 200 units?,inventory_check
404
  Crane AMR-33 reported a fault code,equipment_maintenance
405
  Pause Conveyor-14 until the aisle in Zone E is clear,agv_navigation
406
  What's the difference between a stacker crane and a shuttle?,general_faq
407
  Redirect Sorter-06 around the blocked aisle in Zone C,agv_navigation
408
  Conveyor-21 motor temperature seems high,equipment_maintenance
409
- Do we have enough SKU-2245 to fulfill 200 units?,inventory_check
410
- Check inventory count for SKU-3735 in Zone E,inventory_check
411
  Report unsafe pallet stacking in Zone C,safety_incident
412
  Redirect Crane-09 around the blocked aisle in the mezzanine,agv_navigation
413
  How should we sequence orders to minimize walking distance in the mezzanine?,picking_optimization
414
- Do we have enough SKU-5494 to fulfill 200 units?,inventory_check
415
  Please log a near-miss between a pedestrian and Crane-05 in the mezzanine,safety_incident
416
  The conveyor belt in Zone F is making noise,equipment_maintenance
417
- What's the fastest picking route for order #86847?,picking_optimization
418
  Can you dispatch Conveyor-14 to the receiving dock right away?,agv_navigation
419
  What's the current uptime percentage for the receiving dock?,system_status
420
  Optimize the pick path for Zone B,picking_optimization
@@ -426,18 +426,18 @@ Log a breakdown for Conveyor-14 in the shipping dock,equipment_maintenance
426
  The conveyor belt in the shipping dock is making noise,equipment_maintenance
427
  Log a breakdown for Crane-05 in the receiving dock,equipment_maintenance
428
  There was a near collision between Sorter-06 and a pedestrian in Zone E,safety_incident
429
- What's the status of order #45231?,order_status
430
  What's the current uptime percentage for Zone B?,system_status
431
- Track order #15877 for me,order_status
432
  "A spill was reported near AGV-07 in the receiving dock, needs cleanup",safety_incident
433
  Pause AGV-07 until the aisle in the cross-dock area is clear,agv_navigation
434
  AGV-07 motor temperature seems high,equipment_maintenance
435
  What KPIs matter most in warehouse automation?,general_faq
436
- What is the current stock level for SKU-1934?,inventory_check
437
  Redirect Crane-09 around the blocked aisle in Zone E,agv_navigation
438
- Is order #66488 delayed?,order_status
439
- Has order #71734 shipped yet?,order_status
440
- What's the fastest picking route for order #78872?,picking_optimization
441
  There was a near collision between AGV-12 and a pedestrian in Zone C,safety_incident
442
  What is a pick rate and how is it measured?,general_faq
443
- Why hasn't order #89697 left the dock yet?,order_status
 
1
  text,intent
2
+ What's the fastest picking route for order #85330?,picking_optimization
3
  Pause AGV-12 until the aisle in Zone E is clear,agv_navigation
4
+ Is order #82421 delayed?,order_status
5
  Report unsafe pallet stacking in Zone F,safety_incident
6
+ What's the status of order #47013?,order_status
7
  What's the current uptime percentage for Zone D?,system_status
8
  Check system health for the receiving dock,system_status
9
  "A spill was reported near Crane-05 in the receiving dock, needs cleanup",safety_incident
10
  What's the most efficient picking sequence for the receiving dock today?,picking_optimization
11
  Schedule maintenance for Sorter-06,equipment_maintenance
12
  Explain how an AS/RS works,general_faq
13
+ When will order #62450 be delivered?,order_status
14
  The sorter in Zone A keeps jamming,equipment_maintenance
15
+ Track order #33029 for me,order_status
16
  Report unsafe pallet stacking in the shipping dock,safety_incident
17
  Why is inventory accuracy important?,general_faq
18
  Crane Crane-05 reported a fault code,equipment_maintenance
19
  Would zone picking work better than batch picking for the cross-dock area?,picking_optimization
20
+ Is order #15110 delayed?,order_status
21
+ Has order #43202 shipped yet?,order_status
22
+ Do we have enough SKU-2103 to fulfill 200 units?,inventory_check
23
  Send the next available AGV to picking station 22,agv_navigation
24
+ What is the current stock level for SKU-8359?,inventory_check
25
  Check system health for Zone A,system_status
26
+ Give me stock levels across all zones for SKU-9769,inventory_check
27
  Report vibration issue on Sorter-06,equipment_maintenance
28
  There was a near collision between AGV-12 and a pedestrian in Zone F,safety_incident
29
  Send AGV Sorter-06 to the mezzanine,agv_navigation
30
  What does WCS stand for?,general_faq
31
  Report vibration issue on Crane-09,equipment_maintenance
32
  Is the sorter in the shipping dock running normally?,system_status
33
+ What's the status of order #32613?,order_status
34
+ Show me the on-hand quantity of SKU-1747,inventory_check
35
  File an incident report for Zone F,safety_incident
36
  A forklift near-miss was reported in the mezzanine,safety_incident
37
  Explain the difference between discrete and batch picking,general_faq
38
+ Show the fulfillment status of #41155,order_status
39
  "Belt Crane-03 stopped unexpectedly, please check",equipment_maintenance
40
  File an incident report for Zone C,safety_incident
41
  Is the WCS connection to AGV-12 stable?,system_status
42
+ Why hasn't order #69979 left the dock yet?,order_status
43
  What is the current location of Conveyor-14?,agv_navigation
44
+ What's the fastest picking route for order #25183?,picking_optimization
45
  What is the uptime for AGV-18 today?,system_status
46
  Send AGV Crane-09 to Zone D,agv_navigation
47
+ When will order #87283 be delivered?,order_status
48
+ Has order #57411 shipped yet?,order_status
49
+ Give me stock levels across all zones for SKU-5185,inventory_check
50
  "Someone bypassed the safety gate near Crane-05, please log this",safety_incident
51
  Is the sorter in the receiving dock running normally?,system_status
52
  Is the WCS connection to AGV-18 stable?,system_status
53
  Sorter-02 motor temperature seems high,equipment_maintenance
54
+ Is SKU-1506 in stock at the cross-dock area?,inventory_check
55
  Is the WCS connection to Crane-05 stable?,system_status
56
+ What is the current stock level for SKU-9304?,inventory_check
57
+ Is order #61347 delayed?,order_status
58
  Redirect AMR-33 around the blocked aisle in the mezzanine,agv_navigation
59
+ What is the current stock level for SKU-5753?,inventory_check
60
+ Do we have enough SKU-1627 to fulfill 200 units?,inventory_check
61
+ What's the fastest picking route for order #75573?,picking_optimization
62
  Log a safety incident involving Conveyor-14,safety_incident
63
+ How many units of SKU-9661 are in Zone F?,inventory_check
64
  Suggest a wave picking plan for Zone B,picking_optimization
65
+ Track order #66375 for me,order_status
66
  Route Sorter-06 to picking station 18,agv_navigation
67
  How should we sequence orders to minimize walking distance in Zone D?,picking_optimization
68
  What is the uptime for Crane-05 today?,system_status
69
  Is Crane-05 operational?,system_status
70
  Is the WCS connection to Crane-03 stable?,system_status
71
+ What is the current stock level for SKU-5292?,inventory_check
72
  Reassign Conveyor-21 to charging station,agv_navigation
73
  Why is AGV-07 stuck near Zone E?,agv_navigation
74
+ Show the fulfillment status of #50488,order_status
75
+ Check inventory count for SKU-4502 in the shipping dock,inventory_check
76
  How should we sequence orders to minimize walking distance in Zone A?,picking_optimization
77
  What is wave picking?,general_faq
78
  Schedule maintenance for AGV-12,equipment_maintenance
79
  How does zone picking work?,general_faq
80
  The sorter in the cross-dock area keeps jamming,equipment_maintenance
81
  Suggest a wave picking plan for the cross-dock area,picking_optimization
82
+ Show me the on-hand quantity of SKU-3554,inventory_check
83
+ How much inventory is left for SKU-4486?,inventory_check
84
+ Has order #21753 shipped yet?,order_status
85
  What is dock-to-stock time?,general_faq
86
  Would zone picking work better than batch picking for the mezzanine?,picking_optimization
87
+ Why hasn't order #32297 left the dock yet?,order_status
88
+ Do we have enough SKU-6904 to fulfill 200 units?,inventory_check
89
  Has Sorter-02 reported any faults today?,system_status
90
+ How many units of SKU-5094 are in Zone F?,inventory_check
91
+ What is the current stock level for SKU-1726?,inventory_check
92
+ Has order #92929 shipped yet?,order_status
93
  Schedule maintenance for Conveyor-21,equipment_maintenance
94
  Should we batch pick these orders together?,picking_optimization
95
+ How much inventory is left for SKU-9428?,inventory_check
96
+ Has order #65652 shipped yet?,order_status
97
  Check system health for the mezzanine,system_status
98
  What's the current uptime percentage for the mezzanine?,system_status
99
  Are all cranes online in Zone C?,system_status
100
+ Track order #70218 for me,order_status
101
  "AMR-21 seems to be idle near Zone E, please reroute it",agv_navigation
102
  How do warehouses reduce energy use during peak hours?,general_faq
103
  There was a near collision between Sorter-02 and a pedestrian in the cross-dock area,safety_incident
104
  A forklift near-miss was reported in the receiving dock,safety_incident
105
  The conveyor belt in Zone E is making noise,equipment_maintenance
106
  Schedule maintenance for Sorter-02,equipment_maintenance
107
+ How many units of SKU-6575 are in the shipping dock?,inventory_check
108
+ Do we have enough SKU-5018 to fulfill 200 units?,inventory_check
109
  Report vibration issue on AGV-12,equipment_maintenance
110
  Reassign Crane-09 to charging station,agv_navigation
111
  What's the current uptime percentage for Zone A?,system_status
112
  What's the most efficient picking sequence for Zone A today?,picking_optimization
113
+ Show me the on-hand quantity of SKU-9298,inventory_check
114
  What's the current uptime percentage for the shipping dock?,system_status
115
  How is a WMS different from a WCS?,general_faq
116
  Log a safety incident involving Sorter-02,safety_incident
117
+ Give me stock levels across all zones for SKU-1808,inventory_check
118
+ Is SKU-9799 in stock at Zone C?,inventory_check
119
  Please log a near-miss between a pedestrian and Conveyor-14 in the shipping dock,safety_incident
120
+ Is order #20803 delayed?,order_status
121
  Has Conveyor-14 reported any faults today?,system_status
122
  "Belt Crane-09 stopped unexpectedly, please check",equipment_maintenance
123
+ Show the fulfillment status of #65677,order_status
124
+ Has order #79386 shipped yet?,order_status
125
+ What's the fastest picking route for order #91540?,picking_optimization
126
  How do sortation systems decide where to route a parcel?,general_faq
127
+ Show me the on-hand quantity of SKU-4036,inventory_check
128
  Is Sorter-06 operational?,system_status
129
+ What's the fastest picking route for order #65982?,picking_optimization
130
  Can you dispatch AGV-07 to the shipping dock right away?,agv_navigation
131
+ Is SKU-8044 in stock at Zone D?,inventory_check
132
+ Show me the on-hand quantity of SKU-8274,inventory_check
133
  Is AGV-18 operational?,system_status
134
+ What's the status of order #12781?,order_status
135
  What is the current location of AMR-33?,agv_navigation
136
  What is the uptime for Crane-03 today?,system_status
137
+ Why hasn't order #62037 left the dock yet?,order_status
138
+ Show the fulfillment status of #22436,order_status
139
  Are all cranes online in Zone A?,system_status
140
  Is the sorter in the mezzanine running normally?,system_status
141
  Log a safety incident involving Sorter-06,safety_incident
 
148
  What is the current location of AGV-07?,agv_navigation
149
  "A spill was reported near Conveyor-21 in the receiving dock, needs cleanup",safety_incident
150
  "AGV-07 seems to be idle near the receiving dock, please reroute it",agv_navigation
151
+ Why hasn't order #63053 left the dock yet?,order_status
152
  Redirect Conveyor-14 around the blocked aisle in the receiving dock,agv_navigation
153
  Crane Sorter-02 reported a fault code,equipment_maintenance
154
  Pause AGV-18 until the aisle in Zone A is clear,agv_navigation
155
  Conveyor-14 motor temperature seems high,equipment_maintenance
156
  How should we sequence orders to minimize walking distance in the shipping dock?,picking_optimization
157
  "Sorter-02 seems to be idle near Zone C, please reroute it",agv_navigation
158
+ Has order #91932 shipped yet?,order_status
159
  Reassign AMR-21 to charging station,agv_navigation
160
  "A spill was reported near AMR-21 in the shipping dock, needs cleanup",safety_incident
161
+ Why hasn't order #11052 left the dock yet?,order_status
162
  What is the current location of AMR-21?,agv_navigation
163
  Schedule maintenance for AGV-18,equipment_maintenance
164
  Reassign AMR-33 to charging station,agv_navigation
165
+ What's the status of order #47552?,order_status
166
  How should we sequence orders to minimize walking distance in Zone E?,picking_optimization
167
  What is the uptime for Conveyor-14 today?,system_status
168
  Are all cranes online in Zone F?,system_status
 
172
  How can we reduce travel time for pickers in Zone C?,picking_optimization
173
  Is the sorter in Zone E running normally?,system_status
174
  Report unsafe pallet stacking in Zone E,safety_incident
175
+ What is the current stock level for SKU-8069?,inventory_check
176
  The sorter in Zone D keeps jamming,equipment_maintenance
177
  "A worker slipped near AGV-18, please log it",safety_incident
178
  Check system health for Zone F,system_status
179
+ What's the fastest picking route for order #91268?,picking_optimization
180
  Would zone picking work better than batch picking for Zone C?,picking_optimization
181
+ How much inventory is left for SKU-7962?,inventory_check
182
+ Track order #56354 for me,order_status
183
  Route Crane-05 to picking station 18,agv_navigation
184
  Has AGV-12 reported any faults today?,system_status
185
+ Give me stock levels across all zones for SKU-9600,inventory_check
186
  Is AMR-21 operational?,system_status
187
  A forklift near-miss was reported in Zone D,safety_incident
188
  "Belt Conveyor-21 stopped unexpectedly, please check",equipment_maintenance
189
  "Belt Sorter-06 stopped unexpectedly, please check",equipment_maintenance
190
  Report vibration issue on Conveyor-14,equipment_maintenance
191
  Reassign Crane-05 to charging station,agv_navigation
192
+ Give me stock levels across all zones for SKU-6051,inventory_check
193
  Has AGV-18 reported any faults today?,system_status
194
+ Track order #29623 for me,order_status
195
+ When will order #71699 be delivered?,order_status
196
+ Check inventory count for SKU-5885 in the receiving dock,inventory_check
197
  What's the most efficient picking sequence for the shipping dock today?,picking_optimization
198
  Log a breakdown for Crane-09 in Zone F,equipment_maintenance
199
  Has Sorter-06 reported any faults today?,system_status
 
203
  Route Sorter-06 to picking station 3,agv_navigation
204
  Is the sorter in Zone D running normally?,system_status
205
  What is the current location of Sorter-02?,agv_navigation
206
+ Has order #18807 shipped yet?,order_status
207
  Please log a near-miss between a pedestrian and Crane-03 in Zone E,safety_incident
208
  Log a breakdown for Conveyor-21 in Zone C,equipment_maintenance
209
  How should we sequence orders to minimize walking distance in Zone C?,picking_optimization
210
  The conveyor belt in Zone B is making noise,equipment_maintenance
211
+ What is the current stock level for SKU-5582?,inventory_check
212
+ When will order #26928 be delivered?,order_status
213
  File an incident report for Zone E,safety_incident
214
+ Show the fulfillment status of #41446,order_status
215
  Report unsafe pallet stacking in the receiving dock,safety_incident
216
  Crane Crane-09 reported a fault code,equipment_maintenance
217
  "A worker slipped near AMR-33, please log it",safety_incident
218
+ When will order #78867 be delivered?,order_status
219
  Report vibration issue on Crane-03,equipment_maintenance
220
  Log a safety incident involving AMR-33,safety_incident
221
  Please log a near-miss between a pedestrian and AGV-12 in the shipping dock,safety_incident
222
  How can we reduce travel time for pickers in Zone A?,picking_optimization
223
+ Why hasn't order #88111 left the dock yet?,order_status
224
  What's the most efficient picking sequence for Zone E today?,picking_optimization
225
+ Why hasn't order #13010 left the dock yet?,order_status
226
+ Is SKU-7869 in stock at Zone A?,inventory_check
227
+ Is SKU-5472 in stock at Zone B?,inventory_check
228
  The conveyor belt in Zone A is making noise,equipment_maintenance
229
  Crane-09 motor temperature seems high,equipment_maintenance
230
  Suggest a wave picking plan for Zone D,picking_optimization
231
  Reassign Crane-03 to charging station,agv_navigation
232
  Send the next available AGV to picking station 12,agv_navigation
233
+ Is order #15312 delayed?,order_status
234
  Can you dispatch AGV-12 to the receiving dock right away?,agv_navigation
235
  Is Conveyor-14 operational?,system_status
236
  Would zone picking work better than batch picking for the shipping dock?,picking_optimization
 
241
  Crane AGV-18 reported a fault code,equipment_maintenance
242
  AMR-21 motor temperature seems high,equipment_maintenance
243
  Please log a near-miss between a pedestrian and Crane-09 in the mezzanine,safety_incident
244
+ What's the fastest picking route for order #59267?,picking_optimization
245
  Reassign AGV-12 to charging station,agv_navigation
246
  "Conveyor-21 seems to be idle near Zone B, please reroute it",agv_navigation
247
+ When will order #30267 be delivered?,order_status
248
  Is Sorter-02 operational?,system_status
249
  Pause Crane-05 until the aisle in the receiving dock is clear,agv_navigation
250
  Crane Conveyor-21 reported a fault code,equipment_maintenance
 
257
  Please log a near-miss between a pedestrian and Crane-09 in Zone A,safety_incident
258
  What's the current uptime percentage for the cross-dock area?,system_status
259
  There was a near collision between Crane-05 and a pedestrian in Zone F,safety_incident
260
+ Has order #89670 shipped yet?,order_status
261
  Log a breakdown for Sorter-02 in Zone B,equipment_maintenance
262
  Recommend a picking strategy for high-velocity SKUs,picking_optimization
263
+ What's the fastest picking route for order #69155?,picking_optimization
264
  How should we sequence orders to minimize walking distance in Zone F?,picking_optimization
265
  What's the difference between AGV and AMR?,general_faq
266
  "A worker slipped near Crane-03, please log it",safety_incident
267
  "AGV-18 seems to be idle near Zone E, please reroute it",agv_navigation
268
+ What's the fastest picking route for order #10844?,picking_optimization
269
  The conveyor belt in the mezzanine is making noise,equipment_maintenance
270
  "Belt AMR-21 stopped unexpectedly, please check",equipment_maintenance
271
  Redirect AMR-33 around the blocked aisle in Zone F,agv_navigation
272
  Would zone picking work better than batch picking for Zone A?,picking_optimization
273
  Why is Conveyor-14 stuck near the receiving dock?,agv_navigation
274
+ Has order #57746 shipped yet?,order_status
275
  Log a breakdown for Crane-05 in Zone F,equipment_maintenance
276
  Why is AGV-07 stuck near Zone B?,agv_navigation
277
  There was a near collision between Conveyor-21 and a pedestrian in Zone D,safety_incident
278
+ What's the fastest picking route for order #69032?,picking_optimization
279
  "Belt AMR-33 stopped unexpectedly, please check",equipment_maintenance
280
  Is the sorter in Zone C running normally?,system_status
281
+ Is order #42243 delayed?,order_status
282
  Check system health for the shipping dock,system_status
283
  Crane Conveyor-14 reported a fault code,equipment_maintenance
284
  There was a near collision between AGV-12 and a pedestrian in Zone D,safety_incident
285
+ Is SKU-4734 in stock at Zone E?,inventory_check
286
  Check system health for Zone D,system_status
287
+ Has order #76270 shipped yet?,order_status
288
  Would zone picking work better than batch picking for Zone D?,picking_optimization
289
+ When will order #32758 be delivered?,order_status
290
  Suggest a wave picking plan for Zone C,picking_optimization
291
  Can you dispatch AGV-07 to Zone F right away?,agv_navigation
292
  The conveyor belt in the cross-dock area is making noise,equipment_maintenance
293
+ How many units of SKU-3646 are in the receiving dock?,inventory_check
294
+ Show me the on-hand quantity of SKU-1123,inventory_check
295
+ Check inventory count for SKU-9034 in Zone D,inventory_check
296
  Crane Crane-03 reported a fault code,equipment_maintenance
297
  Schedule maintenance for Crane-05,equipment_maintenance
298
  Report unsafe pallet stacking in Zone D,safety_incident
299
  "Someone bypassed the safety gate near Crane-09, please log this",safety_incident
300
  "AMR-21 seems to be idle near Zone B, please reroute it",agv_navigation
301
+ Why hasn't order #86364 left the dock yet?,order_status
302
+ Is SKU-7788 in stock at the receiving dock?,inventory_check
303
  Would zone picking work better than batch picking for the receiving dock?,picking_optimization
304
  What is a mini-load system?,general_faq
305
  "A spill was reported near Conveyor-14 in the receiving dock, needs cleanup",safety_incident
306
  Report vibration issue on Sorter-02,equipment_maintenance
307
+ Do we have enough SKU-1328 to fulfill 200 units?,inventory_check
308
  Why do warehouses use cycle counting instead of annual counts?,general_faq
309
  Route Crane-05 to picking station 12,agv_navigation
310
+ What's the fastest picking route for order #27681?,picking_optimization
311
  Suggest a wave picking plan for the mezzanine,picking_optimization
312
  Is the WCS connection to AGV-07 stable?,system_status
313
+ Do we have enough SKU-8264 to fulfill 200 units?,inventory_check
314
  How should we sequence orders to minimize walking distance in the cross-dock area?,picking_optimization
315
  Is the sorter in the cross-dock area running normally?,system_status
316
+ Track order #47175 for me,order_status
317
  Pause Sorter-06 until the aisle in Zone E is clear,agv_navigation
318
  Check system health for Zone B,system_status
319
  Pause Crane-03 until the aisle in the cross-dock area is clear,agv_navigation
320
  The sorter in Zone F keeps jamming,equipment_maintenance
321
+ What's the status of order #45116?,order_status
322
  Optimize the pick path for Zone F,picking_optimization
323
  Send AGV AMR-21 to Zone D,agv_navigation
324
+ Show the fulfillment status of #10654,order_status
325
+ Check inventory count for SKU-5294 in Zone C,inventory_check
326
+ What is the current stock level for SKU-9342?,inventory_check
327
  What's the most efficient picking sequence for the cross-dock area today?,picking_optimization
328
  "AMR-33 seems to be idle near Zone E, please reroute it",agv_navigation
329
  Has AMR-33 reported any faults today?,system_status
330
+ Give me stock levels across all zones for SKU-8783,inventory_check
331
  What is the uptime for AMR-33 today?,system_status
332
  Route Crane-03 to picking station 18,agv_navigation
333
  How can we reduce travel time for pickers in Zone F?,picking_optimization
334
+ What's the fastest picking route for order #65609?,picking_optimization
335
  Report vibration issue on AMR-33,equipment_maintenance
336
  Check system health for Zone E,system_status
337
  "Belt AGV-07 stopped unexpectedly, please check",equipment_maintenance
338
+ Is order #76348 delayed?,order_status
339
  The sorter in the shipping dock keeps jamming,equipment_maintenance
340
  Report vibration issue on Conveyor-21,equipment_maintenance
341
+ Give me stock levels across all zones for SKU-9446,inventory_check
342
  "A spill was reported near AMR-21 in the cross-dock area, needs cleanup",safety_incident
343
+ Show the fulfillment status of #76552,order_status
344
  Please log a near-miss between a pedestrian and Conveyor-21 in the receiving dock,safety_incident
345
+ Is SKU-6228 in stock at the cross-dock area?,inventory_check
346
  "Belt Conveyor-14 stopped unexpectedly, please check",equipment_maintenance
347
+ What is the current stock level for SKU-1173?,inventory_check
348
  Are all cranes online in Zone B?,system_status
349
  "A worker slipped near AMR-21, please log it",safety_incident
350
  What is the current location of AGV-18?,agv_navigation
 
364
  Would zone picking work better than batch picking for Zone E?,picking_optimization
365
  Send the next available AGV to picking station 3,agv_navigation
366
  Crane-03 motor temperature seems high,equipment_maintenance
367
+ Is SKU-6758 in stock at the receiving dock?,inventory_check
368
  Why is AGV-12 stuck near the shipping dock?,agv_navigation
369
  Send the next available AGV to picking station 5,agv_navigation
370
  Please log a near-miss between a pedestrian and AGV-18 in Zone C,safety_incident
371
  What's the most efficient picking sequence for Zone C today?,picking_optimization
372
+ Track order #51679 for me,order_status
373
+ Is SKU-1282 in stock at Zone A?,inventory_check
374
+ Do we have enough SKU-8718 to fulfill 200 units?,inventory_check
375
  How does regenerative braking work on an AS/RS crane?,general_faq
376
+ Give me stock levels across all zones for SKU-9735,inventory_check
377
+ When will order #80380 be delivered?,order_status
378
  Why is AGV-12 stuck near the receiving dock?,agv_navigation
379
+ Give me stock levels across all zones for SKU-5603,inventory_check
380
  Optimize the pick path for Zone D,picking_optimization
381
  Give me the current status of the WMS integration,system_status
382
+ When will order #47645 be delivered?,order_status
383
  A forklift near-miss was reported in Zone F,safety_incident
384
+ What is the current stock level for SKU-1651?,inventory_check
385
  "Someone bypassed the safety gate near AMR-21, please log this",safety_incident
386
  How can we reduce travel time for pickers in Zone D?,picking_optimization
387
  How can we reduce travel time for pickers in the shipping dock?,picking_optimization
388
+ Give me stock levels across all zones for SKU-9634,inventory_check
389
  "A spill was reported near AGV-12 in Zone F, needs cleanup",safety_incident
390
+ Track order #91823 for me,order_status
391
  Are all cranes online in Zone E?,system_status
392
  Would zone picking work better than batch picking for Zone B?,picking_optimization
393
  The sorter in the mezzanine keeps jamming,equipment_maintenance
 
397
  A forklift near-miss was reported in Zone A,safety_incident
398
  What is predictive maintenance?,general_faq
399
  There was a near collision between Conveyor-14 and a pedestrian in Zone B,safety_incident
400
+ What's the fastest picking route for order #13867?,picking_optimization
401
+ Do we have enough SKU-8902 to fulfill 200 units?,inventory_check
402
  Are all cranes online in the mezzanine?,system_status
403
+ Do we have enough SKU-7057 to fulfill 200 units?,inventory_check
404
  Crane AMR-33 reported a fault code,equipment_maintenance
405
  Pause Conveyor-14 until the aisle in Zone E is clear,agv_navigation
406
  What's the difference between a stacker crane and a shuttle?,general_faq
407
  Redirect Sorter-06 around the blocked aisle in Zone C,agv_navigation
408
  Conveyor-21 motor temperature seems high,equipment_maintenance
409
+ Do we have enough SKU-5143 to fulfill 200 units?,inventory_check
410
+ Check inventory count for SKU-8395 in Zone E,inventory_check
411
  Report unsafe pallet stacking in Zone C,safety_incident
412
  Redirect Crane-09 around the blocked aisle in the mezzanine,agv_navigation
413
  How should we sequence orders to minimize walking distance in the mezzanine?,picking_optimization
414
+ Do we have enough SKU-1218 to fulfill 200 units?,inventory_check
415
  Please log a near-miss between a pedestrian and Crane-05 in the mezzanine,safety_incident
416
  The conveyor belt in Zone F is making noise,equipment_maintenance
417
+ What's the fastest picking route for order #30359?,picking_optimization
418
  Can you dispatch Conveyor-14 to the receiving dock right away?,agv_navigation
419
  What's the current uptime percentage for the receiving dock?,system_status
420
  Optimize the pick path for Zone B,picking_optimization
 
426
  The conveyor belt in the shipping dock is making noise,equipment_maintenance
427
  Log a breakdown for Crane-05 in the receiving dock,equipment_maintenance
428
  There was a near collision between Sorter-06 and a pedestrian in Zone E,safety_incident
429
+ What's the status of order #26919?,order_status
430
  What's the current uptime percentage for Zone B?,system_status
431
+ Track order #24084 for me,order_status
432
  "A spill was reported near AGV-07 in the receiving dock, needs cleanup",safety_incident
433
  Pause AGV-07 until the aisle in the cross-dock area is clear,agv_navigation
434
  AGV-07 motor temperature seems high,equipment_maintenance
435
  What KPIs matter most in warehouse automation?,general_faq
436
+ What is the current stock level for SKU-4486?,inventory_check
437
  Redirect Crane-09 around the blocked aisle in Zone E,agv_navigation
438
+ Is order #97953 delayed?,order_status
439
+ Has order #64749 shipped yet?,order_status
440
+ What's the fastest picking route for order #21365?,picking_optimization
441
  There was a near collision between AGV-12 and a pedestrian in Zone C,safety_incident
442
  What is a pick rate and how is it measured?,general_faq
443
+ Why hasn't order #59121 left the dock yet?,order_status
data/latency_eval.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
- "intent_classifier_ms": 0.633,
3
- "anomaly_detector_ms": 14.676,
4
- "kb_retrieval_ms": 0.862,
5
  "note": "LLM generation latency depends on the external Inference API call and is measured live in the app, not benchmarked here."
6
  }
 
1
  {
2
+ "intent_classifier_ms": 0.476,
3
+ "anomaly_detector_ms": 10.104,
4
+ "kb_retrieval_ms": 0.735,
5
  "note": "LLM generation latency depends on the external Inference API call and is measured live in the app, not benchmarked here."
6
  }
data/retrieval_eval.json CHANGED
@@ -1,7 +1,7 @@
1
  {
2
- "hit_rate_at_1": 0.8,
3
  "hit_rate_at_2": 1.0,
4
- "n_queries": 10,
5
  "rows": [
6
  {
7
  "query": "How does an AS/RS crane retrieve a pallet?",
@@ -9,7 +9,7 @@
9
  "retrieved_top1": "asrs_overview",
10
  "hit@1": true,
11
  "hit@2": true,
12
- "top1_score": 0.2435
13
  },
14
  {
15
  "query": "What's the difference between an AGV and an AMR?",
@@ -17,7 +17,7 @@
17
  "retrieved_top1": "safety_protocol",
18
  "hit@1": false,
19
  "hit@2": true,
20
- "top1_score": 0.1499
21
  },
22
  {
23
  "query": "What does a WMS integrate with?",
@@ -25,7 +25,7 @@
25
  "retrieved_top1": "wms_overview",
26
  "hit@1": true,
27
  "hit@2": true,
28
- "top1_score": 0.2741
29
  },
30
  {
31
  "query": "Why would a sorter jam?",
@@ -33,7 +33,7 @@
33
  "retrieved_top1": "conveyor_sorting",
34
  "hit@1": true,
35
  "hit@2": true,
36
- "top1_score": 0.0959
37
  },
38
  {
39
  "query": "What is batch picking?",
@@ -41,7 +41,7 @@
41
  "retrieved_top1": "picking_strategies",
42
  "hit@1": true,
43
  "hit@2": true,
44
- "top1_score": 0.3279
45
  },
46
  {
47
  "query": "How can we predict a motor failure before it happens?",
@@ -49,7 +49,7 @@
49
  "retrieved_top1": "conveyor_sorting",
50
  "hit@1": false,
51
  "hit@2": true,
52
- "top1_score": 0.1426
53
  },
54
  {
55
  "query": "What should I do after a near-miss with a forklift?",
@@ -57,7 +57,7 @@
57
  "retrieved_top1": "safety_protocol",
58
  "hit@1": true,
59
  "hit@2": true,
60
- "top1_score": 0.3443
61
  },
62
  {
63
  "query": "How do we keep inventory counts accurate?",
@@ -65,7 +65,7 @@
65
  "retrieved_top1": "inventory_accuracy",
66
  "hit@1": true,
67
  "hit@2": true,
68
- "top1_score": 0.2345
69
  },
70
  {
71
  "query": "What KPIs should a warehouse manager track?",
@@ -73,7 +73,7 @@
73
  "retrieved_top1": "kpi_overview",
74
  "hit@1": true,
75
  "hit@2": true,
76
- "top1_score": 0.2838
77
  },
78
  {
79
  "query": "How can automated warehouses save energy?",
@@ -81,7 +81,63 @@
81
  "retrieved_top1": "energy_efficiency",
82
  "hit@1": true,
83
  "hit@2": true,
84
- "top1_score": 0.4366
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  }
86
  ]
87
  }
 
1
  {
2
+ "hit_rate_at_1": 0.8823529411764706,
3
  "hit_rate_at_2": 1.0,
4
+ "n_queries": 17,
5
  "rows": [
6
  {
7
  "query": "How does an AS/RS crane retrieve a pallet?",
 
9
  "retrieved_top1": "asrs_overview",
10
  "hit@1": true,
11
  "hit@2": true,
12
+ "top1_score": 0.2129
13
  },
14
  {
15
  "query": "What's the difference between an AGV and an AMR?",
 
17
  "retrieved_top1": "safety_protocol",
18
  "hit@1": false,
19
  "hit@2": true,
20
+ "top1_score": 0.1543
21
  },
22
  {
23
  "query": "What does a WMS integrate with?",
 
25
  "retrieved_top1": "wms_overview",
26
  "hit@1": true,
27
  "hit@2": true,
28
+ "top1_score": 0.2609
29
  },
30
  {
31
  "query": "Why would a sorter jam?",
 
33
  "retrieved_top1": "conveyor_sorting",
34
  "hit@1": true,
35
  "hit@2": true,
36
+ "top1_score": 0.0958
37
  },
38
  {
39
  "query": "What is batch picking?",
 
41
  "retrieved_top1": "picking_strategies",
42
  "hit@1": true,
43
  "hit@2": true,
44
+ "top1_score": 0.3191
45
  },
46
  {
47
  "query": "How can we predict a motor failure before it happens?",
 
49
  "retrieved_top1": "conveyor_sorting",
50
  "hit@1": false,
51
  "hit@2": true,
52
+ "top1_score": 0.1501
53
  },
54
  {
55
  "query": "What should I do after a near-miss with a forklift?",
 
57
  "retrieved_top1": "safety_protocol",
58
  "hit@1": true,
59
  "hit@2": true,
60
+ "top1_score": 0.3327
61
  },
62
  {
63
  "query": "How do we keep inventory counts accurate?",
 
65
  "retrieved_top1": "inventory_accuracy",
66
  "hit@1": true,
67
  "hit@2": true,
68
+ "top1_score": 0.1017
69
  },
70
  {
71
  "query": "What KPIs should a warehouse manager track?",
 
73
  "retrieved_top1": "kpi_overview",
74
  "hit@1": true,
75
  "hit@2": true,
76
+ "top1_score": 0.2761
77
  },
78
  {
79
  "query": "How can automated warehouses save energy?",
 
81
  "retrieved_top1": "energy_efficiency",
82
  "hit@1": true,
83
  "hit@2": true,
84
+ "top1_score": 0.4415
85
+ },
86
+ {
87
+ "query": "What is cross-docking and why use it?",
88
+ "expected": "cross_docking",
89
+ "retrieved_top1": "cross_docking",
90
+ "hit@1": true,
91
+ "hit@2": true,
92
+ "top1_score": 0.3365
93
+ },
94
+ {
95
+ "query": "How should a warehouse handle customer returns?",
96
+ "expected": "reverse_logistics",
97
+ "retrieved_top1": "reverse_logistics",
98
+ "hit@1": true,
99
+ "hit@2": true,
100
+ "top1_score": 0.2315
101
+ },
102
+ {
103
+ "query": "Should I use RFID or barcodes for pallet tracking?",
104
+ "expected": "rfid_vs_barcode",
105
+ "retrieved_top1": "rfid_vs_barcode",
106
+ "hit@1": true,
107
+ "hit@2": true,
108
+ "top1_score": 0.2714
109
+ },
110
+ {
111
+ "query": "How do I avoid congestion at the loading dock?",
112
+ "expected": "dock_scheduling",
113
+ "retrieved_top1": "dock_scheduling",
114
+ "hit@1": true,
115
+ "hit@2": true,
116
+ "top1_score": 0.2939
117
+ },
118
+ {
119
+ "query": "How should I decide where to store a new SKU?",
120
+ "expected": "slotting_optimization",
121
+ "retrieved_top1": "slotting_optimization",
122
+ "hit@1": true,
123
+ "hit@2": true,
124
+ "top1_score": 0.1115
125
+ },
126
+ {
127
+ "query": "How do warehouses control access to high-value inventory?",
128
+ "expected": "warehouse_security",
129
+ "retrieved_top1": "warehouse_security",
130
+ "hit@1": true,
131
+ "hit@2": true,
132
+ "top1_score": 0.4407
133
+ },
134
+ {
135
+ "query": "How can I tell if a picker is underperforming or just has a hard task?",
136
+ "expected": "labor_management",
137
+ "retrieved_top1": "labor_management",
138
+ "hit@1": true,
139
+ "hit@2": true,
140
+ "top1_score": 0.081
141
  }
142
  ]
143
  }
data/sample_sensor_batch.csv ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ id,motor_temp_c,vibration_mm_s,current_amps,belt_speed_mps
2
+ R001,53.17,1.6,10.33,1.53
3
+ R002,72.15,3.97,18.18,0.66
4
+ R003,77.61,5.44,21.41,0.79
5
+ R004,47.4,2.24,11.98,1.51
6
+ R005,51.09,2.65,11.54,1.69
7
+ R006,56.19,1.8,10.81,1.84
8
+ R007,49.93,2.17,11.96,1.33
9
+ R008,53.9,2.18,12.97,1.38
10
+ R009,52.52,2.24,11.45,1.58
11
+ R010,77.04,4.75,17.26,0.49
12
+ R011,55.45,1.61,12.52,1.62
13
+ R012,54.06,2.54,12.98,1.2
14
+ R013,51.28,2.26,11.54,1.34
15
+ R014,52.85,1.97,12.88,1.61
16
+ R015,51.03,2.14,11.85,1.57
17
+ R016,57.78,3.2,11.82,1.37
18
+ R017,47.63,2.11,13.75,1.48
19
+ R018,55.63,2.92,11.49,1.18
20
+ R019,56.43,1.43,14.29,1.49
21
+ R020,55.0,2.73,10.01,1.52
22
+ R021,55.42,2.63,11.36,1.51
23
+ R022,48.88,1.91,9.47,1.52
24
+ R023,49.62,2.58,11.7,1.65
25
+ R024,74.74,5.32,19.02,0.7
26
+ R025,55.24,2.26,13.89,1.47
27
+ R026,60.36,2.23,13.03,1.47
28
+ R027,53.09,2.1,8.95,1.27
29
+ R028,44.93,2.3,11.99,1.24
30
+ R029,56.96,2.88,11.62,1.34
31
+ R030,51.76,2.77,10.65,1.72
32
+ R031,84.59,7.01,17.6,1.4
33
+ R032,53.03,1.59,11.51,1.61
34
+ R033,76.36,4.55,19.03,0.81
35
+ R034,54.88,1.88,12.53,1.54
36
+ R035,54.81,2.26,10.06,1.37
37
+ R036,56.09,2.53,13.0,1.55
38
+ R037,49.84,2.49,11.33,1.41
39
+ R038,51.44,2.64,9.01,1.41
40
+ R039,54.25,1.86,13.58,1.63
41
+ R040,53.18,1.91,11.31,1.53
data/vision_eval.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "standard_noise_level": 0.4,
3
+ "n_test": 100,
4
+ "exact_match_rate": 0.88,
5
+ "count_mae": 0.17,
6
+ "occupancy_mae": 0.009444444444444445,
7
+ "noise_sweep_levels": [
8
+ 0.0,
9
+ 0.2,
10
+ 0.4,
11
+ 0.6,
12
+ 0.8,
13
+ 1.0
14
+ ],
15
+ "noise_sweep_exact_match_rates": [
16
+ 1.0,
17
+ 0.9166666666666666,
18
+ 0.8833333333333333,
19
+ 0.7666666666666667,
20
+ 0.8333333333333334,
21
+ 0.7666666666666667
22
+ ],
23
+ "method": "Classical CV: color-distance segmentation -> morphology -> connected components -> geometric filtering. No pretrained weights."
24
+ }
models/anomaly_iforest.joblib CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:1f3c085015adb1b4059275537b8f550cb569a97bd35e2020978083fb75873f57
3
  size 2166973
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0e238af00762e3dced90d74fe626523c83cf0cf3ecd2b7a8c6931ace04ab1641
3
  size 2166973
models/anomaly_scaler.joblib CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:5e2a15be4a9a58c2d584e76e2b2bc701f213afc469768faca1eeac44d962dede
3
  size 679
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:68bbb35009b07935b7cfd67fc41d04f8189ab81768d5ec57859c1ca139bff73e
3
  size 679
models/intent_pipeline.joblib CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:0c7a9a52d4512974c7c0dee05f15871cf0d3346b3a0e1a2ff7d7fb36e7a722f9
3
- size 86940
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c6f690a27b696b3e825190eec1cbe9491def156ce40347146fc8cd8714799959
3
+ size 86780
requirements.txt CHANGED
@@ -1,8 +1,11 @@
1
  gradio==5.9.1
 
2
  scikit-learn==1.7.2
3
  pandas==2.2.3
4
  numpy==1.26.4
5
  matplotlib==3.9.2
6
  joblib==1.4.2
7
  huggingface_hub==0.31.4
 
 
8
  spaces>=0.30.0
 
1
  gradio==5.9.1
2
+ pydantic==2.10.6
3
  scikit-learn==1.7.2
4
  pandas==2.2.3
5
  numpy==1.26.4
6
  matplotlib==3.9.2
7
  joblib==1.4.2
8
  huggingface_hub==0.31.4
9
+ opencv-python-headless==4.10.0.84
10
+ requests>=2.31.0
11
  spaces>=0.30.0
src/alerting.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ alerting.py -- ops integration: Slack alert (real Incoming Webhook if the
3
+ `SLACK_WEBHOOK_URL` secret is set) with a clearly-labelled preview fallback
4
+ otherwise, plus an email preview. Mirrors llm_client.py's pattern: real
5
+ integration when configured, never silently pretends to have sent anything.
6
+ """
7
+ import os
8
+ from dataclasses import dataclass
9
+ from datetime import datetime, timezone
10
+ from typing import Optional
11
+
12
+ try:
13
+ import requests
14
+ except ImportError: # pragma: no cover
15
+ requests = None
16
+
17
+
18
+ @dataclass
19
+ class AlertResult:
20
+ sent: bool
21
+ channel: str # "slack" | "preview-only"
22
+ message_preview: str
23
+ error: Optional[str] = None
24
+
25
+
26
+ def _fmt(zone: str, r: dict, score: float) -> str:
27
+ ts = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M UTC")
28
+ return (
29
+ f":rotating_light: *Equipment anomaly detected* -- {zone}\n"
30
+ f"*Time:* {ts}\n*Anomaly score:* {score:.2f} / 1.00\n"
31
+ f"*Readings:* temp={r.get('motor_temp_c','?')}°C, vibration={r.get('vibration_mm_s','?')} mm/s, "
32
+ f"current={r.get('current_amps','?')} A, belt_speed={r.get('belt_speed_mps','?')} m/s\n"
33
+ f"*Recommended action:* flag for inspection before next shift (bearing wear / "
34
+ f"misalignment / motor overload pattern)."
35
+ )
36
+
37
+
38
+ def send_anomaly_alert(zone: str, reading: dict, score: float) -> AlertResult:
39
+ text = _fmt(zone, reading, score)
40
+ url = os.environ.get("SLACK_WEBHOOK_URL")
41
+ if not url:
42
+ return AlertResult(False, "preview-only", text)
43
+ if requests is None:
44
+ return AlertResult(False, "preview-only", text, "`requests` not installed")
45
+ try:
46
+ resp = requests.post(url, json={"text": text}, timeout=5)
47
+ if resp.status_code == 200:
48
+ return AlertResult(True, "slack", text)
49
+ return AlertResult(False, "preview-only", text, f"Slack HTTP {resp.status_code}: {resp.text[:200]}")
50
+ except Exception as e: # noqa: BLE001
51
+ return AlertResult(False, "preview-only", text, f"{type(e).__name__}: {e}")
52
+
53
+
54
+ def format_email_preview(zone: str, reading: dict, score: float) -> str:
55
+ ts = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M UTC")
56
+ return (
57
+ f"To: maintenance-team@example.com\nSubject: [ALERT] Equipment anomaly detected -- {zone}\n\n"
58
+ f"Detected at {ts}. Anomaly score: {score:.2f} / 1.00\n"
59
+ f"Temp {reading.get('motor_temp_c','?')} C | Vibration {reading.get('vibration_mm_s','?')} mm/s | "
60
+ f"Current {reading.get('current_amps','?')} A | Belt {reading.get('belt_speed_mps','?')} m/s\n"
61
+ f"Recommended action: flag for inspection before the next shift.\n"
62
+ )
src/data_generation.py CHANGED
@@ -268,4 +268,11 @@ RETRIEVAL_EVAL_SET = [
268
  ("How do we keep inventory counts accurate?", "inventory_accuracy"),
269
  ("What KPIs should a warehouse manager track?", "kpi_overview"),
270
  ("How can automated warehouses save energy?", "energy_efficiency"),
 
 
 
 
 
 
 
271
  ]
 
268
  ("How do we keep inventory counts accurate?", "inventory_accuracy"),
269
  ("What KPIs should a warehouse manager track?", "kpi_overview"),
270
  ("How can automated warehouses save energy?", "energy_efficiency"),
271
+ ("What is cross-docking and why use it?", "cross_docking"),
272
+ ("How should a warehouse handle customer returns?", "reverse_logistics"),
273
+ ("Should I use RFID or barcodes for pallet tracking?", "rfid_vs_barcode"),
274
+ ("How do I avoid congestion at the loading dock?", "dock_scheduling"),
275
+ ("How should I decide where to store a new SKU?", "slotting_optimization"),
276
+ ("How do warehouses control access to high-value inventory?", "warehouse_security"),
277
+ ("How can I tell if a picker is underperforming or just has a hard task?", "labor_management"),
278
  ]
src/knowledge_base.py CHANGED
@@ -155,4 +155,59 @@ KNOWLEDGE_BASE = [
155
  "electricity tariff windows."
156
  ),
157
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  ]
 
155
  "electricity tariff windows."
156
  ),
157
  },
158
+ {
159
+ "id": "cross_docking", "title": "Cross-Docking", "category": "process",
160
+ "text": ("Cross-docking moves inbound goods directly from receiving to an outbound "
161
+ "shipment with little or no intermediate storage, typically staged for only a "
162
+ "few hours. It reduces inventory holding cost and handling time but requires "
163
+ "tightly synchronized inbound and outbound schedules, since a delayed inbound "
164
+ "truck can cascade into missed outbound departures."),
165
+ },
166
+ {
167
+ "id": "reverse_logistics", "title": "Returns & Reverse Logistics", "category": "process",
168
+ "text": ("Reverse logistics covers the flow of returned goods back through the warehouse: "
169
+ "inspection, grading (resellable, refurbishable, or scrap), restocking, and "
170
+ "sometimes vendor chargebacks. High e-commerce return rates make a dedicated "
171
+ "returns processing area and fast grading turnaround important for recovering "
172
+ "inventory value quickly."),
173
+ },
174
+ {
175
+ "id": "rfid_vs_barcode", "title": "RFID vs. Barcode Scanning", "category": "equipment",
176
+ "text": ("Barcode scanning requires line-of-sight to a single label and is cheap and highly "
177
+ "accurate. RFID (radio-frequency identification) can read many tags at once "
178
+ "without line-of-sight, speeding up cycle counting and dock receiving, but tags "
179
+ "cost more and dense metal racking can cause read interference. Many warehouses "
180
+ "use barcodes for unit-level picking and RFID for pallet- or case-level tracking."),
181
+ },
182
+ {
183
+ "id": "dock_scheduling", "title": "Dock Scheduling & Yard Management", "category": "process",
184
+ "text": ("Dock scheduling assigns inbound and outbound trucks to specific loading dock doors "
185
+ "and time slots to avoid yard congestion and dock-door bottlenecks. A yard "
186
+ "management system (YMS) tracks trailer location and status across the yard and "
187
+ "is often integrated with the WMS so put-away labor can be planned before a "
188
+ "trailer even arrives."),
189
+ },
190
+ {
191
+ "id": "slotting_optimization", "title": "Warehouse Slotting Optimization", "category": "process",
192
+ "text": ("Slotting assigns each SKU to a storage location based on pick frequency, size, "
193
+ "weight, and affinity with frequently co-ordered SKUs. Placing high-velocity items "
194
+ "near pack-out stations and keeping heavy items at waist height are common rules. "
195
+ "Poor slotting is one of the most common causes of excess picker travel time."),
196
+ },
197
+ {
198
+ "id": "warehouse_security", "title": "Warehouse Security & Access Control", "category": "safety",
199
+ "text": ("Warehouse security typically combines badge-based access control at building and "
200
+ "high-value-cage entry points, CCTV coverage of dock doors and aisles, and "
201
+ "shrinkage tracking (the gap between recorded and physically counted inventory). "
202
+ "High-value or regulated goods often require a separate caged area with its own "
203
+ "access log."),
204
+ },
205
+ {
206
+ "id": "labor_management", "title": "Labor Management & Workforce Scheduling", "category": "process",
207
+ "text": ("A labor management system (LMS) sets expected task times based on engineered "
208
+ "standards, tracks actual performance against them, and helps schedule headcount "
209
+ "to forecast order volume by shift. It flags tasks taking significantly longer "
210
+ "than expected, which can indicate a process problem or a training gap rather "
211
+ "than a motivation problem."),
212
+ },
213
  ]
src/llm_client.py CHANGED
@@ -107,15 +107,40 @@ def _extractive_fallback(query: str, sources: List[RetrievedDoc]) -> str:
107
  )
108
 
109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  def answer_query(
111
  query: str,
112
  retriever: KBRetriever,
113
  k: int = 2,
114
  max_tokens: int = 350,
 
115
  ) -> AssistantResponse:
 
 
116
  start = time.time()
117
  sources = retriever.retrieve(query, k=k)
118
  context_block = "\n\n".join(f"[{s.title}]\n{s.text}" for s in sources)
 
119
 
120
  hf_token = _get_hf_token()
121
 
@@ -144,10 +169,9 @@ def answer_query(
144
  debug_errors=[f"huggingface_hub not importable: {e}"],
145
  )
146
 
147
- messages = [
148
- {"role": "system", "content": SYSTEM_PROMPT},
149
- {"role": "user", "content": f"CONTEXT:\n{context_block}\n\nQUESTION: {query}"},
150
- ]
151
 
152
  errors = []
153
  for candidate in MODEL_CANDIDATES:
 
107
  )
108
 
109
 
110
+ MAX_HISTORY_TURNS = 4 # prior (user, assistant) pairs carried into the LLM call
111
+
112
+
113
+ def _clean_history(history: Optional[List[dict]]) -> List[dict]:
114
+ """Normalize Gradio's messages-format history into a short, clean list safe
115
+ to feed back to the LLM: strips our own metadata footer from assistant
116
+ turns and keeps only the last MAX_HISTORY_TURNS pairs (bounded prompt)."""
117
+ if not history:
118
+ return []
119
+ cleaned = []
120
+ for turn in history:
121
+ role, content = turn.get("role"), turn.get("content", "")
122
+ if not isinstance(content, str):
123
+ continue
124
+ if role == "assistant" and "\n\n---\n" in content:
125
+ content = content.split("\n\n---\n")[0]
126
+ if role in ("user", "assistant") and content.strip():
127
+ cleaned.append({"role": role, "content": content.strip()})
128
+ return cleaned[-MAX_HISTORY_TURNS * 2:]
129
+
130
+
131
  def answer_query(
132
  query: str,
133
  retriever: KBRetriever,
134
  k: int = 2,
135
  max_tokens: int = 350,
136
+ history: Optional[List[dict]] = None,
137
  ) -> AssistantResponse:
138
+ """`history`: prior turns (Gradio messages format) enabling multi-turn
139
+ follow-ups like "what about Zone D instead?". Omit for single-turn."""
140
  start = time.time()
141
  sources = retriever.retrieve(query, k=k)
142
  context_block = "\n\n".join(f"[{s.title}]\n{s.text}" for s in sources)
143
+ prior_turns = _clean_history(history)
144
 
145
  hf_token = _get_hf_token()
146
 
 
169
  debug_errors=[f"huggingface_hub not importable: {e}"],
170
  )
171
 
172
+ messages = [{"role": "system", "content": SYSTEM_PROMPT}]
173
+ messages.extend(prior_turns)
174
+ messages.append({"role": "user", "content": f"CONTEXT:\n{context_block}\n\nQUESTION: {query}"})
 
175
 
176
  errors = []
177
  for candidate in MODEL_CANDIDATES:
src/vision_model.py ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ vision_model.py
3
+ -----------------
4
+ Visual Inventory & Rack Occupancy Scanner.
5
+
6
+ A deliberately different computer-vision approach from a YOLO-style deep
7
+ detector: a small, fully deterministic **classical image-processing
8
+ pipeline** (OpenCV: color-based background/shelf segmentation ->
9
+ morphological cleanup -> connected components -> geometric filtering) that
10
+ (a) counts box/pallet-like objects on a warehouse rack and (b) estimates
11
+ what fraction of the rack's storage slots are occupied.
12
+
13
+ Why classical CV, deliberately: zero model downloads (self-contained and
14
+ reproducible), runs instantly on a free CPU Space, and every detection is a
15
+ traceable contour rather than an opaque activation. A production system
16
+ would likely fine-tune a detector; this module demonstrates the systems
17
+ thinking (synthetic ground truth, honest evaluation under noise) that would
18
+ carry over directly.
19
+
20
+ Synthetic scenes: rack photos can't be licensed/scraped for a portfolio
21
+ project, so -- like every other dataset here -- scenes are generated with
22
+ PIL with known ground truth, which is what allows honest metrics.
23
+
24
+ Development notes (kept because they're real):
25
+ * v1 used Canny edges + heavy dilation and merged every box and shelf bar
26
+ into one blob. Switching to per-pixel color-distance segmentation fixed it.
27
+ * On clean renders (noise_level=0) v2 hit a suspiciously perfect 100%, so
28
+ `noise_level` (Gaussian pixel noise, brightness/contrast jitter, per-box
29
+ color variation) was added; accuracy then degrades realistically.
30
+ * Occupancy was first computed from padded box pixel area vs full cell area
31
+ (a definitional mismatch that under-counted ~40%); it now counts occupied
32
+ grid cells, matching how ground truth is defined.
33
+ """
34
+
35
+ import random
36
+ from dataclasses import dataclass
37
+ from typing import List, Optional, Tuple
38
+
39
+ import cv2
40
+ import numpy as np
41
+ from PIL import Image, ImageDraw
42
+
43
+ RACK_W, RACK_H = 640, 400
44
+ SHELF_ROWS, SHELF_COLS = 3, 6
45
+ MARGIN = 20
46
+ SHELF_BAR_H = 10
47
+ BOX_COLORS = [
48
+ (181, 101, 29), (139, 69, 19), (205, 133, 63), (160, 82, 45),
49
+ (222, 184, 135), (128, 0, 0), (46, 87, 46), (25, 65, 100),
50
+ ]
51
+ BG_COLOR = (235, 235, 230)
52
+ SHELF_COLOR = (90, 90, 95)
53
+
54
+
55
+ @dataclass
56
+ class RackScene:
57
+ image: Image.Image
58
+ true_box_count: int
59
+ true_occupancy: float # fraction of cells filled, 0-1
60
+
61
+
62
+ def generate_rack_scene(fill_prob: float = 0.6, seed: Optional[int] = None, noise_level: float = 0.0) -> RackScene:
63
+ """One synthetic rack image with known ground-truth box count/occupancy."""
64
+ rng = random.Random(seed)
65
+ img = Image.new("RGB", (RACK_W, RACK_H), BG_COLOR)
66
+ draw = ImageDraw.Draw(img)
67
+ cell_w = (RACK_W - 2 * MARGIN) / SHELF_COLS
68
+ cell_h = (RACK_H - 2 * MARGIN) / SHELF_ROWS
69
+
70
+ for row in range(SHELF_ROWS + 1):
71
+ y = MARGIN + row * cell_h
72
+ draw.rectangle([MARGIN - 5, y - SHELF_BAR_H / 2, RACK_W - MARGIN + 5, y + SHELF_BAR_H / 2], fill=SHELF_COLOR)
73
+
74
+ n_filled = 0
75
+ for row in range(SHELF_ROWS):
76
+ for col in range(SHELF_COLS):
77
+ if rng.random() < fill_prob:
78
+ x0, y0 = MARGIN + col * cell_w, MARGIN + row * cell_h
79
+ pad = min(cell_w, cell_h) * 0.12
80
+ bw, bh = cell_w - 2 * pad, cell_h - 2 * pad - 4
81
+ bx0, by0 = x0 + pad, y0 + pad + 4
82
+ base = rng.choice(BOX_COLORS)
83
+ if noise_level > 0:
84
+ j = int(25 * noise_level)
85
+ color = tuple(int(np.clip(c + rng.randint(-j, j), 0, 255)) for c in base)
86
+ else:
87
+ color = base
88
+ draw.rectangle([bx0, by0, bx0 + bw, by0 + bh], fill=color, outline=(30, 30, 30), width=2)
89
+ draw.line([bx0 + 4, by0 + bh * 0.4, bx0 + bw - 4, by0 + bh * 0.4], fill=(20, 20, 20), width=2)
90
+ n_filled += 1
91
+
92
+ if noise_level > 0:
93
+ arr = np.array(img).astype(np.float32)
94
+ brightness = rng.uniform(-20, 20) * noise_level
95
+ contrast = 1.0 + rng.uniform(-0.15, 0.15) * noise_level
96
+ arr = (arr - 127.5) * contrast + 127.5 + brightness
97
+ arr += np.random.RandomState(seed).normal(0, 10 * noise_level, arr.shape)
98
+ img = Image.fromarray(np.clip(arr, 0, 255).astype(np.uint8))
99
+
100
+ return RackScene(img, n_filled, n_filled / (SHELF_ROWS * SHELF_COLS))
101
+
102
+
103
+ @dataclass
104
+ class DetectionResult:
105
+ detected_count: int
106
+ estimated_occupancy: float
107
+ annotated_image: Image.Image
108
+ boxes: List[Tuple[int, int, int, int]]
109
+
110
+
111
+ def _iou(a, b) -> float:
112
+ ax, ay, aw, ah = a
113
+ bx, by, bw, bh = b
114
+ iw = max(0, min(ax + aw, bx + bw) - max(ax, bx))
115
+ ih = max(0, min(ay + ah, by + bh) - max(ay, by))
116
+ inter = iw * ih
117
+ union = aw * ah + bw * bh - inter
118
+ return inter / union if union > 0 else 0.0
119
+
120
+
121
+ def _nms(boxes, thr=0.3):
122
+ kept = []
123
+ for b in sorted(boxes, key=lambda b: b[2] * b[3], reverse=True):
124
+ if all(_iou(b, k) < thr for k in kept):
125
+ kept.append(b)
126
+ return kept
127
+
128
+
129
+ def detect_boxes(image: Image.Image, min_area_frac: float = 0.01, max_area_frac: float = 0.25) -> DetectionResult:
130
+ """Color-distance segmentation -> morphology -> contours -> geometric filter."""
131
+ rgb = np.array(image.convert("RGB")).astype(np.int16)
132
+ dist = lambda c: np.sqrt(np.sum((rgb - np.array(c)) ** 2, axis=-1))
133
+ mask = ((dist(BG_COLOR) > 60) & (dist(SHELF_COLOR) > 60)).astype(np.uint8) * 255
134
+ k = np.ones((3, 3), np.uint8)
135
+ mask = cv2.morphologyEx(mask, cv2.MORPH_CLOSE, k, iterations=2)
136
+ mask = cv2.morphologyEx(mask, cv2.MORPH_OPEN, k, iterations=1)
137
+ contours, _ = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
138
+
139
+ h, w = rgb.shape[:2]
140
+ boxes = []
141
+ for c in contours:
142
+ area = cv2.contourArea(c)
143
+ if not (h * w * min_area_frac <= area <= h * w * max_area_frac):
144
+ continue
145
+ x, y, bw, bh = cv2.boundingRect(c)
146
+ aspect = bw / float(bh) if bh else 0
147
+ if 0.2 <= aspect <= 3.0:
148
+ boxes.append((x, y, bw, bh))
149
+ boxes = _nms(boxes)
150
+
151
+ cell_w = (RACK_W - 2 * MARGIN) / SHELF_COLS
152
+ cell_h = (RACK_H - 2 * MARGIN) / SHELF_ROWS
153
+ cells = set()
154
+ for (x, y, bw, bh) in boxes:
155
+ col = max(0, min(SHELF_COLS - 1, int((x + bw / 2 - MARGIN) // cell_w)))
156
+ row = max(0, min(SHELF_ROWS - 1, int((y + bh / 2 - MARGIN) // cell_h)))
157
+ cells.add((row, col))
158
+ occupancy = len(cells) / (SHELF_ROWS * SHELF_COLS)
159
+
160
+ annotated = image.convert("RGB").copy()
161
+ d = ImageDraw.Draw(annotated)
162
+ for (x, y, bw, bh) in boxes:
163
+ d.rectangle([x, y, x + bw, y + bh], outline=(0, 220, 90), width=3)
164
+ return DetectionResult(len(boxes), float(occupancy), annotated, boxes)