Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -135,8 +135,6 @@ with col3:
|
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
-
|
| 139 |
-
|
| 140 |
# Initialize session state variables
|
| 141 |
st.session_state.setdefault('current_page', 'home')
|
| 142 |
st.session_state.setdefault('premiums_df', None)
|
|
@@ -151,25 +149,9 @@ def is_mostly_numeric(s):
|
|
| 151 |
return percent_numeric > 0.5
|
| 152 |
return False
|
| 153 |
|
| 154 |
-
# # Callback functions for processing each uploaded file
|
| 155 |
-
# def process_premiums_file(uploaded_file):
|
| 156 |
-
# df = pd.read_csv(uploaded_file)
|
| 157 |
-
# st.session_state['premiums_df'] = df
|
| 158 |
-
# st.session_state.active_page = 'premiums_selection'
|
| 159 |
-
|
| 160 |
-
# def process_claims_recoveries_file(uploaded_file):
|
| 161 |
-
# df = pd.read_csv(uploaded_file)
|
| 162 |
-
# st.session_state['claims_recoveries_df'] = df
|
| 163 |
-
# st.session_state.active_page = 'claims_recoveries_selection'
|
| 164 |
-
|
| 165 |
-
# def process_claims_count_file(uploaded_file):
|
| 166 |
-
# df = pd.read_csv(uploaded_file)
|
| 167 |
-
# st.session_state['claims_count_df'] = df
|
| 168 |
-
# st.session_state.active_page = 'claims_count_selection'
|
| 169 |
-
|
| 170 |
def process_file(uploaded_file, key):
|
| 171 |
df = pd.read_csv(uploaded_file)
|
| 172 |
-
st.session_state[key] = df
|
| 173 |
st.session_state['current_page'] = key + '_selection'
|
| 174 |
|
| 175 |
# Function to display the column selection UI
|
|
@@ -197,40 +179,32 @@ def column_selection_ui(dataframe_key, selection_key):
|
|
| 197 |
|
| 198 |
# Filter the DataFrame based on selected 'lob' values
|
| 199 |
if selected_lob_values:
|
| 200 |
-
filtered_df = st.session_state[
|
| 201 |
-
st.session_state['
|
| 202 |
|
| 203 |
# Display other column selections after 'lob' has been selected and DataFrame has been filtered
|
| 204 |
st.write("Now, select the columns for other parameters:")
|
| 205 |
-
valuation_as_at = st.selectbox('Valuation As At:', filtered_df.columns, key='
|
| 206 |
-
quarter_bracket = st.selectbox('Quarter Bracket:', filtered_df.columns, key='
|
| 207 |
# Continue with other selections as required...
|
| 208 |
|
| 209 |
# Store the column selections in the session state
|
| 210 |
-
st.session_state['
|
|
|
|
|
|
|
| 211 |
'valuation_as_at': valuation_as_at,
|
| 212 |
'quarter_bracket': quarter_bracket,
|
| 213 |
-
# ... include other selections as well
|
| 214 |
}
|
| 215 |
|
| 216 |
-
# Store the column selections in the session state
|
| 217 |
-
st.session_state[f'{selection_key}_selections'] = {
|
| 218 |
-
'lob_column': lob_column,
|
| 219 |
-
'selected_lob_values': selected_lob_values,
|
| 220 |
-
'valuation_as_at': valuation_as_at,
|
| 221 |
-
'quarter_bracket': quarter_bracket,
|
| 222 |
-
}
|
| 223 |
-
|
| 224 |
-
|
| 225 |
# File uploaders and buttons
|
| 226 |
if st.session_state.current_page == 'home':
|
| 227 |
upload_col1, upload_col2, upload_col3 = st.columns(3)
|
| 228 |
with upload_col1:
|
| 229 |
-
uploaded_file_premiums = st.file_uploader("Upload Premiums Data", key="
|
| 230 |
with upload_col2:
|
| 231 |
-
uploaded_file_claims_recoveries = st.file_uploader("Upload Claims Recoveries Data", key="
|
| 232 |
with upload_col3:
|
| 233 |
-
uploaded_file_claims_count = st.file_uploader("Upload Claims Count Data", key="
|
| 234 |
|
| 235 |
button_col1, button_col2, button_col3 = st.columns(3)
|
| 236 |
with button_col1:
|
|
@@ -248,10 +222,10 @@ if st.session_state.current_page == 'home':
|
|
| 248 |
|
| 249 |
# Conditional rendering based on the current page
|
| 250 |
if st.session_state.current_page.endswith('_selection'):
|
| 251 |
-
dataframe_key = st.session_state.current_page.replace('_selection', '')
|
| 252 |
-
column_selection_ui(dataframe_key, dataframe_key)
|
| 253 |
|
| 254 |
# Back to Home button
|
| 255 |
if st.session_state.current_page != 'home':
|
| 256 |
if st.button("Back to Home"):
|
| 257 |
-
st.session_state.current_page = 'home'
|
|
|
|
| 135 |
|
| 136 |
|
| 137 |
|
|
|
|
|
|
|
| 138 |
# Initialize session state variables
|
| 139 |
st.session_state.setdefault('current_page', 'home')
|
| 140 |
st.session_state.setdefault('premiums_df', None)
|
|
|
|
| 149 |
return percent_numeric > 0.5
|
| 150 |
return False
|
| 151 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
def process_file(uploaded_file, key):
|
| 153 |
df = pd.read_csv(uploaded_file)
|
| 154 |
+
st.session_state[key + '_df'] = df
|
| 155 |
st.session_state['current_page'] = key + '_selection'
|
| 156 |
|
| 157 |
# Function to display the column selection UI
|
|
|
|
| 179 |
|
| 180 |
# Filter the DataFrame based on selected 'lob' values
|
| 181 |
if selected_lob_values:
|
| 182 |
+
filtered_df = st.session_state[dataframe_key][st.session_state[dataframe_key][lob_column].isin(selected_lob_values)]
|
| 183 |
+
st.session_state['filtered_' + dataframe_key] = filtered_df
|
| 184 |
|
| 185 |
# Display other column selections after 'lob' has been selected and DataFrame has been filtered
|
| 186 |
st.write("Now, select the columns for other parameters:")
|
| 187 |
+
valuation_as_at = st.selectbox('Valuation As At:', filtered_df.columns, key='valuation_as_at_' + selection_key)
|
| 188 |
+
quarter_bracket = st.selectbox('Quarter Bracket:', filtered_df.columns, key='quarter_bracket_' + selection_key)
|
| 189 |
# Continue with other selections as required...
|
| 190 |
|
| 191 |
# Store the column selections in the session state
|
| 192 |
+
st.session_state[f'{selection_key}_selections'] = {
|
| 193 |
+
'lob_column': lob_column,
|
| 194 |
+
'selected_lob_values': selected_lob_values,
|
| 195 |
'valuation_as_at': valuation_as_at,
|
| 196 |
'quarter_bracket': quarter_bracket,
|
|
|
|
| 197 |
}
|
| 198 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
# File uploaders and buttons
|
| 200 |
if st.session_state.current_page == 'home':
|
| 201 |
upload_col1, upload_col2, upload_col3 = st.columns(3)
|
| 202 |
with upload_col1:
|
| 203 |
+
uploaded_file_premiums = st.file_uploader("Upload Premiums Data", key="premiums_file")
|
| 204 |
with upload_col2:
|
| 205 |
+
uploaded_file_claims_recoveries = st.file_uploader("Upload Claims Recoveries Data", key="claims_recoveries_file")
|
| 206 |
with upload_col3:
|
| 207 |
+
uploaded_file_claims_count = st.file_uploader("Upload Claims Count Data", key="claims_count_file")
|
| 208 |
|
| 209 |
button_col1, button_col2, button_col3 = st.columns(3)
|
| 210 |
with button_col1:
|
|
|
|
| 222 |
|
| 223 |
# Conditional rendering based on the current page
|
| 224 |
if st.session_state.current_page.endswith('_selection'):
|
| 225 |
+
dataframe_key = st.session_state.current_page.replace('_selection', '_df')
|
| 226 |
+
column_selection_ui(dataframe_key, dataframe_key.replace('_df', ''))
|
| 227 |
|
| 228 |
# Back to Home button
|
| 229 |
if st.session_state.current_page != 'home':
|
| 230 |
if st.button("Back to Home"):
|
| 231 |
+
st.session_state.current_page = 'home'
|