Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,6 +18,11 @@ def predict_image(image):
|
|
| 18 |
Process the uploaded image and return the top 3 predictions.
|
| 19 |
"""
|
| 20 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
# Preprocess the image
|
| 22 |
image = image.resize((224, 224)) # ResNet152 expects 224x224 input
|
| 23 |
image_array = img_to_array(image)
|
|
@@ -36,6 +41,7 @@ def predict_image(image):
|
|
| 36 |
return {"Error": str(e)}
|
| 37 |
|
| 38 |
# Create the Gradio interface
|
|
|
|
| 39 |
interface = gr.Interface(
|
| 40 |
fn=predict_image,
|
| 41 |
inputs=gr.Image(type="pil"), # Accepts an image input
|
|
@@ -44,6 +50,16 @@ interface = gr.Interface(
|
|
| 44 |
description="Upload an image, and the model will predict what's in the image.",
|
| 45 |
examples=["dog.jpg", "cat.jpg"], # Example images for users to test
|
| 46 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
# Launch the Gradio app
|
| 49 |
if __name__ == "__main__":
|
|
|
|
| 18 |
Process the uploaded image and return the top 3 predictions.
|
| 19 |
"""
|
| 20 |
try:
|
| 21 |
+
# Decode the base64 image string back to a PIL.Image object
|
| 22 |
+
image_data = base64.b64decode(image)
|
| 23 |
+
image = Image.open(BytesIO(image_data))
|
| 24 |
+
image = image.convert("RGB") # Ensure RGB format
|
| 25 |
+
|
| 26 |
# Preprocess the image
|
| 27 |
image = image.resize((224, 224)) # ResNet152 expects 224x224 input
|
| 28 |
image_array = img_to_array(image)
|
|
|
|
| 41 |
return {"Error": str(e)}
|
| 42 |
|
| 43 |
# Create the Gradio interface
|
| 44 |
+
"""
|
| 45 |
interface = gr.Interface(
|
| 46 |
fn=predict_image,
|
| 47 |
inputs=gr.Image(type="pil"), # Accepts an image input
|
|
|
|
| 50 |
description="Upload an image, and the model will predict what's in the image.",
|
| 51 |
examples=["dog.jpg", "cat.jpg"], # Example images for users to test
|
| 52 |
)
|
| 53 |
+
"""
|
| 54 |
+
|
| 55 |
+
interface = gr.Interface(
|
| 56 |
+
fn=predict_image,
|
| 57 |
+
inputs=gr.Textbox(label="Base64 Image String"), # Accepts base64-encoded string
|
| 58 |
+
outputs=gr.Label(num_top_classes=3), # Shows top 3 predictions with confidence
|
| 59 |
+
title="ResNet152 Image Classifier",
|
| 60 |
+
description="Upload an image as a Base64 string, and the model will predict what's in the image.",
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
|
| 64 |
# Launch the Gradio app
|
| 65 |
if __name__ == "__main__":
|