Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -64,9 +64,9 @@ 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 |
if isinstance(image_input, str):
|
69 |
-
|
70 |
try:
|
71 |
response = requests.get(image_input)
|
72 |
response.raise_for_status() # Check for HTTP errors
|
@@ -75,8 +75,8 @@ def predict(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 |
-
|
79 |
-
|
80 |
|
81 |
# Try to load the image from a local file path
|
82 |
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
|
|
|
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):
|