Commit
·
35b3b1d
1
Parent(s):
d70b1c6
base64 encoded images as input and output
Browse files- handler.py +6 -10
handler.py
CHANGED
|
@@ -29,21 +29,17 @@ class EndpointHandler():
|
|
| 29 |
A :obj:`dict`:. base64 encoded image
|
| 30 |
"""
|
| 31 |
inputs = data.pop("inputs", data)
|
|
|
|
| 32 |
# decode base64 image to PIL
|
| 33 |
-
|
| 34 |
-
image = Image.open(BytesIO(inputs['image'])).convert("RGB")
|
| 35 |
|
| 36 |
# run inference pipeline
|
| 37 |
-
#with autocast(device.type):
|
| 38 |
-
# image = self.pipe(inputs, guidance_scale=7.5)["sample"][0]
|
| 39 |
upscaled_image = self.pipe(prompt="", image = image).images[0]
|
| 40 |
|
| 41 |
-
return upscaled_image
|
| 42 |
-
|
| 43 |
# encode image as base 64
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
|
| 48 |
# postprocess the prediction
|
| 49 |
-
|
|
|
|
| 29 |
A :obj:`dict`:. base64 encoded image
|
| 30 |
"""
|
| 31 |
inputs = data.pop("inputs", data)
|
| 32 |
+
|
| 33 |
# decode base64 image to PIL
|
| 34 |
+
image = Image.open(BytesIO(base64.b64decode(inputs['image'])))
|
|
|
|
| 35 |
|
| 36 |
# run inference pipeline
|
|
|
|
|
|
|
| 37 |
upscaled_image = self.pipe(prompt="", image = image).images[0]
|
| 38 |
|
|
|
|
|
|
|
| 39 |
# encode image as base 64
|
| 40 |
+
buffered = BytesIO()
|
| 41 |
+
upscaled_image.save(buffered, format="JPEG")
|
| 42 |
+
img_str = base64.b64encode(buffered.getvalue())
|
| 43 |
|
| 44 |
# postprocess the prediction
|
| 45 |
+
return {"image": img_str.decode()}
|