Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,59 +1,48 @@
|
|
1 |
-
import gradio as gr
|
2 |
import torch
|
3 |
-
from
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
-
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
-
def bsrgan_inference(
|
9 |
-
image: gr.inputs.Image = None,
|
10 |
-
model_path: gr.inputs.Dropdown = 'kadirnar/bsrgan',
|
11 |
-
):
|
12 |
-
"""
|
13 |
-
BSRGAN inference function
|
14 |
-
Args:
|
15 |
-
image: Input image
|
16 |
-
model_path: Path to the model
|
17 |
-
Returns:
|
18 |
-
Rendered image
|
19 |
-
"""
|
20 |
-
device = 'cuda:0' if torch.cuda.is_available() else 'cpu'
|
21 |
-
model = BSRGAN(model_path, device=device, hf_model=True)
|
22 |
-
pred = model.predict(img_path=image)
|
23 |
-
return pred
|
24 |
-
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
label="Model",
|
30 |
-
choices=[
|
31 |
-
"kadirnar/bsrgan",
|
32 |
-
"kadirnar/BSRGANx2",
|
33 |
-
"kadirnar/RRDB_PSNR_x4",
|
34 |
-
"kadirnar/RRDB_ESRGAN_x4",
|
35 |
-
"kadirnar/DF2K",
|
36 |
-
"kadirnar/DPED",
|
37 |
-
"kadirnar/DF2K_JPEG",
|
38 |
-
],
|
39 |
-
default="kadirnar/bsrgan",
|
40 |
-
),
|
41 |
-
]
|
42 |
|
43 |
-
outputs = gr.outputs.Image(type="filepath", label="Output Image")
|
44 |
-
title = "BSRGAN: Designing a Practical Degradation Model for Deep Blind Image Super-Resolution."
|
45 |
-
description = "BSRGAN for Deep Blind Image Super-Resolution model aims to design a practical degradation model for deep blind image super-resolution by considering the deterioration of image quality over time. It uses deep learning methods to predict the deterioration of image quality and to assist in the re-creation of images at higher resolution using these predictions."
|
46 |
-
examples = [["butterfly.jpg", "kadirnar/bsrgan"]]
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
52 |
title=title,
|
53 |
description=description,
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
theme=
|
58 |
-
|
59 |
-
|
|
|
|
|
1 |
import torch
|
2 |
+
from PIL import Image
|
3 |
+
from RealESRGAN import RealESRGAN
|
4 |
+
import gradio as gr
|
5 |
+
|
6 |
+
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
7 |
+
model2 = RealESRGAN(device, scale=2)
|
8 |
+
model2.load_weights('weights/RealESRGAN_x2.pth', download=True)
|
9 |
+
model4 = RealESRGAN(device, scale=4)
|
10 |
+
model4.load_weights('weights/RealESRGAN_x4.pth', download=True)
|
11 |
+
model8 = RealESRGAN(device, scale=8)
|
12 |
+
model8.load_weights('weights/RealESRGAN_x8.pth', download=True)
|
13 |
+
|
14 |
|
15 |
+
def inference(image: Image, size: str) -> Image:
|
16 |
+
try:
|
17 |
+
if size == '2x':
|
18 |
+
result = model2.predict(image.convert('RGB'))
|
19 |
+
elif size == '4x':
|
20 |
+
result = model4.predict(image.convert('RGB'))
|
21 |
+
else:
|
22 |
+
result = model8.predict(image.convert('RGB'))
|
23 |
+
except Exception as e:
|
24 |
+
print(e)
|
25 |
+
raise gr.Error(str(e))
|
26 |
+
return result
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
+
title = "Face Real ESRGAN: 2x 4x 8x"
|
30 |
+
description = "This is an unofficial demo for Real-ESRGAN. Scales the resolution of a photo. This model shows better results on faces compared to the original version.<br>Telegram BOT: https://t.me/restoration_photo_bot"
|
31 |
+
article = "<div style='text-align: center;'>Twitter <a href='https://twitter.com/DoEvent' target='_blank'>Max Skobeev</a> | <a href='https://huggingface.co/sberbank-ai/Real-ESRGAN' target='_blank'>Model card</a> <center><img src='https://visitor-badge.glitch.me/badge?page_id=max_skobeev_face_esrgan' alt='visitor badge'></center></div>"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
|
|
|
|
|
|
|
|
33 |
|
34 |
+
gr.Interface(inference,
|
35 |
+
[gr.Image(type="pil"),
|
36 |
+
gr.Radio(['2x', '4x', '8x'],
|
37 |
+
type="value",
|
38 |
+
value='2x',
|
39 |
+
label='Resolution model')],
|
40 |
+
gr.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 |
+
cache_examples=False,
|
48 |
+
).queue().launch(show_error=True)
|