Update app.py
Browse files
app.py
CHANGED
|
@@ -16,14 +16,32 @@ def analyze_food(image):
|
|
| 16 |
|
| 17 |
# Step 4: Estimate portion size
|
| 18 |
portion_size = estimate_portion_size(image)
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
# Gradio Interface
|
| 23 |
iface = gr.Interface(
|
| 24 |
fn=analyze_food,
|
| 25 |
inputs=gr.Image(type="pil"),
|
| 26 |
-
outputs="
|
| 27 |
title="Diet Nutrition Analyzer",
|
| 28 |
description="Upload an image of your food plate to analyze nutrition and portion size."
|
| 29 |
)
|
|
|
|
| 16 |
|
| 17 |
# Step 4: Estimate portion size
|
| 18 |
portion_size = estimate_portion_size(image)
|
| 19 |
+
|
| 20 |
+
# Format output
|
| 21 |
+
description = f"Detected {len(food_items)} food items: {', '.join(food_items)}.\n\n"
|
| 22 |
+
description += f"Portion size: {portion_size}.\n\n"
|
| 23 |
+
description += "Nutritional Information:\n"
|
| 24 |
+
|
| 25 |
+
for food, nutrients in nutrition_data.items():
|
| 26 |
+
if "Error" in nutrients:
|
| 27 |
+
description += f"- {food}: {nutrients['Error']}\n"
|
| 28 |
+
else:
|
| 29 |
+
description += (
|
| 30 |
+
f"- {food}:\n"
|
| 31 |
+
f" - Energy: {nutrients['Energy (kcal)']} kcal\n"
|
| 32 |
+
f" - Protein: {nutrients['Protein (g)']} g\n"
|
| 33 |
+
f" - Carbs: {nutrients['Carbs (g)']} g\n"
|
| 34 |
+
f" - Fiber: {nutrients['Fiber (g)']} g\n"
|
| 35 |
+
f" - Fat: {nutrients['Fat (g)']} g\n"
|
| 36 |
+
f" - Sugar: {nutrients['Sugar (g)']} g\n"
|
| 37 |
+
)
|
| 38 |
+
return description
|
| 39 |
|
| 40 |
# Gradio Interface
|
| 41 |
iface = gr.Interface(
|
| 42 |
fn=analyze_food,
|
| 43 |
inputs=gr.Image(type="pil"),
|
| 44 |
+
outputs="text",
|
| 45 |
title="Diet Nutrition Analyzer",
|
| 46 |
description="Upload an image of your food plate to analyze nutrition and portion size."
|
| 47 |
)
|