Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -45,11 +45,11 @@ def classify_waste(image):
|
|
| 45 |
|
| 46 |
if model is None:
|
| 47 |
print("Error: Model is None inside classify_waste.")
|
| 48 |
-
return
|
| 49 |
|
| 50 |
if image is None:
|
| 51 |
print("Error: Image is None - no valid image data received")
|
| 52 |
-
return
|
| 53 |
|
| 54 |
# Print image type and info for debugging
|
| 55 |
print(f"Image type: {type(image)}")
|
|
@@ -66,7 +66,7 @@ def classify_waste(image):
|
|
| 66 |
# Make sure the array has valid values
|
| 67 |
if image.size == 0:
|
| 68 |
print("Error: Empty numpy array")
|
| 69 |
-
return
|
| 70 |
|
| 71 |
# Ensure the array is uint8 for PIL
|
| 72 |
if image.dtype != np.uint8:
|
|
@@ -81,7 +81,7 @@ def classify_waste(image):
|
|
| 81 |
image = Image.fromarray(image)
|
| 82 |
else:
|
| 83 |
print(f"Unsupported image type: {type(image)}")
|
| 84 |
-
return
|
| 85 |
|
| 86 |
# Resize to match training dimensions
|
| 87 |
print(f"Resizing image to ({IMG_WIDTH}, {IMG_HEIGHT})")
|
|
@@ -111,16 +111,16 @@ def classify_waste(image):
|
|
| 111 |
print(f"Raw predictions: {predictions}")
|
| 112 |
|
| 113 |
# Format predictions in the way Gradio's Label component expects
|
| 114 |
-
|
| 115 |
-
result
|
| 116 |
-
print(f"
|
| 117 |
print("=== CLASSIFY_WASTE FUNCTION COMPLETED SUCCESSFULLY ===")
|
| 118 |
return result
|
| 119 |
|
| 120 |
except Exception as e:
|
| 121 |
print(f"Error during classification: {e}")
|
| 122 |
traceback.print_exc()
|
| 123 |
-
return
|
| 124 |
|
| 125 |
# --- Gradio Interface ---
|
| 126 |
if model is not None:
|
|
|
|
| 45 |
|
| 46 |
if model is None:
|
| 47 |
print("Error: Model is None inside classify_waste.")
|
| 48 |
+
return {"Error": 1.0}
|
| 49 |
|
| 50 |
if image is None:
|
| 51 |
print("Error: Image is None - no valid image data received")
|
| 52 |
+
return {"No image provided": 1.0}
|
| 53 |
|
| 54 |
# Print image type and info for debugging
|
| 55 |
print(f"Image type: {type(image)}")
|
|
|
|
| 66 |
# Make sure the array has valid values
|
| 67 |
if image.size == 0:
|
| 68 |
print("Error: Empty numpy array")
|
| 69 |
+
return {"Empty image data": 1.0}
|
| 70 |
|
| 71 |
# Ensure the array is uint8 for PIL
|
| 72 |
if image.dtype != np.uint8:
|
|
|
|
| 81 |
image = Image.fromarray(image)
|
| 82 |
else:
|
| 83 |
print(f"Unsupported image type: {type(image)}")
|
| 84 |
+
return {"Unsupported image format": 1.0}
|
| 85 |
|
| 86 |
# Resize to match training dimensions
|
| 87 |
print(f"Resizing image to ({IMG_WIDTH}, {IMG_HEIGHT})")
|
|
|
|
| 111 |
print(f"Raw predictions: {predictions}")
|
| 112 |
|
| 113 |
# Format predictions in the way Gradio's Label component expects
|
| 114 |
+
# Gradio Label component expects a dictionary with class names as keys and confidences as values
|
| 115 |
+
result = {CLASS_NAMES[i]: float(predictions[i]) for i in range(len(CLASS_NAMES))}
|
| 116 |
+
print(f"Predictions as dictionary: {result}")
|
| 117 |
print("=== CLASSIFY_WASTE FUNCTION COMPLETED SUCCESSFULLY ===")
|
| 118 |
return result
|
| 119 |
|
| 120 |
except Exception as e:
|
| 121 |
print(f"Error during classification: {e}")
|
| 122 |
traceback.print_exc()
|
| 123 |
+
return {"Error: " + str(e): 1.0}
|
| 124 |
|
| 125 |
# --- Gradio Interface ---
|
| 126 |
if model is not None:
|