Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,30 +1,31 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import tensorflow as tf
|
|
|
|
| 3 |
|
| 4 |
-
#
|
| 5 |
model_path = 'fruitquality-1.0.h5'
|
| 6 |
model = tf.keras.models.load_model(model_path)
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
def preprocess_image(image):
|
| 10 |
-
image = image.reshape(image, [300, 300])
|
| 11 |
-
image = image / 255.0 # Normalize if your model expects this
|
| 12 |
-
return image.numpy() # Return as numpy array
|
| 13 |
-
|
| 14 |
def predict(image):
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
return class_names[predicted_index]
|
| 24 |
|
|
|
|
| 25 |
iface = gr.Interface(fn=predict,
|
| 26 |
-
inputs=gr.
|
| 27 |
-
outputs=
|
| 28 |
title="Fruit Quality Classifier",
|
| 29 |
description="Upload an image of the fruit.")
|
| 30 |
|
|
|
|
| 1 |
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 |
model_path = 'fruitquality-1.0.h5'
|
| 7 |
model = tf.keras.models.load_model(model_path)
|
| 8 |
|
| 9 |
+
# Define the prediction function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
def predict(image):
|
| 11 |
+
# Preprocess the image here as needed
|
| 12 |
+
processed_image = tf.image.resize(image, (224, 224))
|
| 13 |
+
processed_image = processed_image / 255.0 # Normalize if necessary
|
| 14 |
+
processed_image = np.expand_dims(processed_image, axis=0) # Add batch dimension
|
| 15 |
+
|
| 16 |
+
predictions = model.predict(processed_image)
|
| 17 |
+
predicted_index = np.argmax(predictions, axis=1)[0]
|
| 18 |
+
|
| 19 |
+
# Define your class names
|
| 20 |
+
class_names = ["Fresh Peaches", "Fresh Pomegranates", "Fresh Strawberries",
|
| 21 |
+
"Rotten Peaches", "Rotten Pomegranates", "Rotten Strawberries"]
|
| 22 |
+
|
| 23 |
return class_names[predicted_index]
|
| 24 |
|
| 25 |
+
# Update Gradio Interface creation to match Gradio 2.x syntax
|
| 26 |
iface = gr.Interface(fn=predict,
|
| 27 |
+
inputs=gr.Image(shape=(224, 224)), # Corrected usage
|
| 28 |
+
outputs=gr.Text(),
|
| 29 |
title="Fruit Quality Classifier",
|
| 30 |
description="Upload an image of the fruit.")
|
| 31 |
|