ov-pinka's picture
Upload 7 files
6caaf18 verified
import streamlit as st
import joblib
import pandas as pd
from scipy.stats import yeojohnson
import inv_transform
# Title of the app
st.title("Event Budget Estimate")
# Add custom CSS for spacing between columns
st.markdown(
"""
<style>
.stColumn > div {
padding: 10px; /* Adjust the value as needed to increase spacing */
}
h2 {
font-size: 20px;
}
</style>
""", unsafe_allow_html=True)
# Create columns with adjusted spacing
col1, col2 = st.columns([1, 1], gap="large") # Adjust gap as needed
with col1:
# Smaller column title
#st.subheader("Event Data")
st.markdown("### Event Data")
countries = pd.read_csv('ISO-3166-Countries-with-Regional-Codes.csv')
countries_a2 = list (countries['alpha-2'])
countries_names = list (countries['name'])
countries = [f"{a2} - {name}" for a2, name in zip(countries_a2, countries_names)]
us_index = countries_a2.index('US')
#cn_index = countries_a2.index('CN')
in_index = countries_a2.index('IN')
states = pd.read_csv('USA States.csv', index_col=0)
states = list(states.Abbreviation)
ca_index = states.index('CA')
# Input fields
atnd_num = st.number_input("Estimate Number of Attendees", min_value=0, value=180)
ppr_num = st.number_input("Estimate Paper Number", min_value=0, value=100)
exh_num = st.number_input("Estimate Number of Exhibits", min_value=0, value=0)
long = st.number_input("Conference Duration, Days", min_value=0, value=3)
# Dropdown menus
event_type = st.selectbox("Event Type", ['Colloquium', 'Conference', 'Forum', 'Seminar', 'Symposium', 'Workshop' , 'Other'], index = 1)
cntry = st.selectbox("Conference Location Country", countries, index = us_index)
chosen_country_index = countries.index(cntry)
if chosen_country_index == us_index:
loc_state = st.selectbox("Conference Location: State Code", states, index=ca_index)
else:
loc_state = "Other"
# Checkboxes
st.markdown("<h4>Keywords</h4>", unsafe_allow_html=True)
kw_comp = st.checkbox("Computer(s) / Computing / Computation / Computational")
kw_sys = st.checkbox("System(s)")
kw_app = st.checkbox("Application(s)")
#kw_ntwk = st.checkbox("Network(s) /Networking")
kw_wless = st.checkbox("Wireless")
#kw_mdl = st.checkbox("Model / Modeling")
#kw_arch = st.checkbox("Architecture(s)")
kw_img = st.checkbox("Image / Imaging")
# kw_adv = st.checkbox("Advanced")
# kw_dist = st.checkbox("Distributed")
st.write("**Please only use the exact keywords listed and avoid including any variations or additional words!**")
submit = st.button("Submit")
# If the submit button is clicked, show output in the second column (col2)
with col2:
if submit:
if chosen_country_index != us_index and loc_state != "Other":
st.error("Correct Event Location: Country and State!")
else:
try:
p = True
regressor = joblib.load("budget_prediction_model.joblib")
except:
p = False
if not p:
st.write('Check the model path')
st.error("Model doesn't Exist!")
else:
atnd_num = atnd_num / 1.22
ppr_num = ppr_num / 1.26
data = pd.DataFrame([{
'act_atnd_tot_atnd_num': atnd_num,
'long_atnd_ratio':long/atnd_num,
'act_paprs_num': ppr_num,
'longevity': long,
'papr_atnd_ratio':ppr_num/atnd_num,
'exh_num': exh_num,
'conf_loc_cntry_nm_India': int(chosen_country_index == in_index),
'conf_loc_cntry_nm_USA': int(chosen_country_index == us_index),
'comput': int(kw_comp),
'conf_loc_state_nm_CA': int(loc_state == "CA"),
'system': int(kw_sys),
'conf_evnt_typ_nm_Conference': int(event_type == "Conference"),
'applic': int(kw_app),
'conf_evnt_typ_nm_Workshop': int(event_type == "Workshop"),
'imag': int(kw_img),
'wireless': int(kw_wless),
}])
lambdas = pd.read_csv('lambdas_yeojohnson.csv', header=None, index_col=0)
lambdas = lambdas.to_dict()[1]
for n in ['act_atnd_tot_atnd_num', 'exh_num', 'act_paprs_num']:
data[n] = yeojohnson(data[n], lambdas[n])
data.longevity -= 1
# Predict income
income = regressor.predict(data)[0]
if exh_num > 0:
reg_fees_inc = 0.995 * income
else:
reg_fees_inc = income
income = inv_transform.inv_yeojohnson(income, lambdas['fin_inc_tot_amt'])
reg_fees_inc = inv_transform.inv_yeojohnson(reg_fees_inc, lambdas['fin_inc_tot_amt'])
print(reg_fees_inc)
income = round(income / 1000) * 1000
reg_fees_inc = round(reg_fees_inc / 1000) * 1000
exh_inc = 0
sponsor_inc = 0
if exh_num < 10:
exh_inc = min(exh_num * 1000, income - reg_fees_inc)
elif exh_num < 30:
exh_inc = min(10*1000 + (exh_num-10) * 1500, income - reg_fees_inc)
elif exh_num < 50:
exh_inc = min(10*1000 + 20 * 1500 + (exh_num-30) * 3500, income - reg_fees_inc)
else:
exh_inc = min(10*1000 + 20 * 1500 + 20 * 3500 + (exh_num-50) * 2900, income - reg_fees_inc)
# repeat piecewise function for grants and donations
if exh_num < 50:
sponsor_inc = min(exh_num * 3900, income - reg_fees_inc - exh_inc)
else:
sponsor_inc = min(50 * 3900, income - reg_fees_inc - exh_inc)
sponsor_inc = round(sponsor_inc / 1000) * 1000
exh_inc = round(exh_inc / 1000) * 1000
other_inc = income - reg_fees_inc - exh_inc - sponsor_inc
reg_fees_inc = reg_fees_inc + other_inc
expenses = round(income * 0.85 / 1000) * 1000
socl_funcs_exp = round(expenses * 0.54 / 1000) * 1000
local_arr_exp = round(expenses * 0.30 / 1000) * 1000
admintn_exp = round(expenses * 0.07 / 1000) * 1000
promo_exp =round(expenses * 0.04 / 1000) * 1000
audit_exp = min(expenses*0.006, 6000)
audit_exp = round(audit_exp / 1000) * 1000
other_exp = expenses - socl_funcs_exp - local_arr_exp - admintn_exp - promo_exp - audit_exp
# Display results
st.markdown("### Predicted Budget*")
st.markdown("<h4>Income Structure</h4>", unsafe_allow_html=True)
st.write(f"**Total Income: ${income}**")
st.write(f"Registration Fees Income: ${reg_fees_inc}")
st.write(f"Exhibit Income: ${exh_inc}")
st.write(f"Sponsorship Income: ${sponsor_inc}")
#st.write(f"Other Income: ${other_inc}")
st.markdown("<h4>Expenses Structure</h4>", unsafe_allow_html=True)
st.write(f"**Total Expenses: ${round(round(expenses, -3))}**")
st.write(f"Social Functions Expenses: ${round(round(socl_funcs_exp, -3))}")
st.write(f"Local Arrangement Expenses: ${round(round(local_arr_exp, -3))}")
st.write(f"Administration Expenses: ${round(round(admintn_exp, -3))}")
st.write(f"Promotion Expenses Amount: ${round(round(promo_exp, -3))}")
st.write(f"Audit Fees Expenses: ${audit_exp}")
st.write(f"Other Expenses: ${round(round(other_exp, -3))}")
st.write("")
st.write("***The numbers are approximate and should be adjusted according to event needs**")
# Add button save those numbers to Excel