rishab1090 commited on
Commit
4ff2b06
·
verified ·
1 Parent(s): dd7315c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
2
  import os
3
  import json
4
  import requests
5
- import cv2
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 file
140
- cv2.imwrite(path, image)
 
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"), # ✅ FIXED
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"