Commit
·
4fa2b44
1
Parent(s):
af3699e
Update handler.py
Browse files- handler.py +5 -19
handler.py
CHANGED
|
@@ -27,29 +27,15 @@ class EndpointHandler():
|
|
| 27 |
self.pipe = self.pipe.to(device)
|
| 28 |
|
| 29 |
|
| 30 |
-
def __call__(self,
|
| 31 |
"""
|
| 32 |
Args:
|
| 33 |
-
|
| 34 |
Return:
|
| 35 |
A :obj:`dict`:. base64 encoded image
|
| 36 |
"""
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
logger.info(f"Printing image {inputs['image']}")
|
| 40 |
-
|
| 41 |
-
# decode base64 image to PIL
|
| 42 |
-
decoded_image = Image.open(BytesIO(base64.b64decode(inputs['image'])))
|
| 43 |
-
logger.info(f"Printing loaded image into library {decoded_image}")
|
| 44 |
-
|
| 45 |
-
# run inference pipeline
|
| 46 |
-
with autocast(device.type):
|
| 47 |
-
upscaled_image = self.pipe(prompt="", image = decoded_image).images[0]
|
| 48 |
-
|
| 49 |
-
# encode image as base 64
|
| 50 |
-
buffered = BytesIO()
|
| 51 |
-
upscaled_image.save(buffered, format="JPEG")
|
| 52 |
-
img_str = base64.b64encode(buffered.getvalue())
|
| 53 |
|
| 54 |
# postprocess the prediction
|
| 55 |
-
return {"image":
|
|
|
|
| 27 |
self.pipe = self.pipe.to(device)
|
| 28 |
|
| 29 |
|
| 30 |
+
def __call__(self, *args, **kwargs) -> List[Dict[str, Any]]:
|
| 31 |
"""
|
| 32 |
Args:
|
| 33 |
+
image (:obj:`string`)
|
| 34 |
Return:
|
| 35 |
A :obj:`dict`:. base64 encoded image
|
| 36 |
"""
|
| 37 |
+
print(args)
|
| 38 |
+
print(kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
# postprocess the prediction
|
| 41 |
+
return {"image": "nothing"}
|