# ----- Patch شروع ----- import sys import torchvision.transforms.functional as F # جایگزین functional_tensor با functional معمولی sys.modules['torchvision.transforms.functional_tensor'] = F # ----- Patch پایان ----- from gfpgan import GFPGANer from huggingface_hub import hf_hub_download from PIL import Image import gradio as gr # دانلود خودکار مدل GFPGAN model_path = hf_hub_download( repo_id="TencentARC/GFPGANv1", filename="GFPGANv1.pth" ) # بارگذاری Restorer restorer = GFPGANer( model_path=model_path, upscale=1, arch='clean', channel_multiplier=2, bg_upsampler=None ) # تابع ترمیم def restore_cartoon(image): image = image.convert("RGB") restored_image, _ = restorer.enhance(image, has_aligned=False) return restored_image # رابط کاربری Gradio iface = gr.Interface( fn=restore_cartoon, inputs=gr.Image(type="pil"), outputs=gr.Image(type="pil"), title="Cartoon Face Restorer", description="Upload your AnimeGAN cartoon → get a modern restored cartoon." ) iface.launch()