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") title = "WGAN-GP" description = "Image Generation Using WGAN" article = """

Keras Example given by A_K_Nain
Space by Gitesh Chawda

""" def create_digit_samples(n_samples): random_latent_vectors = tf.random.normal(shape=(int(n_samples), 128)) examples = model(random_latent_vectors) size = ceil(sqrt(n_samples)) digit_images = np.zeros((28*size, 28*size), dtype=float) n = 0 for i in range(size): for j in range(size): if n == n_samples: break digit_images[i* 28 : (i+1)*28, j*28 : (j+1)*28] = examples[n, :, :, 0] n += 1 return digit_images examples = [[5],[8],[2],[3]] iface = gr.Interface( fn = create_digit_samples, inputs = ["number"], outputs = ["image"], examples = examples, description = description, title = title, article = article ) iface.launch()