Spaces:
Runtime error
Runtime error
Delete app.py
Browse files
app.py
DELETED
@@ -1,65 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import numpy as np
|
3 |
-
from torchvision.utils import save_image
|
4 |
-
import torch.nn as nn
|
5 |
-
import torch
|
6 |
-
import torchvision.datasets as datasets
|
7 |
-
import torchvision.transforms as T
|
8 |
-
from torch.utils.data import DataLoader, ConcatDataset
|
9 |
-
import torchvision.utils as vutils
|
10 |
-
import random
|
11 |
-
|
12 |
-
LATENT_VECTOR_DIM = 16 # latent vector dimension
|
13 |
-
|
14 |
-
class Generator_128(nn.Module):
|
15 |
-
def __init__(self, GPU_COUNT):
|
16 |
-
super(Generator_128, self).__init__()
|
17 |
-
self.GPU_COUNT = GPU_COUNT
|
18 |
-
self.main = nn.Sequential(
|
19 |
-
# LATENT_VECTOR_DIM x 1 x 1
|
20 |
-
nn.ConvTranspose2d(LATENT_VECTOR_DIM, 1024, 4, 1, 0, bias=False),
|
21 |
-
nn.BatchNorm2d(1024),
|
22 |
-
nn.ReLU(True),
|
23 |
-
nn.ConvTranspose2d(1024, 512, 4, 2, 1, bias=False),
|
24 |
-
nn.BatchNorm2d(512),
|
25 |
-
nn.ReLU(True),
|
26 |
-
nn.ConvTranspose2d(512, 256, 4, 2, 1, bias=False),
|
27 |
-
nn.BatchNorm2d(256),
|
28 |
-
nn.ReLU(True),
|
29 |
-
nn.ConvTranspose2d(256, 128, 4, 2, 1, bias=False),
|
30 |
-
nn.BatchNorm2d(128),
|
31 |
-
nn.ReLU(True),
|
32 |
-
nn.ConvTranspose2d(128,64, 4, 2, 1, bias=False),
|
33 |
-
nn.BatchNorm2d(64),
|
34 |
-
nn.ReLU(True),
|
35 |
-
nn.ConvTranspose2d(64,3, 4, 2, 1, bias=False),
|
36 |
-
nn.Tanh()
|
37 |
-
# 128 x 128 x 3
|
38 |
-
)
|
39 |
-
def forward(self, input):
|
40 |
-
return self.main(input)
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
trained_gen = Generator_128(0)
|
45 |
-
trained_gen.load_state_dict(torch.load("generator_epoch_1000.h5",map_location=torch.device('cpu')))
|
46 |
-
|
47 |
-
|
48 |
-
def predict(seed, pokemon_count):
|
49 |
-
torch.manual_seed(seed)
|
50 |
-
z = torch.randn(pokemon_count, LATENT_VECTOR_DIM, 1, 1)
|
51 |
-
punks = trained_gen(z)
|
52 |
-
save_image(punks, "pokemon.png", normalize=True)
|
53 |
-
return 'pokemon.png'
|
54 |
-
|
55 |
-
gr.Interface(
|
56 |
-
predict,
|
57 |
-
inputs=[
|
58 |
-
gr.Slider(0, 1000, label='Seed', default=42),
|
59 |
-
gr.Slider(1, 8, label='Number of pokemon', step=1, default=10),
|
60 |
-
],
|
61 |
-
outputs="image",
|
62 |
-
).launch()
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|