Update handler.py
Browse files- handler.py +5 -2
handler.py
CHANGED
|
@@ -35,9 +35,12 @@ class EndpointHandler:
|
|
| 35 |
image_data = data.get("inputs")
|
| 36 |
if image_data is None:
|
| 37 |
return [{"error": "Missing 'inputs' key"}]
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
# Generation args
|
| 40 |
-
args = data.get("generation_args")
|
| 41 |
generation_args = self.default_args.copy()
|
| 42 |
for k in self.default_args:
|
| 43 |
if k in args and args[k] is not None:
|
|
@@ -46,7 +49,7 @@ class EndpointHandler:
|
|
| 46 |
# Decode base64 image
|
| 47 |
try:
|
| 48 |
image = Image.open(io.BytesIO(base64.b64decode(image_data))).convert("RGB")
|
| 49 |
-
image.thumbnail([
|
| 50 |
except Exception as e:
|
| 51 |
return [{"error": f"Image decoding failed: {str(e)}"}]
|
| 52 |
|
|
|
|
| 35 |
image_data = data.get("inputs")
|
| 36 |
if image_data is None:
|
| 37 |
return [{"error": "Missing 'inputs' key"}]
|
| 38 |
+
# Wake up function to restart the server
|
| 39 |
+
elif image_data == "wake":
|
| 40 |
+
return [{"status": "woken"}]
|
| 41 |
|
| 42 |
# Generation args
|
| 43 |
+
args = data.get("generation_args", {})
|
| 44 |
generation_args = self.default_args.copy()
|
| 45 |
for k in self.default_args:
|
| 46 |
if k in args and args[k] is not None:
|
|
|
|
| 49 |
# Decode base64 image
|
| 50 |
try:
|
| 51 |
image = Image.open(io.BytesIO(base64.b64decode(image_data))).convert("RGB")
|
| 52 |
+
image.thumbnail([512,512], Image.LANCZOS)
|
| 53 |
except Exception as e:
|
| 54 |
return [{"error": f"Image decoding failed: {str(e)}"}]
|
| 55 |
|