Update app.py with mock ingredients
Browse files
app.py
CHANGED
|
@@ -1,46 +1,74 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
-
import json
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
| 8 |
mock_detected_assets = {
|
| 9 |
"assets": [
|
| 10 |
-
{"ingredient": "Greek Yogurt", "qty": "0.5 Liters", "status": "Fresh", "est_cost_usd": 2.50},
|
| 11 |
-
{"ingredient": "Baby Spinach", "qty": "1 Bag", "status": "Wilting (
|
| 12 |
-
{"ingredient": "Chicken Breast", "qty": "400 Grams", "status": "Fresh", "est_cost_usd": 6.50},
|
| 13 |
-
{"ingredient": "Yellow Onion", "qty": "1 Whole", "status": "Fresh", "est_cost_usd": 0.80}
|
| 14 |
]
|
| 15 |
}
|
| 16 |
|
| 17 |
-
# Map
|
| 18 |
df_rows = [
|
| 19 |
[item['ingredient'], item['qty'], item['status'], f"${item['est_cost_usd']:.2f}"]
|
| 20 |
for item in mock_detected_assets['assets']
|
| 21 |
]
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
#
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
| 26 |
gr.Markdown("# 🛰️ Parallel Plate: Kitchen Operations & Visual Logistics Engine")
|
| 27 |
-
gr.Markdown("### *Physical-to-Digital Twin Asset Management Pipeline (
|
| 28 |
|
| 29 |
with gr.Row():
|
| 30 |
-
# Left
|
| 31 |
with gr.Column(scale=1):
|
| 32 |
gr.Markdown("### 📸 1. Physical Edge Ingestion")
|
| 33 |
image_input = gr.Image(label="Upload Fridge Optical Survey Scan", type="pil")
|
| 34 |
|
| 35 |
with gr.Row():
|
| 36 |
-
budget_slider = gr.Slider(minimum=5, maximum=100, value=25, step=5, label="
|
| 37 |
days_slider = gr.Slider(minimum=1, maximum=7, value=3, step=1, label="Target Horizon (Days)")
|
| 38 |
|
| 39 |
scan_btn = gr.Button("🚀 Initialize Asset Optimization Scan", variant="primary")
|
| 40 |
|
| 41 |
-
# Right
|
| 42 |
with gr.Column(scale=1):
|
| 43 |
-
gr.Markdown("### 📊 2. Active
|
| 44 |
inventory_df = gr.Dataframe(
|
| 45 |
headers=["Ingredient Asset", "Current Volume / Qty", "Telemetry Status", "Book Value (Est)"],
|
| 46 |
datatype=["str", "str", "str", "str"],
|
|
@@ -48,19 +76,19 @@ with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
|
|
| 48 |
interactive=True
|
| 49 |
)
|
| 50 |
|
| 51 |
-
gr.Markdown("###
|
| 52 |
output_text = gr.Markdown("*Awaiting asset telemetry mapping to generate optimal cooking execution paths...*")
|
| 53 |
|
| 54 |
-
#
|
| 55 |
scan_btn.click(
|
| 56 |
-
fn=
|
| 57 |
-
inputs=[image_input],
|
| 58 |
-
outputs=[inventory_df]
|
| 59 |
)
|
| 60 |
|
| 61 |
-
# Launch the engine
|
| 62 |
if __name__ == "__main__":
|
| 63 |
-
|
|
|
|
| 64 |
|
| 65 |
## trial 1
|
| 66 |
# import gradio as gr
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
|
|
|
| 3 |
|
| 4 |
+
# =====================================================================
|
| 5 |
+
# 🔀 LOCAL DETERMINISTIC LOGISTICS & RESOURCE ROUTING ENGINE
|
| 6 |
+
# =====================================================================
|
| 7 |
+
def process_kitchen_operations(input_image, budget, days):
|
| 8 |
+
# 1. Physical Edge Ingestion Simulation (Assets parsed from the scan)
|
| 9 |
mock_detected_assets = {
|
| 10 |
"assets": [
|
| 11 |
+
{"ingredient": "Greek Yogurt", "qty": "0.5 Liters", "status": "Fresh", "est_cost_usd": 2.50, "calories": 300},
|
| 12 |
+
{"ingredient": "Baby Spinach", "qty": "1 Bag", "status": "Wilting (Critical)", "est_cost_usd": 3.00, "calories": 50},
|
| 13 |
+
{"ingredient": "Chicken Breast", "qty": "400 Grams", "status": "Fresh", "est_cost_usd": 6.50, "calories": 650},
|
| 14 |
+
{"ingredient": "Yellow Onion", "qty": "1 Whole", "status": "Fresh", "est_cost_usd": 0.80, "calories": 40}
|
| 15 |
]
|
| 16 |
}
|
| 17 |
|
| 18 |
+
# 2. Map unstructured results directly into our Digital Twin Dataframe format
|
| 19 |
df_rows = [
|
| 20 |
[item['ingredient'], item['qty'], item['status'], f"${item['est_cost_usd']:.2f}"]
|
| 21 |
for item in mock_detected_assets['assets']
|
| 22 |
]
|
| 23 |
+
|
| 24 |
+
# 3. Constraint-Based Routing Optimization Logic (Local Math Execution)
|
| 25 |
+
daily_budget_allowance = budget / days
|
| 26 |
+
total_asset_value = sum(item['est_cost_usd'] for item in mock_detected_assets['assets'])
|
| 27 |
+
|
| 28 |
+
# Prioritization check for expiring assets (The Wilting Spinach)
|
| 29 |
+
critical_items = [item['ingredient'] for item in mock_detected_assets['assets'] if "Wilting" in item['status']]
|
| 30 |
+
|
| 31 |
+
# Generate the dynamic markdown operational blueprint
|
| 32 |
+
blueprint_md = f"### 🛠️ Logistics Routing Strategy Generated\n"
|
| 33 |
+
blueprint_md += f"**Operational Horizon:** {days} Days | **Daily Financial Ceiling:** ${daily_budget_allowance:.2f}/day\n\n"
|
| 34 |
+
|
| 35 |
+
blueprint_md += "#### 🚨 High-Priority Asset Despatches (Use Immediately):\n"
|
| 36 |
+
for item in critical_items:
|
| 37 |
+
blueprint_md += f"- **{item}** showing high decay telemetry. Scheduled for immediate integration into Day 1.\n"
|
| 38 |
+
|
| 39 |
+
blueprint_md += "\n#### 📋 Cook Execution Pathway:\n"
|
| 40 |
+
blueprint_md += f"- **Day 1 (Asset Optimization):** Creamy Spinach & Chicken Skillet. *Saves {critical_items[0] if critical_items else 'assets'} from spoiling. Uses $0.00 extra out-of-pocket budget.*\n"
|
| 41 |
+
|
| 42 |
+
if daily_budget_allowance < 5.00:
|
| 43 |
+
blueprint_md += "- **Day 2-3 (Scarcity Protocol):** Greek Yogurt Marinated Chicken bites with caramelized onions. *Hyper-low resource allocation mode engaged to preserve budget runway.*"
|
| 44 |
+
else:
|
| 45 |
+
blueprint_md += "- **Day 2-3 (Nominal Operations):** Chicken Prep over balanced greens. *Nominal baseline strategy.*"
|
| 46 |
+
|
| 47 |
+
return df_rows, blueprint_md
|
| 48 |
|
| 49 |
+
# =====================================================================
|
| 50 |
+
# 🎨 GRADIO 6.0 OPERATIONS CENTER DESIGN
|
| 51 |
+
# =====================================================================
|
| 52 |
+
# Notice: Removed theme option from here to fix the startup crash
|
| 53 |
+
with gr.Blocks() as demo:
|
| 54 |
gr.Markdown("# 🛰️ Parallel Plate: Kitchen Operations & Visual Logistics Engine")
|
| 55 |
+
gr.Markdown("### *Physical-to-Digital Twin Asset Management Pipeline (Badge Tier: 🔌 Off the Grid)*")
|
| 56 |
|
| 57 |
with gr.Row():
|
| 58 |
+
# Left Operational Node: Sensory Edge Scanning
|
| 59 |
with gr.Column(scale=1):
|
| 60 |
gr.Markdown("### 📸 1. Physical Edge Ingestion")
|
| 61 |
image_input = gr.Image(label="Upload Fridge Optical Survey Scan", type="pil")
|
| 62 |
|
| 63 |
with gr.Row():
|
| 64 |
+
budget_slider = gr.Slider(minimum=5, maximum=100, value=25, step=5, label="Runway Budget ($ USD)")
|
| 65 |
days_slider = gr.Slider(minimum=1, maximum=7, value=3, step=1, label="Target Horizon (Days)")
|
| 66 |
|
| 67 |
scan_btn = gr.Button("🚀 Initialize Asset Optimization Scan", variant="primary")
|
| 68 |
|
| 69 |
+
# Right Operational Node: Real-time State Machine Telemetry
|
| 70 |
with gr.Column(scale=1):
|
| 71 |
+
gr.Markdown("### 📊 2. Active Refrigerator Digital Twin")
|
| 72 |
inventory_df = gr.Dataframe(
|
| 73 |
headers=["Ingredient Asset", "Current Volume / Qty", "Telemetry Status", "Book Value (Est)"],
|
| 74 |
datatype=["str", "str", "str", "str"],
|
|
|
|
| 76 |
interactive=True
|
| 77 |
)
|
| 78 |
|
| 79 |
+
gr.Markdown("### 🔀 3. Resource Routing & Recipe Output")
|
| 80 |
output_text = gr.Markdown("*Awaiting asset telemetry mapping to generate optimal cooking execution paths...*")
|
| 81 |
|
| 82 |
+
# Wire up the execution event trigger loop
|
| 83 |
scan_btn.click(
|
| 84 |
+
fn=process_kitchen_operations,
|
| 85 |
+
inputs=[image_input, budget_slider, days_slider],
|
| 86 |
+
outputs=[inventory_df, output_text]
|
| 87 |
)
|
| 88 |
|
|
|
|
| 89 |
if __name__ == "__main__":
|
| 90 |
+
# Theme configuration parameters are passed cleanly here to meet Gradio 6.0 strict specs
|
| 91 |
+
demo.launch(theme=gr.themes.Monochrome())
|
| 92 |
|
| 93 |
## trial 1
|
| 94 |
# import gradio as gr
|