doevent commited on
Commit
49f65e4
1 Parent(s): 98819ca

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from PIL import Image
3
+ import numpy as np
4
+ from realesrgan import RealESRGAN
5
+ import os
6
+ import gradio as gr
7
+ os.system("gdown https://drive.google.com/uc?id=1pG2S3sYvSaO0V0B8QPOl1RapPHpUGOaV -O RealESRGAN_x2.pth")
8
+ os.system("gdown https://drive.google.com/uc?id=1SGHdZAln4en65_NQeQY9UjchtkEF9f5F -O RealESRGAN_x4.pth")
9
+ os.system("gdown https://drive.google.com/uc?id=1mT9ewx86PSrc43b-ax47l1E2UzR7Ln4j -O RealESRGAN_x8.pth")
10
+
11
+ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
12
+ model2 = RealESRGAN(device, scale=2)
13
+ model2.load_weights('RealESRGAN_x2.pth')
14
+ model4 = RealESRGAN(device, scale=4)
15
+ model4.load_weights('RealESRGAN_x4.pth')
16
+ model8 = RealESRGAN(device, scale=8)
17
+ model8.load_weights('RealESRGAN_x8.pth')
18
+
19
+
20
+ def inference(image: Image, size: str) -> Image:
21
+ if size == '2x':
22
+ result = model2.predict(image.convert('RGB'))
23
+ elif size == '4x':
24
+ result = model4.predict(image.convert('RGB'))
25
+ else:
26
+ result = model8.predict(image.convert('RGB'))
27
+ return result
28
+
29
+
30
+ title = "Face Real ESRGAN: 2x 4x 8x"
31
+ description = "Increases the resolution of a photo. This model shows better results on faces compared to the original version."
32
+ article = ""
33
+
34
+ gr.Interface(inference,
35
+ [gr.inputs.Image(type="pil"),
36
+ gr.inputs.Radio(['2x', '4x', '8x'],
37
+ type="value",
38
+ default='2x',
39
+ label='Resolution model')],
40
+ gr.outputs.Image(type="pil", label="Output"),
41
+ title=title,
42
+ description=description,
43
+ article=article,
44
+ examples=[['groot.jpeg', "2x"]],
45
+ allow_flagging='never',
46
+ theme="default",
47
+ ).launch(enable_queue=True)