Update handler.py
Browse files- handler.py +2 -6
handler.py
CHANGED
|
@@ -2,6 +2,7 @@ from image_gen_aux import UpscaleWithModel
|
|
| 2 |
import numpy as np
|
| 3 |
from PIL import Image
|
| 4 |
from io import BytesIO
|
|
|
|
| 5 |
|
| 6 |
|
| 7 |
class EndpointHandler():
|
|
@@ -12,13 +13,8 @@ class EndpointHandler():
|
|
| 12 |
img = data.pop("inputs", data)
|
| 13 |
output = self.upscaler(img, tiling=True, tile_width=768, tile_height=768, overlap=8)
|
| 14 |
|
| 15 |
-
output = output.reconstruction.data.squeeze().float().cpu().clamp_(0, 1).numpy()
|
| 16 |
-
output = np.moveaxis(output, source=0, destination=-1)
|
| 17 |
-
output = (output * 255.0).round().astype(np.uint8)
|
| 18 |
-
|
| 19 |
-
img = Image.fromarray(output)
|
| 20 |
buffered = BytesIO()
|
| 21 |
-
|
| 22 |
img_str = base64.b64encode(buffered.getvalue())
|
| 23 |
|
| 24 |
return img_str.decode()
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
from PIL import Image
|
| 4 |
from io import BytesIO
|
| 5 |
+
import base64
|
| 6 |
|
| 7 |
|
| 8 |
class EndpointHandler():
|
|
|
|
| 13 |
img = data.pop("inputs", data)
|
| 14 |
output = self.upscaler(img, tiling=True, tile_width=768, tile_height=768, overlap=8)
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
buffered = BytesIO()
|
| 17 |
+
output.save(buffered, format="JPEG")
|
| 18 |
img_str = base64.b64encode(buffered.getvalue())
|
| 19 |
|
| 20 |
return img_str.decode()
|