jays009 commited on
Commit
9eebef2
·
verified ·
1 Parent(s): 06728b1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -12
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
- # 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):
 
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):