Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,279 +4,27 @@ import streamlit as st
|
|
| 4 |
st.markdown("# Main Page 🏠")
|
| 5 |
st.sidebar.markdown("## Main Page 🏠")
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
#
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
#
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
# # First row with three text components
|
| 32 |
-
# col1, col2, col3 = st.columns(3)
|
| 33 |
-
# with col1:
|
| 34 |
-
# header('Premiums','h3')
|
| 35 |
-
# with col2:
|
| 36 |
-
# header("Incurred Claims & Recoveries Data",'h3')
|
| 37 |
-
# with col3:
|
| 38 |
-
# header("Claims Count",'h3')
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
# # Second row with three file upload buttons
|
| 59 |
-
# upload_col1, upload_col2, upload_col3 = st.columns(3)
|
| 60 |
-
# with upload_col1:
|
| 61 |
-
# uploaded_file_premiums = st.file_uploader("", key="premiums")
|
| 62 |
-
# with upload_col2:
|
| 63 |
-
# uploaded_file_claims_recoveries = st.file_uploader("", key="claims_recoveries")
|
| 64 |
-
# with upload_col3:
|
| 65 |
-
# uploaded_file_claims_count = st.file_uploader("", key="claims_count")
|
| 66 |
-
|
| 67 |
-
# # Third row with three buttons, enabled only if the corresponding file is uploaded
|
| 68 |
-
# button_col1, button_col2, button_col3 = st.columns(3)
|
| 69 |
-
# premiumlabel = "Select Premiums columns"
|
| 70 |
-
# incurredlabel = "Select Incurred claims columns"
|
| 71 |
-
# recoverlabel = "Select Recoveries columns"
|
| 72 |
-
# claimscount = "Select Claims count columns"
|
| 73 |
-
|
| 74 |
-
# def process_premiums_file(uploaded_file):
|
| 75 |
-
# # Read the CSV file into a DataFrame
|
| 76 |
-
# df = pd.read_csv(uploaded_file)
|
| 77 |
-
|
| 78 |
-
# # Store the DataFrame in the session state
|
| 79 |
-
# st.session_state['premiums_df'] = df
|
| 80 |
-
|
| 81 |
-
# # Indicate that the CSV has been processed and we're ready to select columns
|
| 82 |
-
# st.session_state['select_columns'] = True
|
| 83 |
-
|
| 84 |
-
# # Button to select premiums, only displayed and active if a file has been uploaded
|
| 85 |
-
# with button_col1:
|
| 86 |
-
# # Check if the file has been uploaded
|
| 87 |
-
# file_uploaded = uploaded_file_premiums is not None
|
| 88 |
-
# # The button is enabled if a file has been uploaded, and disabled otherwise
|
| 89 |
-
# if st.button(premiumlabel, disabled=not file_uploaded, key="premiums_button"):
|
| 90 |
-
# # If the button is clicked (active), call the callback function
|
| 91 |
-
# process_premiums_file(uploaded_file_premiums)
|
| 92 |
-
|
| 93 |
-
# with button_col2:
|
| 94 |
-
# if uploaded_file_claims_recoveries is not None:
|
| 95 |
-
# st.button(incurredlabel)
|
| 96 |
-
# st.button(recoverlabel)
|
| 97 |
-
# else:
|
| 98 |
-
# st.button(incurredlabel, disabled=True)
|
| 99 |
-
# st.button(recoverlabel, disabled=True)
|
| 100 |
-
|
| 101 |
-
# with button_col3:
|
| 102 |
-
# if uploaded_file_claims_count is not None:
|
| 103 |
-
# st.button(claimscount)
|
| 104 |
-
# else:
|
| 105 |
-
# st.button(claimscount, disabled=True)
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
# # If the CSV has been processed, display the column selection UI
|
| 109 |
-
# if st.session_state.get('select_columns', False):
|
| 110 |
-
# st.empty()
|
| 111 |
-
# st.write("Please choose the 'lob' column and the values to filter by:")
|
| 112 |
-
|
| 113 |
-
# # Determine columns with only string values and where no value is mostly numeric
|
| 114 |
-
# string_columns = [
|
| 115 |
-
# col for col in st.session_state['premiums_df'].columns
|
| 116 |
-
# if not any(not isinstance(x, str) or is_mostly_numeric(x) for x in st.session_state['premiums_df'][col].dropna())
|
| 117 |
-
# ]
|
| 118 |
-
|
| 119 |
-
# # Create two columns: one for the 'lob' column dropdown, one for the checkboxes
|
| 120 |
-
# col1, col2 = st.columns(2)
|
| 121 |
-
|
| 122 |
-
# # Dropdown to select the 'lob' column, filtered to only string columns
|
| 123 |
-
# with col1:
|
| 124 |
-
# lob_column = st.selectbox('Choose the column for "lob":', string_columns, key='lob_column')
|
| 125 |
-
# # Initialize an empty list to hold the selected values
|
| 126 |
-
# selected_lob_values = []
|
| 127 |
-
|
| 128 |
-
# # Generate checkboxes for each unique value in the 'lob' column
|
| 129 |
-
# with col2:
|
| 130 |
-
# st.write("Select values for filtering:")
|
| 131 |
-
# # Ensure that 'lob_column' is in the session state and it's in the DataFrame columns
|
| 132 |
-
# if 'lob_column' in st.session_state and st.session_state['lob_column'] in st.session_state['premiums_df'].columns:
|
| 133 |
-
# # Retrieve unique values from the 'lob' column
|
| 134 |
-
# unique_values = st.session_state['premiums_df'][st.session_state['lob_column']].unique()
|
| 135 |
-
# # Sort the values for consistent checkbox ordering
|
| 136 |
-
# unique_values.sort()
|
| 137 |
-
# for value in unique_values:
|
| 138 |
-
# # Create a checkbox for each unique value in the 'lob' column
|
| 139 |
-
# if st.checkbox(f"{value}", key=f"checkbox_{value}"):
|
| 140 |
-
# selected_lob_values.append(value)
|
| 141 |
-
|
| 142 |
-
# # Filter the DataFrame based on selected 'lob' values
|
| 143 |
-
# if selected_lob_values:
|
| 144 |
-
# filtered_df = st.session_state['premiums_df'][st.session_state['premiums_df'][lob_column].isin(selected_lob_values)]
|
| 145 |
-
# st.session_state['filtered_premiums_df'] = filtered_df
|
| 146 |
-
|
| 147 |
-
# # Display other column selections after 'lob' has been selected and DataFrame has been filtered
|
| 148 |
-
# st.write("Now, select the columns for other parameters:")
|
| 149 |
-
# valuation_as_at = st.selectbox('Valuation As At:', filtered_df.columns, key='valuation_as_at')
|
| 150 |
-
# quarter_bracket = st.selectbox('Quarter Bracket:', filtered_df.columns, key='quarter_bracket')
|
| 151 |
-
# # Continue with other selections as required...
|
| 152 |
-
|
| 153 |
-
# # Store the column selections in the session state
|
| 154 |
-
# st.session_state['column_selections'] = {
|
| 155 |
-
# 'valuation_as_at': valuation_as_at,
|
| 156 |
-
# 'quarter_bracket': quarter_bracket,
|
| 157 |
-
# # ... include other selections as well
|
| 158 |
-
# }
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
# # Initialize session state variables
|
| 181 |
-
# st.session_state.setdefault('current_page', 'home')
|
| 182 |
-
# st.session_state.setdefault('premiums_df', None)
|
| 183 |
-
# st.session_state.setdefault('claims_recoveries_df', None)
|
| 184 |
-
# st.session_state.setdefault('claims_count_df', None)
|
| 185 |
-
# st.session_state.setdefault('back_to_home', False) # Flag for back to home button
|
| 186 |
-
|
| 187 |
-
# # Helper function to check if a string has more than 50% numeric characters
|
| 188 |
-
# def is_mostly_numeric(s):
|
| 189 |
-
# if isinstance(s, str):
|
| 190 |
-
# num_numeric = sum(c.isdigit() for c in s)
|
| 191 |
-
# percent_numeric = num_numeric / len(s) if s else 0
|
| 192 |
-
# return percent_numeric > 0.5
|
| 193 |
-
# return False
|
| 194 |
-
|
| 195 |
-
# def process_file(uploaded_file, key):
|
| 196 |
-
# df = pd.read_csv(uploaded_file)
|
| 197 |
-
# st.session_state[key + '_df'] = df
|
| 198 |
-
# st.session_state['current_page'] = key + '_selection'
|
| 199 |
-
|
| 200 |
-
# # Function to display the column selection UI
|
| 201 |
-
# def column_selection_ui(dataframe_key, selection_key):
|
| 202 |
-
# st.write(f"Please choose the 'lob' column and the values to filter by for {selection_key}:")
|
| 203 |
-
|
| 204 |
-
# string_columns = [
|
| 205 |
-
# col for col in st.session_state[dataframe_key].columns
|
| 206 |
-
# if not any(not isinstance(x, str) or is_mostly_numeric(x) for x in st.session_state[dataframe_key][col].dropna())
|
| 207 |
-
# ]
|
| 208 |
-
|
| 209 |
-
# col1, col2 = st.columns(2)
|
| 210 |
-
# with col1:
|
| 211 |
-
# lob_column = st.selectbox('Choose the column for "lob":', string_columns, key=f'lob_column_{selection_key}')
|
| 212 |
-
# selected_lob_values = []
|
| 213 |
-
|
| 214 |
-
# with col2:
|
| 215 |
-
# st.write("Select values for filtering:")
|
| 216 |
-
# if lob_column in st.session_state[dataframe_key].columns:
|
| 217 |
-
# unique_values = st.session_state[dataframe_key][lob_column].unique()
|
| 218 |
-
# unique_values.sort()
|
| 219 |
-
# for value in unique_values:
|
| 220 |
-
# if st.checkbox(f"{value}", key=f"checkbox_{value}_{selection_key}"):
|
| 221 |
-
# selected_lob_values.append(value)
|
| 222 |
-
|
| 223 |
-
# # Initialize the variables to prevent UnboundLocalError
|
| 224 |
-
# valuation_as_at = None
|
| 225 |
-
# quarter_bracket = None
|
| 226 |
-
|
| 227 |
-
# # Filter the DataFrame based on selected 'lob' values
|
| 228 |
-
# if selected_lob_values:
|
| 229 |
-
# filtered_df = st.session_state[dataframe_key][st.session_state[dataframe_key][lob_column].isin(selected_lob_values)]
|
| 230 |
-
# st.session_state['filtered_' + dataframe_key] = filtered_df
|
| 231 |
-
|
| 232 |
-
# # Display other column selections after 'lob' has been selected and DataFrame has been filtered
|
| 233 |
-
# st.write("Now, select the columns for other parameters:")
|
| 234 |
-
# valuation_as_at = st.selectbox('Valuation As At:', filtered_df.columns, key='valuation_as_at_' + selection_key)
|
| 235 |
-
# quarter_bracket = st.selectbox('Quarter Bracket:', filtered_df.columns, key='quarter_bracket_' + selection_key)
|
| 236 |
-
|
| 237 |
-
# # Store the column selections in the session state
|
| 238 |
-
# st.session_state[f'{selection_key}_selections'] = {
|
| 239 |
-
# 'lob_column': lob_column,
|
| 240 |
-
# 'selected_lob_values': selected_lob_values,
|
| 241 |
-
# 'valuation_as_at': valuation_as_at,
|
| 242 |
-
# 'quarter_bracket': quarter_bracket,
|
| 243 |
-
# }
|
| 244 |
-
|
| 245 |
-
# # File uploaders and buttons
|
| 246 |
-
# if st.session_state.current_page == 'home':
|
| 247 |
-
# upload_col1, upload_col2, upload_col3 = st.columns(3)
|
| 248 |
-
# with upload_col1:
|
| 249 |
-
# uploaded_file_premiums = st.file_uploader("Upload Premiums Data", key="premiums_file")
|
| 250 |
-
# with upload_col2:
|
| 251 |
-
# uploaded_file_claims_recoveries = st.file_uploader("Upload Claims Recoveries Data", key="claims_recoveries_file")
|
| 252 |
-
# with upload_col3:
|
| 253 |
-
# uploaded_file_claims_count = st.file_uploader("Upload Claims Count Data", key="claims_count_file")
|
| 254 |
-
|
| 255 |
-
# button_col1, button_col2, button_col3 = st.columns(3)
|
| 256 |
-
# with button_col1:
|
| 257 |
-
# if uploaded_file_premiums and st.button("Select Premiums columns"):
|
| 258 |
-
# process_file(uploaded_file_premiums, 'premiums')
|
| 259 |
-
# with button_col2:
|
| 260 |
-
# if uploaded_file_claims_recoveries:
|
| 261 |
-
# if st.button("Select Incurred claims columns"):
|
| 262 |
-
# process_file(uploaded_file_claims_recoveries, 'claims_recoveries')
|
| 263 |
-
# if st.button("Select Recoveries columns"):
|
| 264 |
-
# process_file(uploaded_file_claims_recoveries, 'claims_recoveries')
|
| 265 |
-
# with button_col3:
|
| 266 |
-
# if uploaded_file_claims_count and st.button("Select Claims count columns"):
|
| 267 |
-
# process_file(uploaded_file_claims_count, 'claims_count')
|
| 268 |
-
|
| 269 |
-
# # Conditional rendering based on the current page
|
| 270 |
-
# if st.session_state.current_page.endswith('_selection'):
|
| 271 |
-
# dataframe_key = st.session_state.current_page.replace('_selection', '_df')
|
| 272 |
-
# column_selection_ui(dataframe_key, dataframe_key.replace('_df', ''))
|
| 273 |
-
|
| 274 |
-
# # Back to Home button
|
| 275 |
-
# if st.session_state.current_page != 'home':
|
| 276 |
-
# if st.button("Back to Home"):
|
| 277 |
-
# st.session_state['back_to_home'] = True
|
| 278 |
-
|
| 279 |
-
# # Handling the back to home action
|
| 280 |
-
# if st.session_state['back_to_home']:
|
| 281 |
-
# st.session_state['current_page'] = 'home'
|
| 282 |
-
# st.session_state['back_to_home'] = False
|
|
|
|
| 4 |
st.markdown("# Main Page 🏠")
|
| 5 |
st.sidebar.markdown("## Main Page 🏠")
|
| 6 |
|
| 7 |
+
# streamlit_app.py
|
| 8 |
+
import streamlit as st
|
| 9 |
+
import page_1
|
| 10 |
+
import page_2
|
| 11 |
+
|
| 12 |
+
# Initialize session state
|
| 13 |
+
if 'page' not in st.session_state:
|
| 14 |
+
st.session_state.page = 'main'
|
| 15 |
+
|
| 16 |
+
# Main Page
|
| 17 |
+
if st.session_state.page == 'main':
|
| 18 |
+
st.markdown("# Main Page 🏠")
|
| 19 |
+
if st.button('Go to Page 1'):
|
| 20 |
+
st.session_state.page = 'page_1'
|
| 21 |
+
elif st.button('Go to Page 2'):
|
| 22 |
+
st.session_state.page = 'page_2'
|
| 23 |
+
|
| 24 |
+
# Page 1
|
| 25 |
+
elif st.session_state.page == 'page_1':
|
| 26 |
+
page_1.run()
|
| 27 |
+
|
| 28 |
+
# Page 2
|
| 29 |
+
elif st.session_state.page == 'page_2':
|
| 30 |
+
page_2.run()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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