bijoymirza99 commited on
Commit
1fef300
1 Parent(s): be7da3b

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -77
app.py DELETED
@@ -1,77 +0,0 @@
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
- global model2
17
- global model4
18
- global model8
19
- if image is None:
20
- raise gr.Error("Image not uploaded")
21
-
22
- width, height = image.size
23
- if width >= 5000 or height >= 5000:
24
- raise gr.Error("The image is too large.")
25
-
26
- if torch.cuda.is_available():
27
- torch.cuda.empty_cache()
28
-
29
- if size == '2x':
30
- try:
31
- result = model2.predict(image.convert('RGB'))
32
- except torch.cuda.OutOfMemoryError as e:
33
- print(e)
34
- model2 = RealESRGAN(device, scale=2)
35
- model2.load_weights('weights/RealESRGAN_x2.pth', download=False)
36
- result = model2.predict(image.convert('RGB'))
37
- elif size == '4x':
38
- try:
39
- result = model4.predict(image.convert('RGB'))
40
- except torch.cuda.OutOfMemoryError as e:
41
- print(e)
42
- model4 = RealESRGAN(device, scale=4)
43
- model4.load_weights('weights/RealESRGAN_x4.pth', download=False)
44
- result = model2.predict(image.convert('RGB'))
45
- else:
46
- try:
47
- result = model8.predict(image.convert('RGB'))
48
- except torch.cuda.OutOfMemoryError as e:
49
- print(e)
50
- model8 = RealESRGAN(device, scale=8)
51
- model8.load_weights('weights/RealESRGAN_x8.pth', download=False)
52
- result = model2.predict(image.convert('RGB'))
53
-
54
- print(f"Image size ({device}): {size} ... OK")
55
- return result
56
-
57
-
58
- title = "Face Real ESRGAN UpScale: 2x 4x 8x"
59
- 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"
60
- 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><div>"
61
-
62
-
63
- gr.Interface(inference,
64
- [gr.Image(type="pil"),
65
- gr.Radio(['2x', '4x', '8x'],
66
- type="value",
67
- value='2x',
68
- label='Resolution model')],
69
- gr.Image(type="pil", label="Output"),
70
- title=title,
71
- description=description,
72
- article=article,
73
- examples=[['groot.jpeg', "2x"]],
74
- allow_flagging='never',
75
- cache_examples=False,
76
- ).queue(api_open=False).launch(show_error=True, show_api=False)
77
-