File size: 1,712 Bytes
27758e8
 
 
 
 
 
 
826c17e
 
27758e8
907d6fd
26c5af6
907d6fd
 
 
 
 
 
2f6cd1f
734bc31
3104922
97ef017
f4f30ca
97ef017
 
 
 
 
 
 
 
 
 
734bc31
97bd2a2
 
3104922
826c17e
3104922
826c17e
97ef017
3104922
826c17e
4c9b055
d89dbed
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

model1 = tf.keras.models.load_model("mnist.h5", compile=False)
model2 = from_pretrained_keras("keras-io/WGAN-GP")

title = "WGAN-GP"
description = "Image Generation(Fashion Mnist and Handwritten Digits) 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>
        """

def Predict(model, num_images):
      random_latent_vectors = tf.random.normal(shape=(int(num_images), 128))
      predictions = model(random_latent_vectors)
      num = ceil(sqrt(num_images))
      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
              images[i* 28 : (i+1)*28, j*28 : (j+1)*28] = predictions[n, :, :, 0]
              n += 1
      return images

def inference(num_images, Choose: str):
    if Choose == 'Fashion_mnist':
        result = Predict(model2, num_images)
    else:
        result = Predict(model1, num_images)
    return result

inputs = [gr.inputs.Number(label="number of images"), gr.inputs.Radio(['Fashion_mnist', 'Handwritten_digits_mnist'])]
outputs = gr.outputs.Image(label="Output Image")
examples = [[4,"Handwritten_digits_mnist"], [6,"Handwritten_digits_mnist"],[10,"Fashion_mnist"]]
gr.Interface(inference, inputs, outputs, title=title, description=description, article=article, examples=examples).launch()