File size: 903 Bytes
df6a24a
5d9b8be
 
 
 
3664c8f
5d9b8be
 
df6a24a
835dfc3
3664c8f
fe16b6b
032b2fc
fe16b6b
032b2fc
48ecd32
032b2fc
b96eb2c
5d9b8be
df6a24a
5d9b8be
835dfc3
e338dea
d4667a6
835dfc3
a653a0c
e338dea
e52bac8
835dfc3
 
ed33ebd
5d9b8be
ed33ebd
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
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):
    rn = int(random.random() * 60000)  
  digit_img = train_images[rn]
  fig = plt.figure()
  plt.imshow(digit_img, cmap=plt.cm.binary)
  out_txt = "train_images[%d]" % rn
  return fig, out_txt

iface = gr.Interface(
  fn = sample_digit,
  inputs = [ 
    #gr.inputs.Dropdown([0, 1, 2, 3])
    #gr.inputs.Number()
    gr.inputs.Slider(minimum=0, maximum=9, step=1)
  ],
  outputs=[gr.outputs.Image(type='plot'), 'text'],
  title='MNIST Digit Sampler',
  description='Pick a random digit from the MNIST dataset'
)
  
iface.launch()