import gradio as gr import torch from PIL import Image from realesrgan import RealESRGAN device = torch.device("cuda" if torch.cuda.is_available() else "cpu") # حمّل النموذج ووزنه (يُنزَّل تلقائياً أول مرة) model = RealESRGAN(device, scale=4) model.load_weights("RealESRGAN_x4plus.pth", download=True) def upscale(img: Image.Image) -> Image.Image: return model.predict(img) demo = gr.Interface( fn=upscale, inputs=gr.Image(type="pil", label="Upload image"), outputs=gr.Image(type="pil", label="Upscaled ×4"), title="Upscayl-Web", description="Open-source image upscaler powered by Real-ESRGAN (×4).", ) if __name__ == "__main__": demo.launch(server_name="0.0.0.0", server_port=7860)