Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,23 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
2 |
|
3 |
from huggan.pytorch.pix2pix.modeling_pix2pix import GeneratorUNet
|
4 |
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
def
|
8 |
-
|
|
|
|
|
|
|
9 |
|
10 |
-
gr.Interface(
|
|
|
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()
|