Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,6 @@ import gradio as gr
|
|
| 2 |
import tensorflow as tf
|
| 3 |
import numpy as np
|
| 4 |
|
| 5 |
-
# Assuming you have the model loaded correctly as 'model'
|
| 6 |
def load_model():
|
| 7 |
model_path = 'fruitquality-1.0.h5'
|
| 8 |
model = tf.keras.models.load_model(model_path)
|
|
@@ -10,14 +9,14 @@ def load_model():
|
|
| 10 |
|
| 11 |
model = load_model()
|
| 12 |
|
| 13 |
-
# Define the prediction function
|
| 14 |
def predict(image):
|
| 15 |
-
image = image.reshape((-1, 300, 300, 3)) #
|
| 16 |
-
preds = model.predict(image)
|
| 17 |
-
labels = ['Fresh Peaches', 'Fresh Pomegranates', 'Fresh Strawberries',
|
| 18 |
-
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
# Update Gradio Interface creation to match Gradio 2.x syntax
|
| 21 |
iface = gr.Interface(fn=predict, inputs="image", outputs="label")
|
| 22 |
|
| 23 |
iface.launch()
|
|
|
|
| 2 |
import tensorflow as tf
|
| 3 |
import numpy as np
|
| 4 |
|
|
|
|
| 5 |
def load_model():
|
| 6 |
model_path = 'fruitquality-1.0.h5'
|
| 7 |
model = tf.keras.models.load_model(model_path)
|
|
|
|
| 9 |
|
| 10 |
model = load_model()
|
| 11 |
|
|
|
|
| 12 |
def predict(image):
|
| 13 |
+
image = image.reshape((-1, 300, 300, 3)) # Ensure image has the correct shape
|
| 14 |
+
preds = model.predict(image)[0] # Assuming single image prediction
|
| 15 |
+
labels = ['Fresh Peaches', 'Fresh Pomegranates', 'Fresh Strawberries',
|
| 16 |
+
'Rotten Peaches', 'Rotten Pomegranates', 'Rotten Strawberries']
|
| 17 |
+
# Format the predictions as a dictionary {'label': probability}
|
| 18 |
+
return {labels[i]: float(preds[i]) for i in range(len(labels))}
|
| 19 |
|
|
|
|
| 20 |
iface = gr.Interface(fn=predict, inputs="image", outputs="label")
|
| 21 |
|
| 22 |
iface.launch()
|