last
Browse files
app.py
CHANGED
@@ -5,7 +5,6 @@ import gradio as gr
|
|
5 |
import os
|
6 |
import spaces
|
7 |
|
8 |
-
# Kiểm tra và cấu hình GPU
|
9 |
if torch.cuda.is_available():
|
10 |
print(f"CUDA is available. GPU: {torch.cuda.get_device_name(0)}")
|
11 |
device = torch.device("cuda")
|
@@ -13,7 +12,6 @@ else:
|
|
13 |
print("CUDA is not available. Using CPU.")
|
14 |
device = torch.device("cpu")
|
15 |
|
16 |
-
# Lazy loading cho các mô hình
|
17 |
class LazyRealESRGAN:
|
18 |
def __init__(self, device, scale):
|
19 |
self.device = device
|
@@ -33,7 +31,6 @@ model2 = LazyRealESRGAN(device, scale=2)
|
|
33 |
model4 = LazyRealESRGAN(device, scale=4)
|
34 |
model8 = LazyRealESRGAN(device, scale=8)
|
35 |
|
36 |
-
# Hàm inference chính
|
37 |
@spaces.GPU
|
38 |
def inference(image, size):
|
39 |
if image is None:
|
@@ -60,12 +57,11 @@ def inference(image, size):
|
|
60 |
except Exception as e:
|
61 |
raise gr.Error(f"An error occurred: {str(e)}")
|
62 |
|
63 |
-
# Cấu hình giao diện Gradio
|
64 |
title = "Face Real ESRGAN UpScale: 2x 4x 8x"
|
65 |
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."
|
66 |
-
#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>"
|
67 |
|
68 |
-
|
|
|
69 |
iface = gr.Interface(
|
70 |
inference,
|
71 |
[
|
@@ -75,11 +71,10 @@ iface = gr.Interface(
|
|
75 |
gr.Image(type="pil", label="Output"),
|
76 |
title=title,
|
77 |
description=description,
|
78 |
-
#examples=[["groot.jpeg", "2x"]],
|
79 |
flagging_mode="never",
|
80 |
cache_examples=True
|
81 |
)
|
82 |
|
83 |
-
|
84 |
if __name__ == "__main__":
|
85 |
iface.launch(debug=True, show_error=True)
|
|
|
5 |
import os
|
6 |
import spaces
|
7 |
|
|
|
8 |
if torch.cuda.is_available():
|
9 |
print(f"CUDA is available. GPU: {torch.cuda.get_device_name(0)}")
|
10 |
device = torch.device("cuda")
|
|
|
12 |
print("CUDA is not available. Using CPU.")
|
13 |
device = torch.device("cpu")
|
14 |
|
|
|
15 |
class LazyRealESRGAN:
|
16 |
def __init__(self, device, scale):
|
17 |
self.device = device
|
|
|
31 |
model4 = LazyRealESRGAN(device, scale=4)
|
32 |
model8 = LazyRealESRGAN(device, scale=8)
|
33 |
|
|
|
34 |
@spaces.GPU
|
35 |
def inference(image, size):
|
36 |
if image is None:
|
|
|
57 |
except Exception as e:
|
58 |
raise gr.Error(f"An error occurred: {str(e)}")
|
59 |
|
|
|
60 |
title = "Face Real ESRGAN UpScale: 2x 4x 8x"
|
61 |
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."
|
|
|
62 |
|
63 |
+
|
64 |
+
|
65 |
iface = gr.Interface(
|
66 |
inference,
|
67 |
[
|
|
|
71 |
gr.Image(type="pil", label="Output"),
|
72 |
title=title,
|
73 |
description=description,
|
|
|
74 |
flagging_mode="never",
|
75 |
cache_examples=True
|
76 |
)
|
77 |
|
78 |
+
|
79 |
if __name__ == "__main__":
|
80 |
iface.launch(debug=True, show_error=True)
|