File size: 771 Bytes
558f167
 
 
 
 
 
83410ac
 
 
 
 
61b86db
 
558f167
 
3761b39
558f167
 
 
 
a9149b6
558f167
 
948c35d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import gradio as gr
from torchvision.transforms import Compose, Resize, ToTensor, Normalize
from PIL import Image
from torchvision.utils import save_image
from huggan.pytorch.pix2pix.modeling_pix2pix import GeneratorUNet

def predict_fn(img):
    inp = transform(img).unsqueeze(0)
    out = model(inp)
    save_image(out, 'out.png', normalize=True)
    return 'out.png'


transform = Compose(
    [
        Resize((1024, 1024), Image.BICUBIC),
        ToTensor(),
        Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)),
    ]
)

model = GeneratorUNet.from_pretrained('huggan/pix2pix-uavid-15')

gr.Interface(predict_fn, inputs=gr.inputs.Image(type='pil'), outputs='image', examples=[['image1.jpg'], ['image2.jpg'], ['sample.jpg'], ['sample2.jpg'], ['sample3.jpg']]).launch()