Update app.py
Browse files
app.py
CHANGED
|
@@ -1,38 +1,33 @@
|
|
| 1 |
-
# ----- Patch
|
| 2 |
import sys
|
| 3 |
import torchvision.transforms.functional as F
|
| 4 |
-
|
| 5 |
-
# جایگزین functional_tensor با functional معمولی
|
| 6 |
sys.modules['torchvision.transforms.functional_tensor'] = F
|
| 7 |
-
# -----
|
| 8 |
|
| 9 |
from gfpgan import GFPGANer
|
| 10 |
from huggingface_hub import hf_hub_download
|
| 11 |
from PIL import Image
|
| 12 |
import gradio as gr
|
| 13 |
|
| 14 |
-
# دانلود
|
| 15 |
model_path = hf_hub_download(
|
| 16 |
-
repo_id="
|
| 17 |
-
filename="GFPGANv1.pth"
|
| 18 |
)
|
| 19 |
|
| 20 |
-
# بارگذاری Restorer
|
| 21 |
restorer = GFPGANer(
|
| 22 |
model_path=model_path,
|
| 23 |
upscale=1,
|
| 24 |
-
arch='
|
| 25 |
channel_multiplier=2,
|
| 26 |
bg_upsampler=None
|
| 27 |
)
|
| 28 |
|
| 29 |
-
# تابع ترمیم
|
| 30 |
def restore_cartoon(image):
|
| 31 |
image = image.convert("RGB")
|
| 32 |
restored_image, _ = restorer.enhance(image, has_aligned=False)
|
| 33 |
return restored_image
|
| 34 |
|
| 35 |
-
# رابط کاربری Gradio
|
| 36 |
iface = gr.Interface(
|
| 37 |
fn=restore_cartoon,
|
| 38 |
inputs=gr.Image(type="pil"),
|
|
|
|
| 1 |
+
# ----- Patch برای torchvision -----
|
| 2 |
import sys
|
| 3 |
import torchvision.transforms.functional as F
|
|
|
|
|
|
|
| 4 |
sys.modules['torchvision.transforms.functional_tensor'] = F
|
| 5 |
+
# --------------------------------
|
| 6 |
|
| 7 |
from gfpgan import GFPGANer
|
| 8 |
from huggingface_hub import hf_hub_download
|
| 9 |
from PIL import Image
|
| 10 |
import gradio as gr
|
| 11 |
|
| 12 |
+
# دانلود مدل v1.4 (سازگار با arch='original')
|
| 13 |
model_path = hf_hub_download(
|
| 14 |
+
repo_id="leonelhs/gfpgan",
|
| 15 |
+
filename="GFPGANv1.4.pth"
|
| 16 |
)
|
| 17 |
|
|
|
|
| 18 |
restorer = GFPGANer(
|
| 19 |
model_path=model_path,
|
| 20 |
upscale=1,
|
| 21 |
+
arch='original', # 🔑 تغییر دادیم
|
| 22 |
channel_multiplier=2,
|
| 23 |
bg_upsampler=None
|
| 24 |
)
|
| 25 |
|
|
|
|
| 26 |
def restore_cartoon(image):
|
| 27 |
image = image.convert("RGB")
|
| 28 |
restored_image, _ = restorer.enhance(image, has_aligned=False)
|
| 29 |
return restored_image
|
| 30 |
|
|
|
|
| 31 |
iface = gr.Interface(
|
| 32 |
fn=restore_cartoon,
|
| 33 |
inputs=gr.Image(type="pil"),
|