File size: 842 Bytes
d6bad87
 
 
65357fb
d6bad87
389c998
d6bad87
 
f4981c8
 
d6bad87
65357fb
 
d6bad87
 
 
 
65357fb
d6bad87
65357fb
d6bad87
 
 
 
 
 
f4981c8
 
 
 
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
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()