Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -86,6 +86,14 @@ def preprocess_image(image):
|
|
| 86 |
"""
|
| 87 |
Preprocess image for model prediction.
|
| 88 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
# Convert to RGB if necessary
|
| 90 |
if image.mode != 'RGB':
|
| 91 |
image = image.convert('RGB')
|
|
|
|
| 86 |
"""
|
| 87 |
Preprocess image for model prediction.
|
| 88 |
"""
|
| 89 |
+
# Handle different input types
|
| 90 |
+
if isinstance(image, str):
|
| 91 |
+
# If it's a file path or URL, load it
|
| 92 |
+
image = Image.open(image)
|
| 93 |
+
elif not isinstance(image, Image.Image):
|
| 94 |
+
# If it's a numpy array, convert to PIL
|
| 95 |
+
image = Image.fromarray(image)
|
| 96 |
+
|
| 97 |
# Convert to RGB if necessary
|
| 98 |
if image.mode != 'RGB':
|
| 99 |
image = image.convert('RGB')
|