Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import gradio as gr
|
|
| 2 |
import os
|
| 3 |
import json
|
| 4 |
import requests
|
| 5 |
-
import
|
| 6 |
from difflib import get_close_matches
|
| 7 |
from functools import lru_cache
|
| 8 |
|
|
@@ -39,7 +39,7 @@ def normalize_food_name(name):
|
|
| 39 |
return mapping.get(name, name)
|
| 40 |
|
| 41 |
# =====================
|
| 42 |
-
# MATCH
|
| 43 |
# =====================
|
| 44 |
def find_food(name):
|
| 45 |
if name in NUTRITION_DB:
|
|
@@ -136,8 +136,9 @@ def analyze_image(image):
|
|
| 136 |
|
| 137 |
path = "temp.jpg"
|
| 138 |
|
| 139 |
-
# numpy → image
|
| 140 |
-
|
|
|
|
| 141 |
|
| 142 |
preds = detect(path)
|
| 143 |
|
|
@@ -180,7 +181,7 @@ def analyze_image(image):
|
|
| 180 |
# =====================
|
| 181 |
demo = gr.Interface(
|
| 182 |
fn=analyze_image,
|
| 183 |
-
inputs=gr.Image(type="numpy"), # ✅
|
| 184 |
outputs="text",
|
| 185 |
title="🍽️ AI Nutritionist",
|
| 186 |
description="Upload food image to get calories & macros"
|
|
|
|
| 2 |
import os
|
| 3 |
import json
|
| 4 |
import requests
|
| 5 |
+
from PIL import Image
|
| 6 |
from difflib import get_close_matches
|
| 7 |
from functools import lru_cache
|
| 8 |
|
|
|
|
| 39 |
return mapping.get(name, name)
|
| 40 |
|
| 41 |
# =====================
|
| 42 |
+
# FIND MATCH
|
| 43 |
# =====================
|
| 44 |
def find_food(name):
|
| 45 |
if name in NUTRITION_DB:
|
|
|
|
| 136 |
|
| 137 |
path = "temp.jpg"
|
| 138 |
|
| 139 |
+
# numpy → image (Pillow)
|
| 140 |
+
img = Image.fromarray(image)
|
| 141 |
+
img.save(path)
|
| 142 |
|
| 143 |
preds = detect(path)
|
| 144 |
|
|
|
|
| 181 |
# =====================
|
| 182 |
demo = gr.Interface(
|
| 183 |
fn=analyze_image,
|
| 184 |
+
inputs=gr.Image(type="numpy"), # ✅ correct
|
| 185 |
outputs="text",
|
| 186 |
title="🍽️ AI Nutritionist",
|
| 187 |
description="Upload food image to get calories & macros"
|