IMvision12 commited on
Commit
734bc31
·
1 Parent(s): d81477d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -28
app.py CHANGED
@@ -17,31 +17,43 @@ article = """
17
  </p>
18
  """
19
 
20
- def Predict(num_images):
21
- random_latent_vectors = tf.random.normal(shape=(int(num_images), 128))
22
- predictions = model.predict(random_latent_vectors)
23
- num = ceil(sqrt(num_images))
24
- images = np.zeros((28*num, 28*num), dtype=float)
25
- n = 0
26
- for i in range(num):
27
- for j in range(num):
28
- if n == num_images:
29
- break
30
- images[i* 28 : (i+1)*28, j*28 : (j+1)*28] = predictions[n, :, :, 0]
31
- n += 1
32
- return images
33
-
34
-
35
- inputs = gr.inputs.Number(label="number of images")
36
- outputs = gr.outputs.Image(label="Predictions")
37
-
38
- examples = [
39
- [10],
40
- [7],
41
- [1],
42
- [3],
43
- [5]
44
- ]
45
-
46
-
47
- gr.Interface(Predict, inputs, outputs, article=article, title=title, description=description, examples=examples, analytics_enabled=False).launch(enable_queue=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
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()