File size: 1,717 Bytes
27758e8
 
 
 
 
 
 
826c17e
 
27758e8
907d6fd
 
 
 
 
 
 
 
2f6cd1f
734bc31
826c17e
7eabb4f
 
 
 
734bc31
7eabb4f
 
 
734bc31
7eabb4f
734bc31
7eabb4f
734bc31
 
826c17e
 
 
 
 
 
 
62ba484
826c17e
 
734bc31
d0d037d
826c17e
 
 
734bc31
 
 
 
 
 
d0d037d
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
46
47
48
49
50
51
52
53
54
55
56
57
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 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))
        preds = 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] = preds[n, :, :, 0]
                n += 1
        return images


def inference(num_images, select: str):
    if select == 'fmnist':
        result = create_digit_samples(model2, num_images)
    else:
        result = create_digit_samples(model1, num_images)
    return result
    
examples = [[5],[8],[2],[3]]
inputs = [gr.inputs.Number(label="number of images"), gr.inputs.Radio(['fmnist', 'mnist'])]
outputs = gr.outputs.Image(label="Output Image")

interface = gr.Interface(
    fn = inference,
    inputs = inputs,
    outputs = outputs,
    examples = examples,
    description = description,
    title = title,
    article = article
    )

interface.launch(share=True)