File size: 736 Bytes
14057b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import tensorflow as tf
import numpy as np
from urllib.request import urlretrieve
import gradio as gr

urlretrieve("https://gr-models.s3-us-west-2.amazonaws.com/mnist-model.h5", "mnist-model.h5")
model = tf.keras.models.load_model("mnist-model.h5")

def recognize_digit(image):
	image = image.reshape(1, -1)  # add a batch dimension
	prediction = model.predict(image).tolist()[0]
	return {str(i): prediction[i] for i in range(10)}

gr.Interface(fn=recognize_digit,
			 inputs="sketchpad",
			 outputs=gr.outputs.Label(num_top_classes=3),
			 live=True,
			 css=".footer {display:none !important}",
			 # title="MNIST Sketchpad",
			 description="Draw a number 0 through 9 on the sketchpad, and see predictions in real time.").launch();