Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import pandas as pd | |
| st.set_page_config(layout="wide") | |
| st.markdown("<h1 style='text-align: center;'>حسن xxx دحوم</h1>", unsafe_allow_html=True) | |
| def header(text,h='h2'): | |
| return st.markdown(f"<{h} style='text-align: center;'>{text}</{h}>", unsafe_allow_html=True) | |
| # First row with three text components | |
| col1, col2, col3 = st.columns(3) | |
| with col1: | |
| header('Premiums','h3') | |
| with col2: | |
| header("Incurred Claims & Recoveries Data",'h3') | |
| with col3: | |
| header("Claims Count",'h3') | |
| # Second row with three file upload buttons | |
| upload_col1, upload_col2, upload_col3 = st.columns(3) | |
| with upload_col1: | |
| uploaded_file_premiums = st.file_uploader("", key="premiums") | |
| with upload_col2: | |
| uploaded_file_claims_recoveries = st.file_uploader("", key="claims_recoveries") | |
| with upload_col3: | |
| uploaded_file_claims_count = st.file_uploader("", key="claims_count") | |
| # Third row with three buttons, enabled only if the corresponding file is uploaded | |
| button_col1, button_col2, button_col3 = st.columns(3) | |
| premiumlabel = "Select Premiums columns" | |
| incurredlabel = "Select Incurred claims columns" | |
| recoverlabel = "Select Recoveries columns" | |
| claimscount = "Select Claims count columns" | |
| with button_col1: | |
| if uploaded_file_premiums is not None: | |
| st.button(premiumlabel) | |
| else: | |
| st.button(premiumlabel, disabled=True) | |
| def process_premiums_file(uploaded_file): | |
| # Read the CSV file into a DataFrame | |
| df = pd.read_csv(uploaded_file) | |
| # Store the DataFrame in the session state | |
| st.session_state['premiums_df'] = df | |
| # Indicate that the CSV has been processed and we're ready to select columns | |
| st.session_state['select_columns'] = True | |
| # Button to select premiums, only enabled if a file has been uploaded | |
| with button_col1: | |
| if uploaded_file_premiums is not None: | |
| if st.button(premiumlabel): | |
| process_premiums_file(uploaded_file_premiums) | |
| else: | |
| st.button(premiumlabel, disabled=True) | |
| with button_col2: | |
| if uploaded_file_claims_recoveries is not None: | |
| st.button(incurredlabel) | |
| st.button(recoverlabel) | |
| else: | |
| st.button(incurredlabel, disabled=True) | |
| st.button(recoverlabel, disabled=True) | |
| with button_col3: | |
| if uploaded_file_claims_count is not None: | |
| st.button(claimscount) | |
| else: | |
| st.button(claimscount, disabled=True) | |
| # If the CSV has been processed, display the column selection UI | |
| if st.session_state.get('select_columns', False): | |
| st.write("Please choose the 'lob' column and the values to filter by:") | |
| # Dropdown to select the 'lob' column | |
| lob_column = st.selectbox('Choose the column for "lob":', st.session_state['premiums_df'].columns) | |
| # Multiselect to choose values from the 'lob' column to filter the DataFrame | |
| selected_lob_values = st.multiselect('Choose values from the "lob" column:', | |
| st.session_state['premiums_df'][lob_column].unique()) | |
| # Filter the DataFrame based on selected 'lob' values | |
| if selected_lob_values: | |
| filtered_df = st.session_state['premiums_df'][st.session_state['premiums_df'][lob_column].isin(selected_lob_values)] | |
| st.session_state['filtered_premiums_df'] = filtered_df | |
| # Display other column selections after 'lob' has been selected and DataFrame has been filtered | |
| st.write("Now, select the columns for other parameters:") | |
| valuation_as_at = st.selectbox('Valuation As At:', filtered_df.columns) | |
| quarter_bracket = st.selectbox('Quarter Bracket:', filtered_df.columns) | |
| # Continue with other selections as required... | |
| # Store the column selections in the session state | |
| st.session_state['column_selections'] = { | |
| 'valuation_as_at': valuation_as_at, | |
| 'quarter_bracket': quarter_bracket, | |
| # ... include other selections as well | |
| } | |