Rishav-ctrl commited on
Commit
966ff33
·
verified ·
1 Parent(s): 588f11b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -5
app.py CHANGED
@@ -3,8 +3,8 @@ import tensorflow as tf
3
  from tensorflow.keras.preprocessing import image
4
  import numpy as np
5
 
6
- # Load your trained model (SavedModel format)
7
- model = tf.keras.models.load_model("waste_sort_model") # Loading from SavedModel directory
8
  class_names = ["Non-Recyclable", "Recyclable"]
9
 
10
  def classify_image(img):
@@ -13,7 +13,7 @@ def classify_image(img):
13
  img_array = np.array(img) / 255.0 # Normalize pixel values
14
  img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
15
 
16
- predictions = model.predict(img_array)
17
  predicted_class = class_names[np.argmax(predictions)]
18
  return f"Prediction: {predicted_class}"
19
 
@@ -28,5 +28,4 @@ interface = gr.Interface(
28
 
29
  # Launch the Gradio app
30
  if __name__ == "__main__":
31
- interface.launch()
32
-
 
3
  from tensorflow.keras.preprocessing import image
4
  import numpy as np
5
 
6
+ # Use TFSMLayer to load the SavedModel
7
+ model = tf.keras.layers.experimental.preprocessing.TFSMLayer("waste_sort_model", call_endpoint="serving_default")
8
  class_names = ["Non-Recyclable", "Recyclable"]
9
 
10
  def classify_image(img):
 
13
  img_array = np.array(img) / 255.0 # Normalize pixel values
14
  img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
15
 
16
+ predictions = model(img_array)
17
  predicted_class = class_names[np.argmax(predictions)]
18
  return f"Prediction: {predicted_class}"
19
 
 
28
 
29
  # Launch the Gradio app
30
  if __name__ == "__main__":
31
+ interface.launch(share=True)