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("""

andwritten Digit Recognition

jason.yu.mail@qq.com 📧
""") 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()