Spaces:
Runtime error
Runtime error
File size: 1,294 Bytes
27758e8 90fb17b 27758e8 907d6fd 2f6cd1f 734bc31 7eabb4f 734bc31 7eabb4f 734bc31 7eabb4f 734bc31 7eabb4f 734bc31 62ba484 734bc31 d0d037d 7eabb4f cb16c0d 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 |
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("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(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
examples = [[5],[8],[2],[3]]
interface = gr.Interface(
fn = Predict,
inputs = ["number"],
outputs = ["image"],
examples = examples,
description = description,
title = title,
article = article
)
interface.launch(share=True) |