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): | |
if img is None: | |
return | |
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=[ | |
["8.png"], | |
["4.png"], | |
["9.png"], | |
["2.png"]]).launch() |