jays009 commited on
Commit
ee2271a
·
verified ·
1 Parent(s): 871b5a8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -4
app.py CHANGED
@@ -36,16 +36,27 @@ transform = transforms.Compose([
36
  # Prediction function
37
  def process_image(image, image_url=None):
38
  try:
 
 
 
 
39
  # Handle URL-based image loading
40
  if image_url:
41
- response = requests.get(image_url)
42
- image = Image.open(BytesIO(response.content))
 
 
 
 
43
 
44
  # Handle local file path image loading (Gradio File input)
45
  elif isinstance(image, str) and os.path.isfile(image):
46
- image = Image.open(image)
 
 
 
47
 
48
- # Validate image
49
  if not isinstance(image, Image.Image):
50
  return "Invalid image format received."
51
 
 
36
  # Prediction function
37
  def process_image(image, image_url=None):
38
  try:
39
+ # Ensure that the image is not None
40
+ if image is None and not image_url:
41
+ return "No image or URL provided."
42
+
43
  # Handle URL-based image loading
44
  if image_url:
45
+ try:
46
+ response = requests.get(image_url)
47
+ response.raise_for_status() # Raise an error if the request fails
48
+ image = Image.open(BytesIO(response.content))
49
+ except Exception as e:
50
+ return f"Error fetching image from URL: {e}"
51
 
52
  # Handle local file path image loading (Gradio File input)
53
  elif isinstance(image, str) and os.path.isfile(image):
54
+ try:
55
+ image = Image.open(image)
56
+ except Exception as e:
57
+ return f"Error loading image from local path: {e}"
58
 
59
+ # Validate that the image is loaded correctly
60
  if not isinstance(image, Image.Image):
61
  return "Invalid image format received."
62