Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
43 |
|
44 |
# Handle local file path image loading (Gradio File input)
|
45 |
elif isinstance(image, str) and os.path.isfile(image):
|
46 |
-
|
|
|
|
|
|
|
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 |
|