import tensorflow as tf import numpy as np import cv2 as cv import gradio as gr from PIL import Image model = tf.keras.models.load_model("mnist-model.h5") def recognize_digit(image): image = cv.resize(image, (28, 28)) image = image / 255 image = image.reshape((1, 28, 28)) 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=10), live=True, css=".footer {display:none !important}", # title="MNIST Sketchpad", description="Draw a number 0 through 9.", thumbnail="https://raw.githubusercontent.com/gradio-app/real-time-mnist/master/thumbnail2.png").launch();