uttarasawant commited on
Commit
9943408
·
verified ·
1 Parent(s): fbe9d58

Update app.py to update recipe

Browse files
Files changed (1) hide show
  1. app.py +49 -8
app.py CHANGED
@@ -76,7 +76,6 @@ def process_kitchen_operations(input_image, budget, days):
76
  with torch.no_grad():
77
  generated_ids = model.generate(**inputs, max_new_tokens=50)
78
 
79
- # Trim prompt padding from generation token boundaries
80
  generated_ids_trimmed = [
81
  out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
82
  ]
@@ -88,23 +87,65 @@ def process_kitchen_operations(input_image, budget, days):
88
 
89
  # 3. Dynamic array mapping to local state matrix
90
  df_rows = []
91
- raw_items = [item.strip() for item in detected_text.replace(".", ",").split(",") if item.strip()]
92
 
93
  if not raw_items or raw_items == [""]:
94
- raw_items = ["Salmon Fillet", "Fresh Broccoli", "Cherry Tomatoes"]
95
 
96
  for raw_item in raw_items:
97
- df_rows.append([raw_item.title(), "1 Unit", "Fresh (Nominal)", "$3.50"])
98
 
99
  save_state_to_disk(df_rows)
100
 
 
 
 
101
  daily_budget_allowance = budget / days
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  blueprint_md = (
103
- f"### 🛠️ Logistics Routing Strategy Generated via Qwen2.5-VL\n\n"
104
  f"**Operational Horizon:** {days} Days | **Daily Financial Runway Ceiling:** ${daily_budget_allowance:.2f}/day\n\n"
105
- f"📋 **Dynamic Cook Execution Pathway:**\n"
106
- f"- **Day 1 Asset Recovery:** Prioritize routing fresh profile (**{raw_items[0]}**) mapped by the edge sensor.\n"
107
- f"- **Day 2-3 Runway Balance:** Allocate remaining items under your strict financial boundary of ${daily_budget_allowance:.2f}/day."
 
 
 
 
 
 
108
  )
109
 
110
  return df_rows, blueprint_md
 
76
  with torch.no_grad():
77
  generated_ids = model.generate(**inputs, max_new_tokens=50)
78
 
 
79
  generated_ids_trimmed = [
80
  out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
81
  ]
 
87
 
88
  # 3. Dynamic array mapping to local state matrix
89
  df_rows = []
90
+ raw_items = [item.strip().title() for item in detected_text.replace(".", ",").split(",") if item.strip()]
91
 
92
  if not raw_items or raw_items == [""]:
93
+ raw_items = ["Salmon", "Broccoli", "Tomatoes", "Lettuce", "Chicken", "Onions"]
94
 
95
  for raw_item in raw_items:
96
+ df_rows.append([raw_item, "1 Unit", "Fresh (Nominal)", "$3.50"])
97
 
98
  save_state_to_disk(df_rows)
99
 
100
+ # =====================================================================
101
+ # 🍳 DYNAMIC LOGISTICS & RECIPE GENERATION ENGINE
102
+ # =====================================================================
103
  daily_budget_allowance = budget / days
104
+
105
+ # Categorize ingredients on the fly for logical pairing
106
+ lower_items = [x.lower() for x in raw_items]
107
+
108
+ proteins = [x for x in raw_items if any(p in x.lower() for p in ['salmon', 'chicken', 'beef', 'pork', 'tofu', 'turkey'])]
109
+ veggies = [x for x in raw_items if any(v in x.lower() for v in ['broccoli', 'lettuce', 'tomato', 'pepper', 'mushroom', 'spinach', 'eggplant'])]
110
+ aromatics = [x for x in raw_items if any(a in x.lower() for a in ['onion', 'garlic', 'ginger'])]
111
+
112
+ # Fallback lists to maintain stability if vision classifications drift
113
+ if not proteins: proteins = ["Discovered Protein Asset"]
114
+ if not veggies: veggies = ["Fresh Greens"]
115
+
116
+ # Generate recipe structures step-by-step based on available timeline bounds
117
+ recipe_steps = []
118
+
119
+ # Day 1 Strategy: Perishable/Premium Protein Routing
120
+ p1 = proteins[0]
121
+ v1 = veggies[0] if len(veggies) > 0 else "Accompanying Vegetables"
122
+ a1 = f" sautéed with {aromatics[0]}" if aromatics else ""
123
+ recipe_steps.append(f"**Day 1 (Asset Recovery - High Priority):** Prepare a **Pan-Seared {p1}** paired with a crisp side of fresh **{v1}**{a1}. Consuming these items early maximizes nutritional book value and prevents wilting telemetry alerts.")
124
+
125
+ # Day 2 Strategy: Secondary Protein Optimization
126
+ if days >= 2:
127
+ p2 = proteins[1] if len(proteins) > 1 else proteins[0]
128
+ v2 = veggies[1] if len(veggies) > 1 else (veggies[0] if len(veggies) > 0 else "Assorted Garden Greens")
129
+ recipe_steps.append(f"**Day 2 (Mid-Horizon Balance):** Execute a **Skillet {p2} Stir-Fry** utilizing chopped **{v2}**. This securely routes secondary core components into your operations phase before quality degradations occur.")
130
+
131
+ # Day 3 Strategy: Final Consolidated Field Clearance
132
+ if days >= 3:
133
+ v_remaining = ", ".join(raw_items[2:5]) if len(raw_items) > 2 else "remaining visual assets"
134
+ recipe_steps.append(f"**Day 3 (Horizon Target - Clearance Run):** Consolidate your inventory with an **Optimized Harvest Bowl / Soup Base**, stewing **{v_remaining}**. This effectively clears out remaining active fridge assets while respecting your daily allocation.")
135
+
136
+ # Build the complete, compiled markdown payload
137
  blueprint_md = (
138
+ f"### 🛠️ Detailed Culinary Logistics Blueprint (Generated via Qwen2.5-VL)\n\n"
139
  f"**Operational Horizon:** {days} Days | **Daily Financial Runway Ceiling:** ${daily_budget_allowance:.2f}/day\n\n"
140
+ f"📋 **Step-by-Step Cooking Execution Path:**\n\n"
141
+ )
142
+
143
+ for step in recipe_steps[:days]:
144
+ blueprint_md += f"- {step}\n\n"
145
+
146
+ blueprint_md += (
147
+ f"⚠️ **Operational Cost Control:** Keeping cumulative execution paths restricted to these identified items "
148
+ f"safely maintains your target financial boundary of **${budget:.2f} USD** across the entire pipeline window."
149
  )
150
 
151
  return df_rows, blueprint_md