sam-brause
commited on
Commit
·
3988a1a
1
Parent(s):
6dbf008
try to fix image scope error
Browse files- .DS_Store +0 -0
- handler.py +6 -4
.DS_Store
CHANGED
|
Binary files a/.DS_Store and b/.DS_Store differ
|
|
|
handler.py
CHANGED
|
@@ -31,17 +31,19 @@ class EndpointHandler:
|
|
| 31 |
]
|
| 32 |
|
| 33 |
def __call__(self, data):
|
| 34 |
-
|
|
|
|
|
|
|
| 35 |
image = Image.open(io.BytesIO(data)).convert("RGB")
|
| 36 |
elif isinstance(data, dict) and "inputs" in data:
|
| 37 |
if isinstance(data["inputs"], bytes):
|
| 38 |
image = Image.open(io.BytesIO(data["inputs"])).convert("RGB")
|
| 39 |
-
# REMOVE the else block below. data["inputs"] is already bytes.
|
| 40 |
-
# else: # This branch is unnecessary and causes the error
|
| 41 |
-
# image = Image.open(io.BytesIO(data["inputs"].encode())).convert("RGB") # Remove .encode()
|
| 42 |
else:
|
| 43 |
raise ValueError("Unsupported input format")
|
| 44 |
|
|
|
|
|
|
|
|
|
|
| 45 |
image_tensor = self.transform(image).unsqueeze(0)
|
| 46 |
|
| 47 |
with torch.no_grad():
|
|
|
|
| 31 |
]
|
| 32 |
|
| 33 |
def __call__(self, data):
|
| 34 |
+
image = None # Initialize image to None
|
| 35 |
+
|
| 36 |
+
if isinstance(data, bytes):
|
| 37 |
image = Image.open(io.BytesIO(data)).convert("RGB")
|
| 38 |
elif isinstance(data, dict) and "inputs" in data:
|
| 39 |
if isinstance(data["inputs"], bytes):
|
| 40 |
image = Image.open(io.BytesIO(data["inputs"])).convert("RGB")
|
|
|
|
|
|
|
|
|
|
| 41 |
else:
|
| 42 |
raise ValueError("Unsupported input format")
|
| 43 |
|
| 44 |
+
if image is None: # Check if image was successfully loaded
|
| 45 |
+
raise ValueError("Could not load image from input data.")
|
| 46 |
+
|
| 47 |
image_tensor = self.transform(image).unsqueeze(0)
|
| 48 |
|
| 49 |
with torch.no_grad():
|