Spaces:
Runtime error
Runtime error
import gradio as gr | |
import tensorflow as tf | |
import keras | |
from keras.datasets import mnist | |
import matplotlib.pyplot as plt | |
import random | |
(train_images, train_labels), (test_images, test_labels) = mnist.load_data() | |
def sample_digit(digit): | |
rn = 0 | |
# pick a random digit from 60,000 in the training set until a desired match is found | |
while(train_labels[rn] != digit_choice): | |
rn = int(random.random() * 60000) | |
digit = train_images[rn] | |
fig = plt.figure() | |
plt.imshow(digit, cmap=plt.cm.binary) | |
out_txt = "train_images[%d] = %d" % (rn, train_labels[rn]) | |
return fig, out_txt | |
iface = gr.Interface( | |
fn = sample_digit, | |
inputs = ('digit', [ | |
#gr.inputs.Dropdown([0, 1, 2, 3]) | |
#gr.inputs.Number() | |
gr.inputs.Slider(0, 9) | |
]), | |
outputs=[gr.outputs.Image(type="plot"), 'text'], | |
title='MNIST Digit Sampler', | |
description='Pick a random digit from the MNIST dataset' | |
) | |
iface.launch() | |