Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -137,21 +137,11 @@ with col3:
|
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
-
#
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
if 'claims_recoveries_df' not in st.session_state:
|
| 146 |
-
st.session_state.claims_recoveries_df = None
|
| 147 |
-
if 'claims_count_df' not in st.session_state:
|
| 148 |
-
st.session_state.claims_count_df = None
|
| 149 |
-
|
| 150 |
-
if 'current_page' not in st.session_state:
|
| 151 |
-
st.session_state['current_page'] = 'home'
|
| 152 |
-
if 'premiums_df' not in st.session_state:
|
| 153 |
-
st.session_state['premiums_df'] = None
|
| 154 |
-
# ... Similarly for other dataframes
|
| 155 |
|
| 156 |
# Helper function to check if a string has more than 50% numeric characters
|
| 157 |
def is_mostly_numeric(s):
|
|
@@ -180,7 +170,7 @@ def is_mostly_numeric(s):
|
|
| 180 |
def process_file(uploaded_file, key):
|
| 181 |
df = pd.read_csv(uploaded_file)
|
| 182 |
st.session_state[key] = df
|
| 183 |
-
st.session_state['current_page'] = key
|
| 184 |
|
| 185 |
# Function to display the column selection UI
|
| 186 |
def column_selection_ui(dataframe_key, selection_key):
|
|
@@ -223,42 +213,45 @@ def column_selection_ui(dataframe_key, selection_key):
|
|
| 223 |
# ... include other selections as well
|
| 224 |
}
|
| 225 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
with
|
| 232 |
-
|
| 233 |
-
with
|
| 234 |
-
|
|
|
|
|
|
|
| 235 |
|
| 236 |
-
# Only show buttons if we're on the home page
|
| 237 |
-
if st.session_state['current_page'] == 'home':
|
| 238 |
button_col1, button_col2, button_col3 = st.columns(3)
|
| 239 |
with button_col1:
|
| 240 |
if uploaded_file_premiums and st.button("Select Premiums columns"):
|
| 241 |
-
process_file(uploaded_file_premiums, '
|
| 242 |
with button_col2:
|
| 243 |
if uploaded_file_claims_recoveries:
|
| 244 |
if st.button("Select Incurred claims columns"):
|
| 245 |
-
process_file(uploaded_file_claims_recoveries, '
|
| 246 |
if st.button("Select Recoveries columns"):
|
| 247 |
-
|
| 248 |
-
process_file(uploaded_file_claims_recoveries, 'claims_recoveries_df')
|
| 249 |
with button_col3:
|
| 250 |
if uploaded_file_claims_count and st.button("Select Claims count columns"):
|
| 251 |
-
process_file(uploaded_file_claims_count, '
|
| 252 |
-
|
| 253 |
-
#
|
| 254 |
-
if st.session_state
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
# Add a button to go back to the home page from any selection page
|
| 262 |
-
if st.session_state['current_page'] != 'home':
|
| 263 |
if st.button("Back to Home"):
|
| 264 |
-
st.session_state
|
|
|
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
+
# Initialize session state variables
|
| 141 |
+
st.session_state.setdefault('current_page', 'home')
|
| 142 |
+
st.session_state.setdefault('premiums_df', None)
|
| 143 |
+
st.session_state.setdefault('claims_recoveries_df', None)
|
| 144 |
+
st.session_state.setdefault('claims_count_df', None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
|
| 146 |
# Helper function to check if a string has more than 50% numeric characters
|
| 147 |
def is_mostly_numeric(s):
|
|
|
|
| 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
|
| 176 |
def column_selection_ui(dataframe_key, selection_key):
|
|
|
|
| 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="premiums")
|
| 230 |
+
with upload_col2:
|
| 231 |
+
uploaded_file_claims_recoveries = st.file_uploader("Upload Claims Recoveries Data", key="claims_recoveries")
|
| 232 |
+
with upload_col3:
|
| 233 |
+
uploaded_file_claims_count = st.file_uploader("Upload Claims Count Data", key="claims_count")
|
| 234 |
|
|
|
|
|
|
|
| 235 |
button_col1, button_col2, button_col3 = st.columns(3)
|
| 236 |
with button_col1:
|
| 237 |
if uploaded_file_premiums and st.button("Select Premiums columns"):
|
| 238 |
+
process_file(uploaded_file_premiums, 'premiums')
|
| 239 |
with button_col2:
|
| 240 |
if uploaded_file_claims_recoveries:
|
| 241 |
if st.button("Select Incurred claims columns"):
|
| 242 |
+
process_file(uploaded_file_claims_recoveries, 'claims_recoveries')
|
| 243 |
if st.button("Select Recoveries columns"):
|
| 244 |
+
process_file(uploaded_file_claims_recoveries, 'claims_recoveries')
|
|
|
|
| 245 |
with button_col3:
|
| 246 |
if uploaded_file_claims_count and st.button("Select Claims count columns"):
|
| 247 |
+
process_file(uploaded_file_claims_count, 'claims_count')
|
| 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'
|