gaspar-avit commited on
Commit
d3669b1
·
1 Parent(s): ca58ff4

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +145 -0
app.py ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Created on Fri Mar 31 17:45:36 2023
4
+
5
+ @author: Gaspar Avit Ferrero
6
+ """
7
+
8
+ import streamlit as st
9
+
10
+ from htbuilder import HtmlElement, div, hr, a, p, styles
11
+ from htbuilder.units import percent, px
12
+ from catboost import CatBoostClassifier
13
+
14
+
15
+ ###############################
16
+ ## ------- FUNCTIONS ------- ##
17
+ ###############################
18
+
19
+ def link(link, text, **style):
20
+ return a(_href=link, _target="_blank", style=styles(**style))(text)
21
+
22
+
23
+ def layout(*args):
24
+
25
+ style = """
26
+ <style>
27
+ # MainMenu {visibility: hidden;}
28
+ footer {visibility: hidden;}
29
+ .stApp { bottom: 105px; }
30
+ </style>
31
+ """
32
+
33
+ style_div = styles(
34
+ position="fixed",
35
+ left=0,
36
+ bottom=0,
37
+ margin=px(0, 0, 0, 0),
38
+ width=percent(100),
39
+ color="black",
40
+ text_align="center",
41
+ height="auto",
42
+ opacity=1
43
+ )
44
+
45
+ style_hr = styles(
46
+ display="block",
47
+ margin=px(8, 8, "auto", "auto"),
48
+ border_style="inset",
49
+ border_width=px(0)
50
+ )
51
+
52
+ body = p()
53
+ foot = div(
54
+ style=style_div
55
+ )(
56
+ hr(
57
+ style=style_hr
58
+ ),
59
+ body
60
+ )
61
+
62
+ st.markdown(style, unsafe_allow_html=True)
63
+
64
+ for arg in args:
65
+ if isinstance(arg, str):
66
+ body(arg)
67
+
68
+ elif isinstance(arg, HtmlElement):
69
+ body(arg)
70
+
71
+ st.markdown(str(foot), unsafe_allow_html=True)
72
+
73
+
74
+ def footer():
75
+ myargs = [
76
+ "Made with ❤️ by ",
77
+ link("https://www.linkedin.com/in/gaspar-avit/", "Gaspar Avit"),
78
+ ]
79
+ layout(*myargs)
80
+
81
+
82
+ def update_prediction():
83
+ """Callback to automatically update prediction if button has already been
84
+ clicked"""
85
+ if is_clicked:
86
+ launch_prediction()
87
+
88
+
89
+ def input_layout():
90
+
91
+ input_expander = st.expander('Input parameters', True)
92
+ with input_expander:
93
+ # Row 1
94
+ col_age, col_sex = st.columns(2)
95
+ col_age = st.slider('Age', 18, 75, on_change=update_prediction())
96
+ col_sex = st.radio('Sex', ['Female', 'Male'],
97
+ on_change=update_prediction())
98
+ st.write(‘div.row-widget.stRadio > div{flex-direction: row
99
+ justify-content: center}’,
100
+ unsafe_allow_html=True)
101
+
102
+ # Row 2
103
+ col_height, col_weight = st.columns(2)
104
+ col_height = st.slider(
105
+ 'Height', 140, 200, on_change=update_prediction())
106
+ col_weight = st.slider(
107
+ 'Weight', 40, 140, on_change=update_prediction())
108
+
109
+ # Row 3
110
+ col_ap_hi, col_ap_lo = st.columns(2)
111
+ col_ap_hi = st.slider(
112
+ 'AP Hi', 90, 200, on_change=update_prediction())
113
+ col_ap_lo = st.slider(
114
+ 'AP Lo', 50, 120, on_change=update_prediction())
115
+
116
+
117
+ ###############################
118
+ ## --------- MAIN ---------- ##
119
+ ###############################
120
+
121
+
122
+ if __name__ == "__main__":
123
+
124
+ # Initialize image variable
125
+ poster = None
126
+
127
+ ## --- Page config ------------ ##
128
+ # Set page title
129
+ st.title("""
130
+ Cardiovascular Disease predictor
131
+ #### This app aims to give a scoring of how probable is that an individual \
132
+ would suffer from a cardiovascular disease given its physical \
133
+ characteristics
134
+ #### Just enter your info and get a prediction.
135
+ """)
136
+
137
+ # Set page footer
138
+ footer()
139
+
140
+ # Load classification model
141
+ model = CatBoostClassifier() # parameters not required.
142
+ model.load_model('./train/model.cbm')
143
+
144
+ # Define inputs
145
+ input_layout()