ov-pinka commited on
Commit
3e30cc2
·
verified ·
1 Parent(s): 9623400

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +196 -196
app.py CHANGED
@@ -1,196 +1,196 @@
1
- import streamlit as st
2
- import joblib
3
- import pandas as pd
4
- from scipy.stats import yeojohnson
5
- import inv_transform
6
- import math
7
-
8
-
9
-
10
- # Title of the app
11
- st.title("Event Budget Estimate")
12
-
13
- # Add custom CSS for spacing between columns
14
- st.markdown(
15
- """
16
- <style>
17
- .stColumn > div {
18
- padding: 10px; /* Adjust the value as needed to increase spacing */
19
- }
20
- h2 {
21
- font-size: 20px;
22
- }
23
- </style>
24
- """, unsafe_allow_html=True)
25
-
26
- # Create columns with adjusted spacing
27
- col1, col2 = st.columns([1, 1], gap="large") # Adjust gap as needed
28
-
29
- with col1:
30
- # Smaller column title
31
- #st.subheader("Event Data")
32
- st.markdown("### Event Data")
33
-
34
- countries = pd.read_csv('ISO-3166-Countries-with-Regional-Codes.csv')
35
- countries_a2 = list (countries['alpha-2'])
36
- countries_names = list (countries['name'])
37
- countries = [f"{a2} - {name}" for a2, name in zip(countries_a2, countries_names)]
38
-
39
- us_index = countries_a2.index('US')
40
- #cn_index = countries_a2.index('CN')
41
- in_index = countries_a2.index('IN')
42
-
43
- states = pd.read_csv('USA States.csv', index_col=0)
44
- states = list(states.Abbreviation)
45
- ca_index = states.index('CA')
46
-
47
- # Input fields
48
- atnd_num = st.number_input("Estimate Number of Attendees", min_value=0, value=180)
49
- ppr_num = st.number_input("Estimate Paper Number", min_value=0, value=100)
50
- exh_num = st.number_input("Estimate Number of Exhibits", min_value=0, value=0)
51
- long = st.number_input("Conference Duration, Days", min_value=0, value=3)
52
-
53
- # Dropdown menus
54
- event_type = st.selectbox("Event Type", ['Colloquium', 'Conference', 'Forum', 'Seminar', 'Symposium', 'Workshop' , 'Other'], index = 1)
55
- cntry = st.selectbox("Conference Location Country", countries, index = us_index)
56
- chosen_country_index = countries.index(cntry)
57
- if chosen_country_index == us_index:
58
- loc_state = st.selectbox("Conference Location: State Code", states, index=ca_index)
59
- else:
60
- loc_state = "Other"
61
-
62
- # Checkboxes
63
- st.markdown("<h4>Keywords</h4>", unsafe_allow_html=True)
64
- kw_comp = st.checkbox("Computer(s) / Computing / Computation / Computational")
65
- kw_sys = st.checkbox("System(s)")
66
- kw_app = st.checkbox("Application(s)")
67
- #kw_ntwk = st.checkbox("Network(s) /Networking")
68
- kw_wless = st.checkbox("Wireless")
69
- #kw_mdl = st.checkbox("Model / Modeling")
70
- #kw_arch = st.checkbox("Architecture(s)")
71
- kw_img = st.checkbox("Image / Imaging")
72
- # kw_adv = st.checkbox("Advanced")
73
- # kw_dist = st.checkbox("Distributed")
74
-
75
- st.write("**Please only use the exact keywords listed and avoid including any variations or additional words!**")
76
- submit = st.button("Submit")
77
-
78
- # If the submit button is clicked, show output in the second column (col2)
79
- with col2:
80
- if submit:
81
- if chosen_country_index != us_index and loc_state != "Other":
82
- st.error("Correct Event Location: Country and State!")
83
- else:
84
-
85
- try:
86
- p = True
87
- regressor = joblib.load("budget_prediction_model.joblib")
88
- except:
89
- p = False
90
-
91
- if not p:
92
- st.write('Check the model path')
93
- st.error("Model doesn't Exist!")
94
- else:
95
-
96
- atnd_num = atnd_num / 1.22
97
- ppr_num = ppr_num / 1.26
98
-
99
-
100
- data = pd.DataFrame([{
101
- 'act_atnd_tot_atnd_num': atnd_num,
102
- 'long_atnd_ratio':long/atnd_num,
103
- 'act_paprs_num': ppr_num,
104
- 'longevity': long,
105
- 'papr_atnd_ratio':ppr_num/atnd_num,
106
- 'exh_num': exh_num,
107
- 'conf_loc_cntry_nm_India': int(chosen_country_index == in_index),
108
- 'conf_loc_cntry_nm_USA': int(chosen_country_index == us_index),
109
- 'comput': int(kw_comp),
110
- 'conf_loc_state_nm_CA': int(loc_state == "CA"),
111
- 'system': int(kw_sys),
112
- 'conf_evnt_typ_nm_Conference': int(event_type == "Conference"),
113
- 'applic': int(kw_app),
114
- 'conf_evnt_typ_nm_Workshop': int(event_type == "Workshop"),
115
- 'imag': int(kw_img),
116
- 'wireless': int(kw_wless),
117
-
118
- }])
119
-
120
-
121
-
122
- lambdas = pd.read_csv('lambdas_yeojohnson.csv', header=None, index_col=0)
123
- lambdas = lambdas.to_dict()[1]
124
-
125
- for n in ['act_atnd_tot_atnd_num', 'exh_num', 'act_paprs_num']:
126
- data[n] = yeojohnson(data[n], lambdas[n])
127
- data.longevity -= 1
128
-
129
- # Predict income
130
- income = regressor.predict(data)[0]
131
-
132
- if exh_num > 0:
133
- reg_fees_inc = 0.995 * income
134
- else:
135
- reg_fees_inc = income
136
-
137
- income = inv_transform.inv_yeojohnson(income, lambdas['fin_inc_tot_amt'])
138
- reg_fees_inc = inv_transform.inv_yeojohnson(reg_fees_inc, lambdas['fin_inc_tot_amt'])
139
- print(reg_fees_inc)
140
- income = math.ceil(income / 1000) * 1000
141
- reg_fees_inc = math.ceil(reg_fees_inc / 1000) * 1000
142
-
143
- exh_inc = 0
144
- sponsor_inc = 0
145
-
146
- if exh_num < 10:
147
- exh_inc = min(exh_num * 1000, income - reg_fees_inc)
148
- elif exh_num < 30:
149
- exh_inc = min(10*1000 + (exh_num-10) * 1500, income - reg_fees_inc)
150
- elif exh_num < 50:
151
- exh_inc = min(10*1000 + 20 * 1500 + (exh_num-30) * 3500, income - reg_fees_inc)
152
- else:
153
- exh_inc = min(10*1000 + 20 * 1500 + 20 * 3500 + (exh_num-50) * 2900, income - reg_fees_inc)
154
-
155
-
156
- # repeat piecewise function for grants and donations
157
- if exh_num < 50:
158
- sponsor_inc = min(exh_num * 3900, income - reg_fees_inc - exh_inc)
159
- else:
160
- sponsor_inc = min(50 * 3900, income - reg_fees_inc - exh_inc)
161
-
162
- sponsor_inc = math.ceil(sponsor_inc / 1000) * 1000
163
- exh_inc = math.ceil(exh_inc / 1000) * 1000
164
- other_inc = income - reg_fees_inc - exh_inc - sponsor_inc
165
- reg_fees_inc = reg_fees_inc + other_inc
166
-
167
-
168
- expenses = math.ceil(income * 0.85 / 1000) * 1000
169
- socl_funcs_exp = math.ceil(expenses * 0.54 / 1000) * 1000
170
- local_arr_exp = math.ceil(expenses * 0.30 / 1000) * 1000
171
- admintn_exp = math.ceil(expenses * 0.07 / 1000) * 1000
172
- promo_exp = math.ceil(expenses * 0.04 / 1000) * 1000
173
- audit_exp = min(expenses*0.006, 6000)
174
- audit_exp = math.ceil(audit_exp / 1000) * 1000
175
- other_exp = 0.05*expenses - audit_exp
176
-
177
- # Display results
178
- st.markdown("### Predicted Budget*")
179
- st.markdown("<h4>Income Structure</h4>", unsafe_allow_html=True)
180
- st.write(f"**Total Income: ${income}**")
181
- st.write(f"Registration Fees Income: ${reg_fees_inc}")
182
- st.write(f"Exhibit Income: ${exh_inc}")
183
- st.write(f"Sponsorship Income: ${sponsor_inc}")
184
- #st.write(f"Other Income: ${other_inc}")
185
- st.markdown("<h4>Expenses Structure</h4>", unsafe_allow_html=True)
186
- st.write(f"**Total Expenses: ${round(round(expenses, -3))}**")
187
- st.write(f"Social Functions Expenses: ${round(round(socl_funcs_exp, -3))}")
188
- st.write(f"Local Arrangement Expenses: ${round(round(local_arr_exp, -3))}")
189
- st.write(f"Administration Expenses: ${round(round(admintn_exp, -3))}")
190
- st.write(f"Promotion Expenses Amount: ${round(round(promo_exp, -3))}")
191
- st.write(f"Audit Fees Expenses: ${audit_exp}")
192
- st.write(f"Other Expenses: ${round(round(other_exp, -3))}")
193
- st.write("")
194
- st.write("***The numbers are approximate and should be adjusted according to event needs**")
195
-
196
- # Add button save those numbers to Excel
 
1
+ import streamlit as st
2
+ import joblib
3
+ import pandas as pd
4
+ from scipy.stats import yeojohnson
5
+ import inv_transform
6
+ import math
7
+
8
+
9
+
10
+ # Title of the app
11
+ st.title("Event Budget Estimate")
12
+
13
+ # Add custom CSS for spacing between columns
14
+ st.markdown(
15
+ """
16
+ <style>
17
+ .stColumn > div {
18
+ padding: 10px; /* Adjust the value as needed to increase spacing */
19
+ }
20
+ h2 {
21
+ font-size: 20px;
22
+ }
23
+ </style>
24
+ """, unsafe_allow_html=True)
25
+
26
+ # Create columns with adjusted spacing
27
+ col1, col2 = st.columns([1, 1], gap="large") # Adjust gap as needed
28
+
29
+ with col1:
30
+ # Smaller column title
31
+ #st.subheader("Event Data")
32
+ st.markdown("### Event Data")
33
+
34
+ countries = pd.read_csv('ISO-3166-Countries-with-Regional-Codes.csv')
35
+ countries_a2 = list (countries['alpha-2'])
36
+ countries_names = list (countries['name'])
37
+ countries = [f"{a2} - {name}" for a2, name in zip(countries_a2, countries_names)]
38
+
39
+ us_index = countries_a2.index('US')
40
+ #cn_index = countries_a2.index('CN')
41
+ in_index = countries_a2.index('IN')
42
+
43
+ states = pd.read_csv('USA States.csv', index_col=0)
44
+ states = list(states.Abbreviation)
45
+ ca_index = states.index('CA')
46
+
47
+ # Input fields
48
+ atnd_num = st.number_input("Estimate Number of Attendees", min_value=0, value=180)
49
+ ppr_num = st.number_input("Estimate Paper Number", min_value=0, value=100)
50
+ exh_num = st.number_input("Estimate Number of Exhibits", min_value=0, value=0)
51
+ long = st.number_input("Conference Duration, Days", min_value=0, value=3)
52
+
53
+ # Dropdown menus
54
+ event_type = st.selectbox("Event Type", ['Colloquium', 'Conference', 'Forum', 'Seminar', 'Symposium', 'Workshop' , 'Other'], index = 1)
55
+ cntry = st.selectbox("Conference Location Country", countries, index = us_index)
56
+ chosen_country_index = countries.index(cntry)
57
+ if chosen_country_index == us_index:
58
+ loc_state = st.selectbox("Conference Location: State Code", states, index=ca_index)
59
+ else:
60
+ loc_state = "Other"
61
+
62
+ # Checkboxes
63
+ st.markdown("<h4>Keywords</h4>", unsafe_allow_html=True)
64
+ kw_comp = st.checkbox("Computer(s) / Computing / Computation / Computational")
65
+ kw_sys = st.checkbox("System(s)")
66
+ kw_app = st.checkbox("Application(s)")
67
+ #kw_ntwk = st.checkbox("Network(s) /Networking")
68
+ kw_wless = st.checkbox("Wireless")
69
+ #kw_mdl = st.checkbox("Model / Modeling")
70
+ #kw_arch = st.checkbox("Architecture(s)")
71
+ kw_img = st.checkbox("Image / Imaging")
72
+ # kw_adv = st.checkbox("Advanced")
73
+ # kw_dist = st.checkbox("Distributed")
74
+
75
+ st.write("**Please only use the exact keywords listed and avoid including any variations or additional words!**")
76
+ submit = st.button("Submit")
77
+
78
+ # If the submit button is clicked, show output in the second column (col2)
79
+ with col2:
80
+ if submit:
81
+ if chosen_country_index != us_index and loc_state != "Other":
82
+ st.error("Correct Event Location: Country and State!")
83
+ else:
84
+
85
+ try:
86
+ p = True
87
+ regressor = joblib.load("budget_prediction_model.joblib")
88
+ except:
89
+ p = False
90
+
91
+ if not p:
92
+ st.write('Check the model path')
93
+ st.error("Model doesn't Exist!")
94
+ else:
95
+
96
+ atnd_num = atnd_num / 1.22
97
+ ppr_num = ppr_num / 1.26
98
+
99
+
100
+ data = pd.DataFrame([{
101
+ 'act_atnd_tot_atnd_num': atnd_num,
102
+ 'long_atnd_ratio':long/atnd_num,
103
+ 'act_paprs_num': ppr_num,
104
+ 'longevity': long,
105
+ 'papr_atnd_ratio':ppr_num/atnd_num,
106
+ 'exh_num': exh_num,
107
+ 'conf_loc_cntry_nm_India': int(chosen_country_index == in_index),
108
+ 'conf_loc_cntry_nm_USA': int(chosen_country_index == us_index),
109
+ 'comput': int(kw_comp),
110
+ 'conf_loc_state_nm_CA': int(loc_state == "CA"),
111
+ 'system': int(kw_sys),
112
+ 'conf_evnt_typ_nm_Conference': int(event_type == "Conference"),
113
+ 'applic': int(kw_app),
114
+ 'conf_evnt_typ_nm_Workshop': int(event_type == "Workshop"),
115
+ 'imag': int(kw_img),
116
+ 'wireless': int(kw_wless),
117
+
118
+ }])
119
+
120
+
121
+
122
+ lambdas = pd.read_csv('lambdas_yeojohnson.csv', header=None, index_col=0)
123
+ lambdas = lambdas.to_dict()[1]
124
+
125
+ for n in ['act_atnd_tot_atnd_num', 'exh_num', 'act_paprs_num']:
126
+ data[n] = yeojohnson(data[n], lambdas[n])
127
+ data.longevity -= 1
128
+
129
+ # Predict income
130
+ income = regressor.predict(data)[0]
131
+
132
+ if exh_num > 0:
133
+ reg_fees_inc = 0.995 * income
134
+ else:
135
+ reg_fees_inc = income
136
+
137
+ income = inv_transform.inv_yeojohnson(income, lambdas['fin_inc_tot_amt'])
138
+ reg_fees_inc = inv_transform.inv_yeojohnson(reg_fees_inc, lambdas['fin_inc_tot_amt'])
139
+ print(reg_fees_inc)
140
+ income = math.ceil(income / 1000) * 1000
141
+ reg_fees_inc = math.ceil(reg_fees_inc / 1000) * 1000
142
+
143
+ exh_inc = 0
144
+ sponsor_inc = 0
145
+
146
+ if exh_num < 10:
147
+ exh_inc = min(exh_num * 1000, income - reg_fees_inc)
148
+ elif exh_num < 30:
149
+ exh_inc = min(10*1000 + (exh_num-10) * 1500, income - reg_fees_inc)
150
+ elif exh_num < 50:
151
+ exh_inc = min(10*1000 + 20 * 1500 + (exh_num-30) * 3500, income - reg_fees_inc)
152
+ else:
153
+ exh_inc = min(10*1000 + 20 * 1500 + 20 * 3500 + (exh_num-50) * 2900, income - reg_fees_inc)
154
+
155
+
156
+ # repeat piecewise function for grants and donations
157
+ if exh_num < 50:
158
+ sponsor_inc = min(exh_num * 3900, income - reg_fees_inc - exh_inc)
159
+ else:
160
+ sponsor_inc = min(50 * 3900, income - reg_fees_inc - exh_inc)
161
+
162
+ sponsor_inc = math.ceil(sponsor_inc / 1000) * 1000
163
+ exh_inc = math.ceil(exh_inc / 1000) * 1000
164
+ other_inc = income - reg_fees_inc - exh_inc - sponsor_inc
165
+ reg_fees_inc = reg_fees_inc + other_inc
166
+
167
+
168
+ expenses = math.ceil(income * 0.85 / 1000) * 1000
169
+ socl_funcs_exp = math.ceil(expenses * 0.54 / 1000) * 1000
170
+ local_arr_exp = math.ceil(expenses * 0.30 / 1000) * 1000
171
+ admintn_exp = math.ceil(expenses * 0.07 / 1000) * 1000
172
+ promo_exp = math.ceil(expenses * 0.04 / 1000) * 1000
173
+ audit_exp = min(expenses*0.006, 6000)
174
+ audit_exp = math.ceil(audit_exp / 1000) * 1000
175
+ other_exp = expenses - socl_funcs_exp - local_arr_exp - admintn_exp - promo_exp - audit_exp
176
+
177
+ # Display results
178
+ st.markdown("### Predicted Budget*")
179
+ st.markdown("<h4>Income Structure</h4>", unsafe_allow_html=True)
180
+ st.write(f"**Total Income: ${income}**")
181
+ st.write(f"Registration Fees Income: ${reg_fees_inc}")
182
+ st.write(f"Exhibit Income: ${exh_inc}")
183
+ st.write(f"Sponsorship Income: ${sponsor_inc}")
184
+ #st.write(f"Other Income: ${other_inc}")
185
+ st.markdown("<h4>Expenses Structure</h4>", unsafe_allow_html=True)
186
+ st.write(f"**Total Expenses: ${round(round(expenses, -3))}**")
187
+ st.write(f"Social Functions Expenses: ${round(round(socl_funcs_exp, -3))}")
188
+ st.write(f"Local Arrangement Expenses: ${round(round(local_arr_exp, -3))}")
189
+ st.write(f"Administration Expenses: ${round(round(admintn_exp, -3))}")
190
+ st.write(f"Promotion Expenses Amount: ${round(round(promo_exp, -3))}")
191
+ st.write(f"Audit Fees Expenses: ${audit_exp}")
192
+ st.write(f"Other Expenses: ${round(round(other_exp, -3))}")
193
+ st.write("")
194
+ st.write("***The numbers are approximate and should be adjusted according to event needs**")
195
+
196
+ # Add button save those numbers to Excel