Spaces:
Runtime error
Runtime error
Ahsen Khaliq
commited on
Commit
·
e94169e
1
Parent(s):
4fb7b35
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
import torchvision
|
| 5 |
+
use_gpu = True if torch.cuda.is_available() else False
|
| 6 |
+
|
| 7 |
+
model = torch.hub.load('facebookresearch/pytorch_GAN_zoo:hub', 'DCGAN', pretrained=True, useGPU=use_gpu)
|
| 8 |
+
|
| 9 |
+
def dcgan(num_images):
|
| 10 |
+
noise, _ = model.buildNoiseData(num_images)
|
| 11 |
+
with torch.no_grad():
|
| 12 |
+
generated_images = model.test(noise)
|
| 13 |
+
plt.imshow(torchvision.utils.make_grid(generated_images).permute(1, 2, 0).cpu().numpy())
|
| 14 |
+
plt.axis("off")
|
| 15 |
+
return plt
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
inputs = gr.inputs.Number(label="number of images")
|
| 19 |
+
outputs = gr.outputs.Image(label="Output Image")
|
| 20 |
+
|
| 21 |
+
title = "DCGAN"
|
| 22 |
+
description = "demo for DCGAN. To use it, simply add the number of images to generate or click on the examples. Read more below."
|
| 23 |
+
article = "<p style='text-align: center'><a href='https://arxiv.org/abs/1511.06434'>Unsupervised Representation Learning with Deep Convolutional Generative Adversarial Networks</a> | <a href='https://github.com/facebookresearch/pytorch_GAN_zoo/blob/master/models/DCGAN.py'>Github Repo</a></p>"
|
| 24 |
+
examples = [
|
| 25 |
+
[1],
|
| 26 |
+
[2],
|
| 27 |
+
[3],
|
| 28 |
+
[4],
|
| 29 |
+
[64]
|
| 30 |
+
]
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
gr.Interface(dcgan, inputs, outputs, title=title, description=description, article=article, analytics_enabled=False, examples=examples).launch(debug=True)
|