Update handler.py
Browse files- handler.py +15 -8
handler.py
CHANGED
@@ -10,14 +10,21 @@ class EndpointHandler:
|
|
10 |
self.model = CLIPModel.from_pretrained("dazpye/clip-image")
|
11 |
self.processor = CLIPProcessor.from_pretrained("dazpye/clip-image")
|
12 |
|
13 |
-
def _load_image(self,
|
14 |
-
"""
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
def __call__(self, data):
|
23 |
"""Main inference function Hugging Face expects."""
|
|
|
10 |
self.model = CLIPModel.from_pretrained("dazpye/clip-image")
|
11 |
self.processor = CLIPProcessor.from_pretrained("dazpye/clip-image")
|
12 |
|
13 |
+
def _load_image(self, image_url):
|
14 |
+
"""Fetches an image and ensures it is fully loaded."""
|
15 |
+
try:
|
16 |
+
print(f"Fetching image from: {image_url}")
|
17 |
+
response = requests.get(image_url, timeout=5)
|
18 |
+
print(f"HTTP Status Code: {response.status_code}")
|
19 |
+
|
20 |
+
if response.status_code == 200:
|
21 |
+
image_bytes = io.BytesIO(response.content) # Convert to bytes
|
22 |
+
return Image.open(image_bytes)
|
23 |
+
else:
|
24 |
+
print(f"❌ Failed to fetch image: HTTP {response.status_code}")
|
25 |
+
except Exception as e:
|
26 |
+
print(f"❌ Exception in image loading: {e}")
|
27 |
+
return None # Return None if image loading fails
|
28 |
|
29 |
def __call__(self, data):
|
30 |
"""Main inference function Hugging Face expects."""
|