Pant0x commited on
Commit
f439d1d
·
verified ·
1 Parent(s): 97735de

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -8
app.py CHANGED
@@ -1,22 +1,32 @@
1
  import gradio as gr
2
  import os
3
-
4
- # Force Keras 2 behavior before importing tensorflow
5
  os.environ["TF_USE_LEGACY_KERAS"] = "1"
6
 
 
7
  import tensorflow as tf
 
8
  import numpy as np
9
  from PIL import Image
10
 
11
- # Use the legacy loader if you are on TF 2.16+
12
- try:
13
- import tf_keras as keras
14
- except ImportError:
15
- from tensorflow import keras
16
-
17
  MODEL_PATH = "model/FOOD CAL MODEL.h5"
18
  model = keras.models.load_model(MODEL_PATH)
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  # 2. Labels & Database (Make sure to include the full dictionary from previous turns)
21
  LABELS = [
22
  'apple_pie', 'baby_back_ribs', 'baklava', 'beef_carpaccio', 'beef_tartare', 'beet_salad', 'beignets',
 
1
  import gradio as gr
2
  import os
3
+ # Force legacy Keras
 
4
  os.environ["TF_USE_LEGACY_KERAS"] = "1"
5
 
6
+ import gradio as gr
7
  import tensorflow as tf
8
+ import tf_keras as keras # Use this instead of tf.keras
9
  import numpy as np
10
  from PIL import Image
11
 
12
+ # 1. Load your model using the tf_keras loader
 
 
 
 
 
13
  MODEL_PATH = "model/FOOD CAL MODEL.h5"
14
  model = keras.models.load_model(MODEL_PATH)
15
 
16
+ # ... (rest of your labels and NUTRITION_DB here) ...
17
+
18
+ def predict_nutrition(img):
19
+ if img is None:
20
+ return None, "Please upload an image."
21
+
22
+ # Preprocessing
23
+ img = Image.fromarray(img).resize((224, 224))
24
+ img_array = keras.preprocessing.image.img_to_array(img)
25
+ img_array = np.expand_dims(img_array, axis=0) / 255.0
26
+
27
+ # Prediction
28
+ prediction = model.predict(img_array)[0]
29
+
30
  # 2. Labels & Database (Make sure to include the full dictionary from previous turns)
31
  LABELS = [
32
  'apple_pie', 'baby_back_ribs', 'baklava', 'beef_carpaccio', 'beef_tartare', 'beet_salad', 'beignets',