Rainy commited on
Commit
c9728db
1 Parent(s): 7aa3008

:tada: first commit

Browse files
Files changed (3) hide show
  1. README.md +9 -9
  2. app.py +46 -0
  3. requirements.txt +1 -0
README.md CHANGED
@@ -1,13 +1,13 @@
1
  ---
2
- title: Real ESRGAN
3
- emoji: 👁
4
- colorFrom: blue
5
- colorTo: purple
6
  sdk: gradio
7
- sdk_version: 3.40.1
 
8
  app_file: app.py
9
- pinned: false
10
- license: openrail
11
  ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: Face Real ESRGAN 2x 4x 8x
3
+ emoji: 😻
4
+ colorFrom: green
5
+ colorTo: gray
6
  sdk: gradio
7
+ sdk_version: 3.34.0
8
+ python_version: 3.11.3
9
  app_file: app.py
10
+ pinned: true
11
+ license: apache-2.0
12
  ---
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces#reference
 
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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, size):
16
+ if size == '2x':
17
+ result = model2.predict(image.convert('RGB'))
18
+ elif size == '4x':
19
+ result = model4.predict(image.convert('RGB'))
20
+ else:
21
+ result = model8.predict(image.convert('RGB'))
22
+ if torch.cuda.is_available():
23
+ torch.cuda.empty_cache()
24
+ return result
25
+
26
+
27
+ title = "Face Real ESRGAN UpScale: 2x 4x 8x"
28
+ 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"
29
+ 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>"
30
+
31
+
32
+ gr.Interface(inference,
33
+ [gr.Image(type="pil"),
34
+ gr.Radio(['2x', '4x', '8x'],
35
+ type="value",
36
+ value='2x',
37
+ label='Resolution model')],
38
+ gr.Image(type="pil", label="Output"),
39
+ title=title,
40
+ description=description,
41
+ article=article,
42
+ examples=[['girl.jpeg', "2x"]],
43
+ allow_flagging='never',
44
+ cache_examples=False,
45
+ ).queue(concurrency_count=1, api_open=False).launch(show_api=False, show_error=True)
46
+
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ git+https://github.com/sberbank-ai/Real-ESRGAN.git