Iris314 commited on
Commit
ca7f156
·
verified ·
1 Parent(s): 2a83ea2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -0
app.py CHANGED
@@ -377,6 +377,37 @@ def run_pipeline(
377
  f"⚠️ Error: {exc}",
378
  )
379
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
380
 
381
  def record_feedback(selected_recipe: str, user_id: str, feedback_rows: List[Dict[str, Any]]):
382
  if not selected_recipe:
@@ -441,6 +472,23 @@ with gr.Blocks(title="Smart Fridge Recipe Assistant", theme=gr.themes.Soft()) as
441
  type="pil",
442
  height=350,
443
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
444
 
445
  detection_json = gr.JSON(label="Detection payload")
446
  annotated_output = gr.Image(label="Annotated detection", height=350)
 
377
  f"⚠️ Error: {exc}",
378
  )
379
 
380
+ def run_detection_only(image, user_id):
381
+
382
+ rgb_image = ensure_numpy_image(image)
383
+ upload_path = write_temp_image(rgb_image)
384
+
385
+ temp_dir = Path(tempfile.mkdtemp(prefix="fridge_outputs_"))
386
+ output_json = temp_dir / "recipe_input.json"
387
+ output_image = temp_dir / "annotated_image.jpg"
388
+
389
+ detection_result = detect_and_generate(
390
+ image_path=upload_path,
391
+ credentials=ROBOFLOW_CREDENTIALS,
392
+ conf_threshold=0.4,
393
+ overlap_threshold=0.3,
394
+ conf_split=0.7,
395
+ output_json=str(output_json),
396
+ output_image=str(output_image),
397
+ )
398
+ Path(upload_path).unlink(missing_ok=True)
399
+
400
+ detection_payload = detection_result["recipe_json"]
401
+ ingredients = detection_payload.get("ingredients", [])
402
+
403
+ ingredient_rows = []
404
+ for ing in ingredients:
405
+ name = ing.get("name", "")
406
+ conf = ing.get("confidence", 1.0)
407
+ ingredient_rows.append([name, conf])
408
+
409
+ return str(output_image), detection_payload, ingredient_rows
410
+
411
 
412
  def record_feedback(selected_recipe: str, user_id: str, feedback_rows: List[Dict[str, Any]]):
413
  if not selected_recipe:
 
472
  type="pil",
473
  height=350,
474
  )
475
+
476
+ detect_button = gr.Button("Analyze Fridge")
477
+ annotated_detection_preview = gr.Image(label="Annotated Detection Preview", height=300)
478
+ detection_payload_json_step1 = gr.JSON(label="Raw Detection Payload")
479
+
480
+ editable_ingredients = gr.Dataframe(
481
+ headers=["Ingredient", "Confidence"],
482
+ label="Detected Ingredients (editable)",
483
+ interactive=True,
484
+ )
485
+
486
+ detect_button.click(
487
+ fn=run_detection_only,
488
+ inputs=[image_input, user_id_box],
489
+ outputs=[annotated_detection_preview, detection_payload_json_step1, editable_ingredients],
490
+ )
491
+
492
 
493
  detection_json = gr.JSON(label="Detection payload")
494
  annotated_output = gr.Image(label="Annotated detection", height=350)