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