Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -65,14 +65,17 @@ def predict(image):
|
|
65 |
return json.dumps({"error": f"Error decoding base64 image: {e}"})
|
66 |
|
67 |
# Try to fetch the image from a URL
|
68 |
-
elif isinstance(image, str)
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
76 |
|
77 |
# Try to load the image from a local file path
|
78 |
elif isinstance(image, str) and os.path.isfile(image):
|
|
|
65 |
return json.dumps({"error": f"Error decoding base64 image: {e}"})
|
66 |
|
67 |
# Try to fetch the image from a URL
|
68 |
+
elif isinstance(image, str):
|
69 |
+
if image.startswith("http://") or image.startswith("https://"):
|
70 |
+
try:
|
71 |
+
response = requests.get(image)
|
72 |
+
image = Image.open(BytesIO(response.content))
|
73 |
+
print(f"Fetched image from URL: {image}")
|
74 |
+
except Exception as e:
|
75 |
+
print(f"Error fetching image from URL: {e}")
|
76 |
+
return json.dumps({"error": f"Error fetching image from URL: {e}"})
|
77 |
+
else:
|
78 |
+
return json.dumps({"error": "Invalid URL format. Please provide a valid URL starting with 'http://' or 'https://'."})
|
79 |
|
80 |
# Try to load the image from a local file path
|
81 |
elif isinstance(image, str) and os.path.isfile(image):
|