Spaces:
Runtime error
Runtime error
Commit
·
734bc31
1
Parent(s):
d81477d
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,31 +17,43 @@ article = """
|
|
| 17 |
</p>
|
| 18 |
"""
|
| 19 |
|
| 20 |
-
def
|
| 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 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
</p>
|
| 18 |
"""
|
| 19 |
|
| 20 |
+
def generate_latent_points(latent_dim, n_samples):
|
| 21 |
+
random_latent_vectors = tf.random.normal(shape=(n_samples, latent_dim))
|
| 22 |
+
return
|
| 23 |
+
|
| 24 |
+
def create_digit_samples(digit, n_samples):
|
| 25 |
+
if digit in range(10):
|
| 26 |
+
latent_dim = 128
|
| 27 |
+
random_vector_labels = generate_latent_points(int(digit), latent_dim, int(n_samples))
|
| 28 |
+
examples = model.predict(random_vector_labels)
|
| 29 |
+
examples = examples * 255.0
|
| 30 |
+
size = ceil(sqrt(n_samples))
|
| 31 |
+
digit_images = np.zeros((28*size, 28*size), dtype=float)
|
| 32 |
+
n = 0
|
| 33 |
+
for i in range(size):
|
| 34 |
+
for j in range(size):
|
| 35 |
+
if n == n_samples:
|
| 36 |
+
break
|
| 37 |
+
digit_images[i* 28 : (i+1)*28, j*28 : (j+1)*28] = examples[n, :, :, 0]
|
| 38 |
+
n += 1
|
| 39 |
+
digit_images = (digit_images/127.5) -1
|
| 40 |
+
return digit_images
|
| 41 |
+
|
| 42 |
+
description = "Keras implementation for Conditional GAN to generate samples for specific digit of MNIST"
|
| 43 |
+
article = "Author:<a href=\"https://huggingface.co/rajrathi\"> Rajeshwar Rathi</a>; Based on the keras example by <a href=\"https://keras.io/examples/generative/conditional_gan/\">Sayak Paul</a>"
|
| 44 |
+
title = "Conditional GAN for MNIST"
|
| 45 |
+
|
| 46 |
+
examples = [[1, 10], [3, 5], [5, 15]]
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
iface = gr.Interface(
|
| 50 |
+
fn = create_digit_samples,
|
| 51 |
+
inputs = ["number", "number"],
|
| 52 |
+
outputs = ["image"],
|
| 53 |
+
examples = examples,
|
| 54 |
+
description = description,
|
| 55 |
+
title = title,
|
| 56 |
+
article = article
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
iface.launch()
|