Spaces:
Runtime error
Runtime error
File size: 1,429 Bytes
27758e8 907d6fd 419ca0b 226690e 419ca0b 226690e 419ca0b 226690e 419ca0b 226690e 419ca0b 226690e 907d6fd 419ca0b 907d6fd c5b3b95 |
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 |
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 = """
<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 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))
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
inputs = gr.inputs.Number(label="number of images")
outputs = gr.outputs.Image(label="Predictions")
examples = [
[10],
[7],
[1],
[3],
[5]
]
gr.Interface(create_digit_samples, inputs, outputs, article=article, description=description, article=article, examples=examples, analytics_enabled=False).launch(enable_queue=True)
|