Update app.py
Browse files
app.py
CHANGED
|
@@ -1,48 +1,36 @@
|
|
| 1 |
-
|
| 2 |
from PIL import Image
|
| 3 |
-
import
|
| 4 |
-
from torchvision import transforms
|
| 5 |
-
from huggingface_hub import hf_hub_download
|
| 6 |
|
| 7 |
# -----------------------------
|
| 8 |
-
# بارگذاری مدل
|
| 9 |
# -----------------------------
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
model_path
|
| 13 |
-
|
| 14 |
-
#
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
model = CodeFormer(pretrained=model_path, device=device)
|
| 19 |
|
| 20 |
# -----------------------------
|
| 21 |
-
# تابع ت
|
| 22 |
# -----------------------------
|
| 23 |
-
def
|
| 24 |
image = image.convert("RGB")
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
transforms.ToTensor()
|
| 28 |
-
])
|
| 29 |
-
img_tensor = transform(image).unsqueeze(0).to(device)
|
| 30 |
-
|
| 31 |
-
with torch.no_grad():
|
| 32 |
-
output_tensor = model.enhance(img_tensor, fidelity=0.8)
|
| 33 |
-
|
| 34 |
-
output_image = transforms.ToPILImage()(output_tensor.squeeze(0).cpu())
|
| 35 |
-
return output_image
|
| 36 |
|
| 37 |
# -----------------------------
|
| 38 |
-
# رابط Gradio
|
| 39 |
# -----------------------------
|
| 40 |
iface = gr.Interface(
|
| 41 |
-
fn=
|
| 42 |
inputs=gr.Image(type="pil"),
|
| 43 |
outputs=gr.Image(type="pil"),
|
| 44 |
-
title="
|
| 45 |
-
description="Upload your AnimeGAN output → get a modern cartoon with
|
| 46 |
)
|
| 47 |
|
| 48 |
iface.launch()
|
|
|
|
| 1 |
+
from gfpgan import GFPGANer
|
| 2 |
from PIL import Image
|
| 3 |
+
import gradio as gr
|
|
|
|
|
|
|
| 4 |
|
| 5 |
# -----------------------------
|
| 6 |
+
# بارگذاری مدل GFPGAN (عمومی)
|
| 7 |
# -----------------------------
|
| 8 |
+
# مدل به صورت خودکار از HF دانلود میشود و عمومی است
|
| 9 |
+
restorer = GFPGANer(
|
| 10 |
+
model_path=None, # None → مدل عمومی
|
| 11 |
+
upscale=1, # بزرگنمایی 1x
|
| 12 |
+
arch='clean', # معماری مدل
|
| 13 |
+
channel_multiplier=2,
|
| 14 |
+
bg_upsampler=None
|
| 15 |
+
)
|
|
|
|
| 16 |
|
| 17 |
# -----------------------------
|
| 18 |
+
# تابع ترمیم کارتونی
|
| 19 |
# -----------------------------
|
| 20 |
+
def restore_cartoon(image):
|
| 21 |
image = image.convert("RGB")
|
| 22 |
+
restored_image, _ = restorer.enhance(image, has_aligned=False)
|
| 23 |
+
return restored_image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
# -----------------------------
|
| 26 |
+
# رابط کاربری Gradio
|
| 27 |
# -----------------------------
|
| 28 |
iface = gr.Interface(
|
| 29 |
+
fn=restore_cartoon,
|
| 30 |
inputs=gr.Image(type="pil"),
|
| 31 |
outputs=gr.Image(type="pil"),
|
| 32 |
+
title="Cartoon Face Restorer",
|
| 33 |
+
description="Upload your AnimeGAN output → get a restored modern cartoon with face and background fixed."
|
| 34 |
)
|
| 35 |
|
| 36 |
iface.launch()
|