nateraw commited on
Commit
7d0d1dc
1 Parent(s): a3e0416

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -4
app.py CHANGED
@@ -1,10 +1,23 @@
1
  import gradio as gr
 
 
 
2
 
3
  from huggan.pytorch.pix2pix.modeling_pix2pix import GeneratorUNet
4
 
5
- model = GeneratorUNet.from_pretrained('huggan/pix2pix-edge2shoes')
 
 
 
 
 
 
 
6
 
7
- def dummy_fn(text):
8
- return "Looks like the model is loaded!"
 
 
 
9
 
10
- gr.Interface(dummy_fn, inputs='text', outputs='text').launch()
 
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
 
6
  from huggan.pytorch.pix2pix.modeling_pix2pix import GeneratorUNet
7
 
8
+ transform = Compose(
9
+ [
10
+ Resize((256, 256), Image.BICUBIC),
11
+ ToTensor(),
12
+ Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)),
13
+ ]
14
+ )
15
+ model = GeneratorUNet.from_pretrained('huggan/pix2pix-cityscapes')
16
 
17
+ def predict_fn(img):
18
+ inp = transform(img).unsqueeze(0)
19
+ out = model(inp)
20
+ save_image(out, 'out.png', normalize=True)
21
+ return 'out.png'
22
 
23
+ gr.Interface(predict_fn, inputs=gr.inputs.Image(type='pil'), outputs='image').launch()