|
import torchvision.utils as vutils |
|
import torchvision.transforms as T |
|
from PIL import Image |
|
import gradio as gr |
|
import torch |
|
|
|
def generate_images(num_images, z_dim=100): |
|
|
|
noise = torch.randn(num_images, z_dim, 1, 1) |
|
|
|
|
|
generator.eval() |
|
with torch.no_grad(): |
|
fake_images = generator(noise).detach().cpu() |
|
|
|
|
|
img = vutils.make_grid(fake_images, padding=2, normalize=True).permute(1, 2, 0) |
|
|
|
img = img.permute(2,0,1) |
|
|
|
transform = T.ToPILImage() |
|
|
|
|
|
img = transform(img) |
|
|
|
return img |
|
|
|
|
|
batch_size = 16 |
|
z = torch.randn(batch_size, 100, 1, 1) |
|
fake_images = generator(z) |
|
|
|
|
|
|
|
|
|
out = gr.Image(type="pil",label = "Generated Dogs") |
|
inp = gr.Number(value=0, minimum=0, label="Enter number of Dogs to Generate (positive integer)") |
|
|
|
demo = gr.Interface(fn=generate_images,inputs = inp, outputs=out, allow_flagging="never") |
|
|
|
|
|
demo.launch(debug = True) |