Update app.py
Browse files
app.py
CHANGED
|
@@ -11,7 +11,7 @@ model = EfficientNetV2L(weights="imagenet")
|
|
| 11 |
|
| 12 |
def predict_image(image):
|
| 13 |
"""
|
| 14 |
-
Process the uploaded image and return the top 5 predictions.
|
| 15 |
"""
|
| 16 |
try:
|
| 17 |
# Preprocess the image
|
|
@@ -24,12 +24,12 @@ def predict_image(image):
|
|
| 24 |
predictions = model.predict(image_array)
|
| 25 |
decoded_predictions = decode_predictions(predictions, top=5)[0]
|
| 26 |
|
| 27 |
-
# Format predictions as a
|
| 28 |
-
results =
|
| 29 |
return results
|
| 30 |
|
| 31 |
except Exception as e:
|
| 32 |
-
return
|
| 33 |
|
| 34 |
# Create the Gradio interface
|
| 35 |
interface = gr.Interface(
|
|
@@ -38,7 +38,7 @@ interface = gr.Interface(
|
|
| 38 |
outputs=gr.Label(num_top_classes=2), # Shows top 5 predictions with confidence
|
| 39 |
title="Image Classifier",
|
| 40 |
description="Upload an image, and the model will predict what's in the image with higher accuracy.",
|
| 41 |
-
|
| 42 |
)
|
| 43 |
|
| 44 |
# Launch the Gradio app
|
|
|
|
| 11 |
|
| 12 |
def predict_image(image):
|
| 13 |
"""
|
| 14 |
+
Process the uploaded image and return the top 5 predictions as a list.
|
| 15 |
"""
|
| 16 |
try:
|
| 17 |
# Preprocess the image
|
|
|
|
| 24 |
predictions = model.predict(image_array)
|
| 25 |
decoded_predictions = decode_predictions(predictions, top=5)[0]
|
| 26 |
|
| 27 |
+
# Format predictions as a list of tuples (label, confidence)
|
| 28 |
+
results = [(label, float(confidence)) for _, label, confidence in decoded_predictions]
|
| 29 |
return results
|
| 30 |
|
| 31 |
except Exception as e:
|
| 32 |
+
return [("Error", str(e))]
|
| 33 |
|
| 34 |
# Create the Gradio interface
|
| 35 |
interface = gr.Interface(
|
|
|
|
| 38 |
outputs=gr.Label(num_top_classes=2), # Shows top 5 predictions with confidence
|
| 39 |
title="Image Classifier",
|
| 40 |
description="Upload an image, and the model will predict what's in the image with higher accuracy.",
|
| 41 |
+
|
| 42 |
)
|
| 43 |
|
| 44 |
# Launch the Gradio app
|