nateraw commited on
Commit
c806357
·
1 Parent(s): 656c6eb

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ from huggingface_hub import hf_hub_download
10
+ import gradio as gr
11
+
12
+ model = RRDBNet(num_in_ch=3, num_out_ch=3)
13
+ upsampler = RealESRGANer(
14
+ scale=4,
15
+ model_path=hf_hub_download('nateraw/real-esrgan', 'RealESRGAN_x4plus.pth'),
16
+ model=model,
17
+ tile=0,
18
+ pre_pad=0,
19
+ half=True,
20
+ )
21
+
22
+ def upsample(image):
23
+ # image = np.array(image)
24
+ image = image[:, :, ::-1] # RGB -> BGR
25
+ image, _ = self.upsampler.enhance(image, outscale=4)
26
+ image = image[:, :, ::-1] # BGR -> RGB
27
+ image = Image.fromarray(image)
28
+ return image
29
+
30
+ interface = gr.Interface(
31
+ upsample,
32
+ inputs=["image"],
33
+ outputs=["image"]
34
+ )
35
+
36
+ if __name__ == '__main__':
37
+ interface.launch()