Pant0x commited on
Commit
561bd28
·
verified ·
1 Parent(s): 92c3f9f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -7,7 +7,7 @@ from PIL import Image
7
  MODEL_PATH = "model/best_food_model.keras"
8
  model = tf.keras.models.load_model(MODEL_PATH)
9
 
10
- # 2. Labels & Database (Make sure to include the full dictionary from previous turns)
11
  LABELS = [
12
  'apple_pie', 'baby_back_ribs', 'baklava', 'beef_carpaccio', 'beef_tartare', 'beet_salad', 'beignets',
13
  'bibimbap', 'bread_pudding', 'breakfast_burrito', 'bruschetta', 'caesar_salad', 'cannoli', 'caprese_salad',
@@ -24,6 +24,7 @@ LABELS = [
24
  'shrimp_and_grits', 'spaghetti_bolognese', 'spaghetti_carbonara', 'spring_rolls', 'steak', 'strawberry_shortcake',
25
  'sushi', 'tacos', 'takoyaki', 'tiramisu', 'tuna_tartare', 'waffles'
26
  ]
 
27
  NUTRITION_DB = {
28
  'apple_pie': {'cal': 237, 'protein': 1.9, 'carbs': 34.0, 'fat': 11.0},
29
  'baby_back_ribs': {'cal': 292, 'protein': 17.0, 'carbs': 0.0, 'fat': 24.0},
@@ -128,10 +129,11 @@ NUTRITION_DB = {
128
  'waffles': {'cal': 291, 'protein': 8.0, 'carbs': 33.0, 'fat': 14.0}
129
  }
130
 
 
131
  def predict_nutrition(img):
132
  if img is None:
133
  return None, "Please upload an image."
134
-
135
  # Preprocessing
136
  img = Image.fromarray(img).resize((224, 224))
137
  img_array = tf.keras.preprocessing.image.img_to_array(img)
@@ -165,7 +167,7 @@ def predict_nutrition(img):
165
 
166
  return confidences, nutri_markdown
167
 
168
- # 3. Enhanced Gradio UI
169
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
170
  gr.Markdown("# 🍎 Food-101 Deep Learning Classifier")
171
  gr.Markdown("Identify food items and see their nutritional breakdown instantly.")
@@ -176,11 +178,9 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
176
  submit_btn = gr.Button("Analyze Meal", variant="primary")
177
 
178
  with gr.Column(scale=1):
179
- # Output 1: Top 3 Confidence Chart
180
  output_chart = gr.Label(num_top_classes=3, label="Top 3 Predictions")
181
- # Output 2: Nutrition Table
182
  output_nutri = gr.Markdown(label="Nutrition Breakdown")
183
-
184
  submit_btn.click(
185
  fn=predict_nutrition,
186
  inputs=input_img,
 
7
  MODEL_PATH = "model/best_food_model.keras"
8
  model = tf.keras.models.load_model(MODEL_PATH)
9
 
10
+ # 2. Labels & Database
11
  LABELS = [
12
  'apple_pie', 'baby_back_ribs', 'baklava', 'beef_carpaccio', 'beef_tartare', 'beet_salad', 'beignets',
13
  'bibimbap', 'bread_pudding', 'breakfast_burrito', 'bruschetta', 'caesar_salad', 'cannoli', 'caprese_salad',
 
24
  'shrimp_and_grits', 'spaghetti_bolognese', 'spaghetti_carbonara', 'spring_rolls', 'steak', 'strawberry_shortcake',
25
  'sushi', 'tacos', 'takoyaki', 'tiramisu', 'tuna_tartare', 'waffles'
26
  ]
27
+
28
  NUTRITION_DB = {
29
  'apple_pie': {'cal': 237, 'protein': 1.9, 'carbs': 34.0, 'fat': 11.0},
30
  'baby_back_ribs': {'cal': 292, 'protein': 17.0, 'carbs': 0.0, 'fat': 24.0},
 
129
  'waffles': {'cal': 291, 'protein': 8.0, 'carbs': 33.0, 'fat': 14.0}
130
  }
131
 
132
+ # 3. Prediction Function
133
  def predict_nutrition(img):
134
  if img is None:
135
  return None, "Please upload an image."
136
+
137
  # Preprocessing
138
  img = Image.fromarray(img).resize((224, 224))
139
  img_array = tf.keras.preprocessing.image.img_to_array(img)
 
167
 
168
  return confidences, nutri_markdown
169
 
170
+ # 4. Enhanced Gradio UI
171
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
172
  gr.Markdown("# 🍎 Food-101 Deep Learning Classifier")
173
  gr.Markdown("Identify food items and see their nutritional breakdown instantly.")
 
178
  submit_btn = gr.Button("Analyze Meal", variant="primary")
179
 
180
  with gr.Column(scale=1):
 
181
  output_chart = gr.Label(num_top_classes=3, label="Top 3 Predictions")
 
182
  output_nutri = gr.Markdown(label="Nutrition Breakdown")
183
+
184
  submit_btn.click(
185
  fn=predict_nutrition,
186
  inputs=input_img,