InEase commited on
Commit
e405448
·
1 Parent(s): d550387

Add application file

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pickle
2
+
3
+ import gradio as gr
4
+ import pandas as pd
5
+
6
+
7
+ def rf_predict(GDP, Unemployment, Medical_resources, Past_years_life_expectancy_growth_rate):
8
+ # 读取模型
9
+ with open('rf.pkl', 'rb') as f:
10
+ rf = pickle.load(f)
11
+ # 预测
12
+ X_test = [GDP, Unemployment, Medical_resources, Past_years_life_expectancy_growth_rate]
13
+ X_test = pd.DataFrame(X_test).T
14
+ X_test.columns = ['GDP_per_capita', 'Unemployment_rate', 'Medical_resources_per_capita',
15
+ 'Past_years_life_expectancy_growth_rate']
16
+ y_pred = rf.predict(X_test)
17
+ return y_pred
18
+
19
+
20
+ # def rf_predict(GDP, Unemployment, Medical_resources, Past_years_life_expectancy_growth_rate):
21
+ # print(rf_predict(85698, 5.5, 2120, 0.1))
22
+ gr.Interface(
23
+ fn=rf_predict,
24
+ inputs=[
25
+ gr.Textbox(label="GDP"),
26
+ gr.Textbox(label="Unemployment"),
27
+ gr.Textbox(label="Medical_resources"),
28
+ gr.Textbox(label="Past_years_life_expectancy_growth_rate"),
29
+ ],
30
+ outputs="number",
31
+ title="Life Expectancy Prediction"
32
+ ).launch()