Guldeniz commited on
Commit
3135855
1 Parent(s): 8522f0a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from torchvision.transforms import Compose, Resize, ToTensor, Normalize
3
+ from PIL import Image
4
+ from torchvision.utils import save_image
5
+ from huggan.pytorch.pix2pix.modeling_pix2pix import GeneratorUNet
6
+ 6
7
+ transform = Compose(
8
+ [
9
+ Resize((256, 256), Image.BICUBIC),
10
+ ToTensor(),
11
+ Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)),
12
+ ]
13
+ )
14
+ model = GeneratorUNet.from_pretrained('Guldeniz/pix2pix_maps')
15
+
16
+ def predict_fn(img):
17
+ inp = transform(img).unsqueeze(0)
18
+ out = model(inp)
19
+ save_image(out, 'out.png', normalize=True)
20
+ return 'out.png'
21
+
22
+ gr.Interface(predict_fn, inputs=gr.inputs.Image(type='pil'), outputs='image', examples=[['img.png'], ['real.jpeg'], ['real2.jpg']]).launch()