File size: 1,440 Bytes
27758e8
 
 
 
 
 
 
 
 
4121dc0
907d6fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4121dc0
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
from huggingface_hub import from_pretrained_keras
import matplotlib.pyplot as plt
from math import sqrt, ceil
import tensorflow as tf
import gradio as gr
import numpy as np

model = from_pretrained_keras("IMvision12/WGAN-GP")

def create_digit_samples(num_images):
      random_latent_vectors = tf.random.normal(shape=(int(num_images), 128))
      predictions = model.predict(random_latent_vectors)
      num = ceil(sqrt(num_images))
      digit_images = np.zeros((28*num, 28*num), dtype=float)
      n = 0
      for i in range(num):
          for j in range(num):
              if n == num_images:
                  break
              digit_images[i* 28 : (i+1)*28, j*28 : (j+1)*28] = predictions[n, :, :, 0]
              n += 1
      return digit_images

title = "WGAN-GP"
description = "Image Generation Using WGAN"
article = """
<p style='text-align: center'>
            <a href='https://keras.io/examples/generative/wgan_gp/' target='_blank'>Keras Example given by A_K_Nain</a>
            <br>
            Space by Gitesh Chawda
        </p>
    """
inputs = gr.inputs.Number(label="number of images")
outputs = gr.outputs.Image(label="Predictions")

examples = [
            [4], 
            [7],
            [8],
            [2], 
            [10]
]


gr.Interface(create_digit_samples, inputs, outputs, title=title, examples=examples, description=description, article=article, analytics_enabled=False).launch(enable_queue=True)