File size: 606 Bytes
7481ae6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0c968ab
7481ae6
 
 
 
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
import tensorflow as tf
import gradio as gr

model = tf.keras.models.load_model('model.h5')

def recognize_digit(image):
    if image is not None:
        image = image.reshape((1, 28, 28, 1)) / 255.0
        prediction = model.predict(image)
        
        return {str(i): float(prediction[0][i]) for i in range(10)}
    else:
        return ''

iface = gr.Interface(
    fn=recognize_digit,
    inputs=gr.Image(
        shape=(28, 28),
        image_mode='L',
        invert_colors=True,
        source='canvas'
    ),
    outputs=gr.Label(num_top_classes=10),
    live=True
)

iface.launch(share=True)