jays009 commited on
Commit
06728b1
·
verified ·
1 Parent(s): 5649d80

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -8
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) and image.startswith("http"):
69
- try:
70
- response = requests.get(image)
71
- image = Image.open(BytesIO(response.content))
72
- print(f"Fetched image from URL: {image}")
73
- except Exception as e:
74
- print(f"Error fetching image from URL: {e}")
75
- return json.dumps({"error": f"Error fetching image from URL: {e}"})
 
 
 
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):