File size: 1,145 Bytes
789ee84
bc5e1ec
 
56d2483
789ee84
 
56d2483
789ee84
 
56d2483
789ee84
 
 
 
56d2483
789ee84
 
 
56d2483
789ee84
56d2483
789ee84
 
56d2483
789ee84
 
 
 
 
 
 
56d2483
 
789ee84
56d2483
789ee84
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
import gradio as gr
import torch
from PIL import Image
from torchvision.transforms import ToTensor, ToPILImage
from torchvision import models

# Load the R-ESRGAN Anime model (you need to set up this model properly)
model = torch.hub.load('xinntao/Real-ESRGAN', 'restorer', model='R-ESRGAN_Anime_X6')

def upscale_image(image, scale_factor):
    # Ensure image is in PIL format
    if not isinstance(image, Image.Image):
        image = Image.fromarray(image)

    # Upscale using the model
    with torch.no_grad():
        upscaled_image = model(image, scale=scale_factor)

    return upscaled_image

# Create Gradio interface
iface = gr.Interface(
    fn=upscale_image,
    inputs=[
        gr.inputs.Image(type="pil", label="Input Image"),
        gr.inputs.Slider(minimum=1, maximum=4, step=1, default=2, label="Scale Factor")
    ],
    outputs=gr.outputs.Image(type="pil", label="Upscaled Image"),
    title="R-ESRGAN Anime 6B Image Upscaler",
    description="Upload an image and select a scale factor to upscale the image using R-ESRGAN Anime 6B model."
)

# Launch the Gradio app
if __name__ == "__main__":
    iface.launch()