skella83 commited on
Commit
f895eaf
·
1 Parent(s): a094b1f

Upload 4 files

Browse files
RealESRGAN_x2plus.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:49fafd45f8fd7aa8d31ab2a22d14d91b536c34494a5cfe31eb5d89c2fa266abb
3
+ size 67061725
RealESRGAN_x4plus (1).pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4fa0d38905f75ac06eb49a7951b426670021be3018265fd191d2125df9d682f1
3
+ size 67040989
handler.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from base64 import b64encode, b64decode
2
+ from io import BytesIO
3
+ from pathlib import Path
4
+
5
+ import numpy as np
6
+ from basicsr.archs.rrdbnet_arch import RRDBNet
7
+ from PIL import Image
8
+ from realesrgan import RealESRGANer
9
+
10
+
11
+ class EndpointHandler:
12
+ def __init__(self, path=""):
13
+ model = RRDBNet(num_in_ch=3, num_out_ch=3)
14
+ self.upsampler = RealESRGANer(
15
+ scale=4,
16
+ model_path=str(Path(path) / "RealESRGAN_x4plus.pth"),
17
+ model=model,
18
+ tile=0,
19
+ pre_pad=0,
20
+ half=True,
21
+ )
22
+
23
+ def __call__(self, data):
24
+ """
25
+ Args:
26
+ data (:obj:):
27
+ includes the input data and the parameters for the inference.
28
+ Return:
29
+ A :obj:`dict`:. base64 encoded image
30
+ """
31
+ image = data.pop("inputs", data)
32
+
33
+ # This lets us pass local images as well while developing
34
+ if isinstance(image, str):
35
+ image = Image.open(BytesIO(b64decode(image)))
36
+ elif isinstance(image, bytes):
37
+ image = Image.open(BytesIO(image))
38
+
39
+ image = np.array(image)
40
+ image = image[:, :, ::-1] # RGB -> BGR
41
+ image, _ = self.upsampler.enhance(image, outscale=4)
42
+ image = image[:, :, ::-1] # BGR -> RGB
43
+ image = Image.fromarray(image)
44
+
45
+ # Turn output image into bytestr
46
+ buffered = BytesIO()
47
+ image.save(buffered, format="PNG")
48
+ img_bytes = b64encode(buffered.getvalue())
49
+ img_str = img_bytes.decode()
50
+
51
+ return {"image": img_str}
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ realesrgan==0.3.0