Spaces:
Runtime error
Runtime error
mehdiabruee
commited on
Commit
•
6041fbb
1
Parent(s):
98b6e99
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
"""app.ipynb
|
3 |
+
|
4 |
+
Automatically generated by Colaboratory.
|
5 |
+
|
6 |
+
Original file is located at
|
7 |
+
https://colab.research.google.com/drive/13tu6v1reMxLATyBwle-BgpQrql9p4nqn
|
8 |
+
"""
|
9 |
+
|
10 |
+
from fastai.vision.all import *
|
11 |
+
from fastai.basics import *
|
12 |
+
from upit.models.cyclegan import *
|
13 |
+
from upit.train.cyclegan import *
|
14 |
+
from upit.data.unpaired import *
|
15 |
+
import torchvision
|
16 |
+
import gradio as gr
|
17 |
+
|
18 |
+
#dls = get_dls_from_hf("huggan/horse2zebra", load_size=286)
|
19 |
+
cycle_gan = CycleGAN.from_pretrained('mehdiabruee/HW4_1')
|
20 |
+
|
21 |
+
totensor = torchvision.transforms.ToTensor()
|
22 |
+
normalize_fn = torchvision.transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
|
23 |
+
topilimage = torchvision.transforms.ToPILImage()
|
24 |
+
|
25 |
+
#model = cycle_gan.G_B.cpu().eval()
|
26 |
+
model = cycle_gan.G_B.cpu().eval()
|
27 |
+
def predict(input):
|
28 |
+
im = normalize_fn(totensor(input))
|
29 |
+
print(im.shape)
|
30 |
+
preds = model(im.unsqueeze(0))/2 + 0.5
|
31 |
+
print(preds.shape)
|
32 |
+
return topilimage(preds.squeeze(0).detach())
|
33 |
+
|
34 |
+
gr_interface = gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(256, 256)), outputs="image", title='Horse-to-Zebra CycleGAN with UPIT', description='[This](https://huggingface.co/tmabraham/horse2zebra_cyclegan) CycleGAN model trained on [this dataset](https://huggingface.co/datasets/huggan/horse2zebra), using the [UPIT package](https://github.com/tmabraham/UPIT)', examples=['horse.jpg'])
|
35 |
+
gr_interface.launch(inline=False,share=False)
|