Update app.py
Browse files
app.py
CHANGED
|
@@ -100,55 +100,48 @@ def render_progress(pct: float, label: str = "") -> str:
|
|
| 100 |
<div style="font-size:12px;opacity:.8;margin-top:4px;">{label} {pct:.1f}%</div>'''
|
| 101 |
|
| 102 |
def build_rrdb(scale: int, num_block: int):
|
| 103 |
-
return
|
| 104 |
-
|
| 105 |
|
| 106 |
-
def
|
| 107 |
-
|
| 108 |
-
os.makedirs(wdir, exist_ok=True)
|
| 109 |
-
return wdir
|
| 110 |
-
|
| 111 |
-
# βββββββββββββββββββββββββββββββββββββββββββββ
|
| 112 |
-
# Real-ESRGAN (CPU only)
|
| 113 |
-
# βββββββββββββββββββββββββββββββββββββββββββββ
|
| 114 |
-
def get_realesrganer(model_id: str, scale: int, tile: int, half: bool, device: str = "cpu") -> RealESRGANer:
|
| 115 |
wdir = _weights_dir()
|
|
|
|
| 116 |
if model_id == "x4plus":
|
| 117 |
-
model = build_rrdb(scale=4, num_block=23)
|
| 118 |
-
|
|
|
|
| 119 |
model_path = os.path.join(wdir, "RealESRGAN_x4plus.pth")
|
| 120 |
-
dni_weight = None
|
| 121 |
elif model_id == "x4plus-anime":
|
| 122 |
-
model = build_rrdb(scale=4, num_block=6)
|
| 123 |
-
|
|
|
|
| 124 |
model_path = os.path.join(wdir, "RealESRGAN_x4plus_anime_6B.pth")
|
| 125 |
-
dni_weight = None
|
| 126 |
elif model_id == "x2plus":
|
| 127 |
-
model = build_rrdb(scale=2, num_block=23)
|
| 128 |
-
|
|
|
|
| 129 |
model_path = os.path.join(wdir, "RealESRGAN_x2plus.pth")
|
| 130 |
-
dni_weight = None
|
| 131 |
else:
|
| 132 |
raise ValueError(f"Unknown model_id: {model_id}")
|
| 133 |
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
|
|
|
|
|
|
| 138 |
|
| 139 |
-
|
| 140 |
-
upsampler = RealESRGANer(
|
| 141 |
scale=netscale,
|
| 142 |
model_path=model_path,
|
| 143 |
-
dni_weight=dni_weight,
|
| 144 |
model=model,
|
| 145 |
-
tile=tile
|
| 146 |
tile_pad=10,
|
| 147 |
-
pre_pad=
|
| 148 |
-
half=
|
| 149 |
-
|
| 150 |
)
|
| 151 |
-
return upsampler
|
| 152 |
|
| 153 |
# βββββββββββββββββββββββββββββββββββββββββββββ
|
| 154 |
# Step 2: Sources + Processing (batch click)
|
|
|
|
| 100 |
<div style="font-size:12px;opacity:.8;margin-top:4px;">{label} {pct:.1f}%</div>'''
|
| 101 |
|
| 102 |
def build_rrdb(scale: int, num_block: int):
|
| 103 |
+
return RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64,
|
| 104 |
+
num_block=num_block, num_grow_ch=32, scale=scale)
|
| 105 |
|
| 106 |
+
def get_realesrganer(model_id: str, scale: int, tile: int,
|
| 107 |
+
half: bool, device: str = "cpu") -> RealESRGANer:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
wdir = _weights_dir()
|
| 109 |
+
|
| 110 |
if model_id == "x4plus":
|
| 111 |
+
model = build_rrdb(scale=4, num_block=23)
|
| 112 |
+
netscale = 4
|
| 113 |
+
url = "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth"
|
| 114 |
model_path = os.path.join(wdir, "RealESRGAN_x4plus.pth")
|
|
|
|
| 115 |
elif model_id == "x4plus-anime":
|
| 116 |
+
model = build_rrdb(scale=4, num_block=6)
|
| 117 |
+
netscale = 4
|
| 118 |
+
url = "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth"
|
| 119 |
model_path = os.path.join(wdir, "RealESRGAN_x4plus_anime_6B.pth")
|
|
|
|
| 120 |
elif model_id == "x2plus":
|
| 121 |
+
model = build_rrdb(scale=2, num_block=23)
|
| 122 |
+
netscale = 2
|
| 123 |
+
url = "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.1/RealESRGAN_x2plus.pth"
|
| 124 |
model_path = os.path.join(wdir, "RealESRGAN_x2plus.pth")
|
|
|
|
| 125 |
else:
|
| 126 |
raise ValueError(f"Unknown model_id: {model_id}")
|
| 127 |
|
| 128 |
+
if not os.path.isfile(model_path):
|
| 129 |
+
load_file_from_url(url=url, model_dir=wdir, progress=True)
|
| 130 |
+
|
| 131 |
+
# auto device
|
| 132 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 133 |
+
half = half and device == "cuda"
|
| 134 |
|
| 135 |
+
return RealESRGANer(
|
|
|
|
| 136 |
scale=netscale,
|
| 137 |
model_path=model_path,
|
|
|
|
| 138 |
model=model,
|
| 139 |
+
tile=tile,
|
| 140 |
tile_pad=10,
|
| 141 |
+
pre_pad=0,
|
| 142 |
+
half=half,
|
| 143 |
+
device=device,
|
| 144 |
)
|
|
|
|
| 145 |
|
| 146 |
# βββββββββββββββββββββββββββββββββββββββββββββ
|
| 147 |
# Step 2: Sources + Processing (batch click)
|