Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,21 +9,17 @@ def predict(img):
|
|
| 9 |
try:
|
| 10 |
# Create the image object
|
| 11 |
img = PILImage.create(img)
|
| 12 |
-
|
| 13 |
# Get predictions from the model
|
| 14 |
pred, pred_idx, probs = learn.predict(img)
|
| 15 |
-
|
| 16 |
# Fetch the labels dynamically from the model's vocabulary
|
| 17 |
labels = learn.dls.vocab
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
return {labels[i]: f"{probs[i]*100:.2f}%" for i in range(len(labels))}
|
| 21 |
except Exception as e:
|
| 22 |
# Log the exception and return it as an error message
|
| 23 |
print(f"An error occurred: {e}")
|
| 24 |
return {"error": str(e)}
|
| 25 |
|
| 26 |
-
|
| 27 |
# Define the Gradio interface
|
| 28 |
title = "Interior Design Classifier"
|
| 29 |
description = "Upload an image of an interior design and get a prediction of the design style."
|
|
|
|
| 9 |
try:
|
| 10 |
# Create the image object
|
| 11 |
img = PILImage.create(img)
|
|
|
|
| 12 |
# Get predictions from the model
|
| 13 |
pred, pred_idx, probs = learn.predict(img)
|
|
|
|
| 14 |
# Fetch the labels dynamically from the model's vocabulary
|
| 15 |
labels = learn.dls.vocab
|
| 16 |
+
# Ensure probabilities are floats
|
| 17 |
+
return {labels[i]: {float(probs[i]) for i in range(len(labels))}
|
|
|
|
| 18 |
except Exception as e:
|
| 19 |
# Log the exception and return it as an error message
|
| 20 |
print(f"An error occurred: {e}")
|
| 21 |
return {"error": str(e)}
|
| 22 |
|
|
|
|
| 23 |
# Define the Gradio interface
|
| 24 |
title = "Interior Design Classifier"
|
| 25 |
description = "Upload an image of an interior design and get a prediction of the design style."
|