File size: 1,356 Bytes
d5f2bf5 d2b9628 d63c6cd d2bf1cc d5f2bf5 6ca20c1 d5f2bf5 e174116 2bc17ff d5f2bf5 c082871 8bba89b d5f2bf5 7654258 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import torch
from torch import nn
import gradio as gr
class Generator(nn.Module):
# Refer to the link below for explanations about nc, nz, and ngf
# https://pytorch.org/tutorials/beginner/dcgan_faces_tutorial.html#inputs
def __init__(self, nc=4, nz=100, ngf=64):
super(Generator, self).__init__()
self.network = nn.Sequential(
nn.ConvTranspose2d(nz, ngf * 4, 3, 1, 0, bias=False),
nn.BatchNorm2d(ngf * 4),
nn.ReLU(True),
nn.ConvTranspose2d(ngf * 4, ngf * 2, 3, 2, 1, bias=False),
nn.BatchNorm2d(ngf * 2),
nn.ReLU(True),
nn.ConvTranspose2d(ngf * 2, ngf, 4, 2, 0, bias=False),
nn.BatchNorm2d(ngf),
nn.ReLU(True),
nn.ConvTranspose2d(ngf, nc, 4, 2, 1, bias=False),
nn.Tanh(),
)
def forward(self, input):
output = self.network(input)
return output
def predict(body, hair, top, bottom):
name = str(body) + str(hair) + str(top) + str(bottom)
return name
gr.Interface(
predict,
inputs=[
gr.Radio(["human", "alien"]),
gr.Slider(0, 5, label='Hair', step=1, default=0),
gr.Slider(0, 3, label='Top', step=1, default=0),
gr.Slider(0, 4, label='Bottom', step=1, default=0)
],
outputs="image",
live=True,
).launch()
|