Update app.py
Browse files
app.py
CHANGED
|
@@ -6,21 +6,25 @@ from realesrgan import RealESRGANer
|
|
| 6 |
from basicsr.archs.rrdbnet_arch import RRDBNet
|
| 7 |
from huggingface_hub import hf_hub_download
|
| 8 |
|
| 9 |
-
# دانلود مدل
|
| 10 |
model_path = hf_hub_download(
|
| 11 |
-
repo_id="
|
| 12 |
filename="RealESRGAN_x4plus.pth"
|
| 13 |
)
|
| 14 |
|
| 15 |
-
# تعریف معماری RRDBNet (
|
| 16 |
model = RRDBNet(
|
| 17 |
-
num_in_ch=3,
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
)
|
| 20 |
|
| 21 |
# لود مدل
|
| 22 |
upsampler = RealESRGANer(
|
| 23 |
-
scale=
|
| 24 |
model_path=model_path,
|
| 25 |
model=model,
|
| 26 |
tile=0,
|
|
@@ -31,15 +35,15 @@ upsampler = RealESRGANer(
|
|
| 31 |
|
| 32 |
def upscale_image(img: Image.Image):
|
| 33 |
img = img.convert("RGB")
|
| 34 |
-
output, _ = upsampler.enhance(np.array(img), outscale=
|
| 35 |
return Image.fromarray(output)
|
| 36 |
|
| 37 |
demo = gr.Interface(
|
| 38 |
fn=upscale_image,
|
| 39 |
inputs=gr.Image(type="pil"),
|
| 40 |
outputs="image",
|
| 41 |
-
title="Real-ESRGAN
|
| 42 |
-
description="افزایش کیفیت تصویر
|
| 43 |
)
|
| 44 |
|
| 45 |
if __name__ == "__main__":
|
|
|
|
| 6 |
from basicsr.archs.rrdbnet_arch import RRDBNet
|
| 7 |
from huggingface_hub import hf_hub_download
|
| 8 |
|
| 9 |
+
# دانلود مدل x4
|
| 10 |
model_path = hf_hub_download(
|
| 11 |
+
repo_id="dtarnow/UPscaler",
|
| 12 |
filename="RealESRGAN_x4plus.pth"
|
| 13 |
)
|
| 14 |
|
| 15 |
+
# تعریف معماری RRDBNet (x4)
|
| 16 |
model = RRDBNet(
|
| 17 |
+
num_in_ch=3,
|
| 18 |
+
num_out_ch=3,
|
| 19 |
+
num_feat=64,
|
| 20 |
+
num_block=23,
|
| 21 |
+
num_grow_ch=32,
|
| 22 |
+
scale=4
|
| 23 |
)
|
| 24 |
|
| 25 |
# لود مدل
|
| 26 |
upsampler = RealESRGANer(
|
| 27 |
+
scale=4,
|
| 28 |
model_path=model_path,
|
| 29 |
model=model,
|
| 30 |
tile=0,
|
|
|
|
| 35 |
|
| 36 |
def upscale_image(img: Image.Image):
|
| 37 |
img = img.convert("RGB")
|
| 38 |
+
output, _ = upsampler.enhance(np.array(img), outscale=4)
|
| 39 |
return Image.fromarray(output)
|
| 40 |
|
| 41 |
demo = gr.Interface(
|
| 42 |
fn=upscale_image,
|
| 43 |
inputs=gr.Image(type="pil"),
|
| 44 |
outputs="image",
|
| 45 |
+
title="Real-ESRGAN x4plus",
|
| 46 |
+
description="افزایش کیفیت تصویر (Upscale ×4)"
|
| 47 |
)
|
| 48 |
|
| 49 |
if __name__ == "__main__":
|