JunchuanYu commited on
Commit
819a88c
·
verified ·
1 Parent(s): 89d4f96

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -29
app.py CHANGED
@@ -1,29 +1,29 @@
1
- import gradio as gr
2
- import joblib
3
- import numpy as np
4
-
5
- model=joblib.load('./data/random_forest_model.pkl')
6
- # 构建预测函数
7
- def predict_minist(image):
8
- # print(normalized.shape)
9
- normalized =image['composite'][:,:,-1]
10
- flattened = normalized.reshape(1, 784)
11
- prediction = model.predict(flattened)
12
- print(normalized.shape,np.max(normalized),prediction[0])
13
-
14
- return prediction[0]
15
- with gr.Blocks() as demo:
16
- gr.HTML("""
17
- <center>
18
- <h1> andwritten Digit Recognition</h1>
19
- <b> [email protected] 📧<b>
20
- </center>
21
- """)
22
- gr.Markdown("Draw a digit and the model will predict the digit. Please draw the digit in the center of the canvas")
23
- with gr.Row():
24
- outtext=gr.Textbox(label="Prediciton")
25
- with gr.Row():
26
- inputimg=gr.ImageMask(image_mode="RGBA",crop_size=(28,28))
27
-
28
- inputimg.change(predict_minist,inputimg,outtext)
29
- demo.launch()
 
1
+ import gradio as gr
2
+ import joblib
3
+ import numpy as np
4
+
5
+ model=joblib.load('./data/random_forest_model.pkl')
6
+ # 构建预测函数
7
+ def predict_minist(image):
8
+ # print(normalized.shape)
9
+ normalized =image['composite'][:,:,-1]
10
+ flattened = normalized.reshape(1, 784)
11
+ prediction = model.predict(flattened)
12
+ print(normalized.shape,np.max(normalized),prediction[0])
13
+
14
+ return prediction[0]
15
+ with gr.Blocks(theme="soft") as demo:
16
+ gr.HTML("""
17
+ <center>
18
+ <h1> andwritten Digit Recognition</h1>
19
+ <b> [email protected] 📧<b>
20
+ </center>
21
+ """)
22
+ gr.Markdown("Draw a digit and the model will predict the digit. Please draw the digit in the center of the canvas")
23
+ with gr.Row():
24
+ outtext=gr.Textbox(label="Prediciton")
25
+ with gr.Row():
26
+ inputimg=gr.ImageMask(image_mode="RGBA",crop_size=(28,28))
27
+
28
+ inputimg.change(predict_minist,inputimg,outtext)
29
+ demo.launch()