Spaces:
Runtime error
Runtime error
add new version
Browse files
README.md
CHANGED
|
@@ -4,6 +4,6 @@ emoji: 🐴
|
|
| 4 |
colorFrom: yellow
|
| 5 |
colorTo: orange
|
| 6 |
sdk: gradio
|
| 7 |
-
app_file:
|
| 8 |
pinned: false
|
| 9 |
---
|
|
|
|
| 4 |
colorFrom: yellow
|
| 5 |
colorTo: orange
|
| 6 |
sdk: gradio
|
| 7 |
+
app_file: app.py
|
| 8 |
pinned: false
|
| 9 |
---
|
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastai.vision.all import *
|
| 2 |
+
from fastai.basics import *
|
| 3 |
+
from upit.models.cyclegan import *
|
| 4 |
+
from upit.train.cyclegan import *
|
| 5 |
+
from upit.data.unpaired import *
|
| 6 |
+
import torchvision
|
| 7 |
+
import gradio as gr
|
| 8 |
+
|
| 9 |
+
dls = get_dls_from_hf("huggan/horse2zebra", load_size=286)
|
| 10 |
+
cycle_gan = CycleGAN.from_pretrained('tmabraham/horse2zebra_cyclegan')
|
| 11 |
+
|
| 12 |
+
totensor = torchvision.transforms.ToTensor()
|
| 13 |
+
normalize_fn = torchvision.transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
|
| 14 |
+
topilimage = torchvision.transforms.ToPILImage()
|
| 15 |
+
|
| 16 |
+
model = cycle_gan.G_B.cpu().eval()
|
| 17 |
+
def predict(input):
|
| 18 |
+
im = normalize_fn(totensor(input))
|
| 19 |
+
print(im.shape)
|
| 20 |
+
preds = model(im.unsqueeze(0))/2 + 0.5
|
| 21 |
+
print(preds.shape)
|
| 22 |
+
return topilimage(preds.squeeze(0).detach())
|
| 23 |
+
|
| 24 |
+
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'])
|
| 25 |
+
gr_interface.launch(inline=False,share=False)
|
horse.jpg
ADDED
|
requirements.txt
CHANGED
|
@@ -1,2 +1,3 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
torchvision
|
|
|
|
| 1 |
+
upit
|
| 2 |
+
gradio
|
| 3 |
torchvision
|