import gradio as gr import tensorflow as tf import numpy as np import cv2 model = tf.keras.models.load_model("mymodel/mymodel") def predict(img): z = tf.keras.preprocessing.image.img_to_array(img) kernel = np.ones((5,5),np.uint8) z = cv2.dilate(z ,kernel,iterations = 1) z = np.expand_dims(z, axis=0) y = model.predict(z) ysoft = tf.nn.softmax(y) ymax = np.argmax(ysoft) return int(ymax) sp = gr.Sketchpad(tool="sketch", shape=(140,100), image_mode="L", label='arabic numeral', invert_colors=False).style(height=200, width=280) gr.Label() gr.Interface(fn=predict, inputs=sp, outputs="label", live=True, examples=[ ["writer001_pass01_digit2.png"], ["writer001_pass01_digit4.png"], ["writer001_pass07_digit9.png"], ["writer594_pass06_digit7.png"]]).launch()