File size: 933 Bytes
819a88c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 joblib
import numpy as np

model=joblib.load('./data/random_forest_model.pkl')
# 构建预测函数
def predict_minist(image):
    # print(normalized.shape)
    normalized =image['composite'][:,:,-1]
    flattened = normalized.reshape(1, 784)
    prediction = model.predict(flattened)
    print(normalized.shape,np.max(normalized),prediction[0])

    return prediction[0]
with gr.Blocks(theme="soft") as demo:
    gr.HTML("""
        <center> 
        <h1> andwritten Digit Recognition</h1>
        <b> jason.yu.mail@qq.com  📧<b>
        </center>
        """)  
    gr.Markdown("Draw a digit and the model will predict the digit. Please draw the digit in the center of the canvas")
    with gr.Row():
        outtext=gr.Textbox(label="Prediciton")
    with gr.Row():
        inputimg=gr.ImageMask(image_mode="RGBA",crop_size=(28,28))

    inputimg.change(predict_minist,inputimg,outtext)
demo.launch()