Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
#
|
7 |
-
model = tf.keras.
|
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
|
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)
|
|