640510702phithak commited on
Commit
63dd074
·
verified ·
1 Parent(s): ffb3968

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -62
app.py CHANGED
@@ -4,67 +4,69 @@ import pandas as pd
4
 
5
  # โหลดโมเดลที่บันทึกไว้
6
  model = joblib.load('logistic_regression_model.pkl')
7
-
8
- # ฟังก์ชันสำหรับรับข้อมูลจากผู้ใช้
9
- def get_input():
10
- # ใช้ Streamlit widgets เพื่อรับข้อมูลจากผู้ใช้
11
- child = st.number_input("Enter child value", min_value=0.0, step=0.1)
12
- hct = st.number_input("Enter hct value", min_value=0.0, step=0.1)
13
- inr = st.number_input("Enter inr value", min_value=0.0, step=0.1)
14
- alb = st.number_input("Enter alb value", min_value=0.0, step=0.1)
15
- tb = st.number_input("Enter tb value", min_value=0.0, step=0.1)
16
- ascites = st.selectbox("Enter ascites value", options=[0, 1])
17
- hepencep = st.selectbox("Enter hepencep value", options=[0, 1])
18
- bclcstage = st.number_input("Enter bclcstage value", min_value=0, step=1)
19
- sen = st.number_input("Enter sen value", min_value=0, step=1)
20
- active = st.selectbox("Enter active value", options=[0, 1])
21
- pvinvade = st.selectbox("Enter pvinvade value", options=[0, 1])
22
- hvivcinvade = st.selectbox("Enter hvivcinvade value", options=[0, 1])
23
- treat_embolize = st.selectbox("Enter treat_embolize value", options=[0, 1])
24
- treat_surgery = st.selectbox("Enter treat_surgery value", options=[0, 1])
25
- sex_male = st.selectbox("Enter sex_male value", options=[0, 1])
26
- shock_Shock = st.selectbox("Enter shock_Shock value", options=[0, 1])
27
- loctumor_left_lobe = st.selectbox("Enter loctumor_left_lobe value", options=[0, 1])
28
- locbleed_left_lobe = st.selectbox("Enter locbleed_left_lobe value", options=[0, 1])
29
- locbleed_right_lobe = st.selectbox("Enter locbleed_right_lobe value", options=[0, 1])
30
-
31
- # สร้าง DataFrame จากข้อมูลที่กรอก
32
- input_data = {
33
- "child": [child],
34
- "hct": [hct],
35
- "inr": [inr],
36
- "alb": [alb],
37
- "tb": [tb],
38
- "ascites": [ascites],
39
- "hepencep": [hepencep],
40
- "bclcstage": [bclcstage],
41
- "sen": [sen],
42
- "active": [active],
43
- "pvinvade": [pvinvade],
44
- "hvivcinvade": [hvivcinvade],
45
- "treat_embolize": [treat_embolize],
46
- "treat_surgery": [treat_surgery],
47
- "sex_male": [sex_male],
48
- "shock_Shock": [shock_Shock],
49
- "loctumor_left_lobe": [loctumor_left_lobe],
50
- "locbleed_left_lobe": [locbleed_left_lobe],
51
- "locbleed_right_lobe": [locbleed_right_lobe]
52
- }
53
 
54
- return pd.DataFrame(input_data)
55
-
56
- # ส่วนของ UI ใน Streamlit
57
- st.title('Logistic Regression Model for Prediction')
58
- st.write('กรุณากรอกข้อมูลเพื่อทำนายผล')
59
-
60
- # รับข้อมูลจากผู้ใช้
61
- input_data = get_input()
62
-
63
- # ปุ่มสำหรับทำนายผล
64
- if st.button("Predict"):
65
- # ทำนายผล
66
- prediction = model.predict(input_data)
67
-
68
- # แสดงผลลัพธ์
69
- st.write(f"Prediction Result: {int(prediction[0])}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
 
 
 
 
4
 
5
  # โหลดโมเดลที่บันทึกไว้
6
  model = joblib.load('logistic_regression_model.pkl')
7
+ def main():
8
+ # ฟังก์ชันสำหรับรับข้อมูลจากผู้ใช้
9
+ def get_input():
10
+ # ใช้ Streamlit widgets เพื่อรับข้อมูลจากผู้ใช้
11
+ child = st.number_input("Enter child value", min_value=0.0, step=0.1)
12
+ hct = st.number_input("Enter hct value", min_value=0.0, step=0.1)
13
+ inr = st.number_input("Enter inr value", min_value=0.0, step=0.1)
14
+ alb = st.number_input("Enter alb value", min_value=0.0, step=0.1)
15
+ tb = st.number_input("Enter tb value", min_value=0.0, step=0.1)
16
+ ascites = st.selectbox("Enter ascites value", options=[0, 1])
17
+ hepencep = st.selectbox("Enter hepencep value", options=[0, 1])
18
+ bclcstage = st.number_input("Enter bclcstage value", min_value=0, step=1)
19
+ sen = st.number_input("Enter sen value", min_value=0, step=1)
20
+ active = st.selectbox("Enter active value", options=[0, 1])
21
+ pvinvade = st.selectbox("Enter pvinvade value", options=[0, 1])
22
+ hvivcinvade = st.selectbox("Enter hvivcinvade value", options=[0, 1])
23
+ treat_embolize = st.selectbox("Enter treat_embolize value", options=[0, 1])
24
+ treat_surgery = st.selectbox("Enter treat_surgery value", options=[0, 1])
25
+ sex_male = st.selectbox("Enter sex_male value", options=[0, 1])
26
+ shock_Shock = st.selectbox("Enter shock_Shock value", options=[0, 1])
27
+ loctumor_left_lobe = st.selectbox("Enter loctumor_left_lobe value", options=[0, 1])
28
+ locbleed_left_lobe = st.selectbox("Enter locbleed_left_lobe value", options=[0, 1])
29
+ locbleed_right_lobe = st.selectbox("Enter locbleed_right_lobe value", options=[0, 1])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
+ # สร้าง DataFrame จากข้อมูลที่กรอก
32
+ input_data = {
33
+ "child": [child],
34
+ "hct": [hct],
35
+ "inr": [inr],
36
+ "alb": [alb],
37
+ "tb": [tb],
38
+ "ascites": [ascites],
39
+ "hepencep": [hepencep],
40
+ "bclcstage": [bclcstage],
41
+ "sen": [sen],
42
+ "active": [active],
43
+ "pvinvade": [pvinvade],
44
+ "hvivcinvade": [hvivcinvade],
45
+ "treat_embolize": [treat_embolize],
46
+ "treat_surgery": [treat_surgery],
47
+ "sex_male": [sex_male],
48
+ "shock_Shock": [shock_Shock],
49
+ "loctumor_left_lobe": [loctumor_left_lobe],
50
+ "locbleed_left_lobe": [locbleed_left_lobe],
51
+ "locbleed_right_lobe": [locbleed_right_lobe]
52
+ }
53
+
54
+ return pd.DataFrame(input_data)
55
+
56
+ # ส่วนของ UI ใน Streamlit
57
+ st.title('Logistic Regression Model for Prediction')
58
+ st.write('กรุณากรอกข้อมูลเพื่อทำนายผล')
59
+
60
+ # รับข้อมูลจากผู้ใช้
61
+ input_data = get_input()
62
+
63
+ # ปุ่มสำหรับทำนายผล
64
+ if st.button("Predict"):
65
+ # ทำนายผล
66
+ prediction = model.predict(input_data)
67
+
68
+ # แสดงผลลัพธ์
69
+ st.write(f"Prediction Result: {int(prediction[0])}")
70
 
71
+ if __name__=='__main__':
72
+ main()