Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import pandas as pd | |
| import io | |
| def get_sheet_names(file) -> list[str]: | |
| """Return the sheet names of an Excel file.""" | |
| excel_file = pd.ExcelFile(file) | |
| return excel_file.sheet_names | |
| def load_df(file, sheet_name): | |
| """Read a sheet from an Excel file into a DataFrame and cache the result.""" | |
| return pd.read_excel(file, sheet_name=sheet_name) | |
| buffer = io.BytesIO() | |
| def main(): | |
| # Create columns | |
| main_col1, main_col2 = st.columns([3, 7]) | |
| # File uploader | |
| with main_col1: | |
| uploaded_file = st.file_uploader("Choose an Excel file", type=['xlsx', 'xls']) | |
| if uploaded_file is not None: | |
| # ✅ Only caching serializable sheet names | |
| sheet_names = get_sheet_names(uploaded_file) | |
| selected_sheet = st.selectbox("Select a sheet", options=sheet_names, index=0) | |
| # ✅ Cache the DataFrame (serializable) | |
| df = load_df(uploaded_file, selected_sheet) | |
| st.write(df) | |
| # Display the uploaded file's contents in the second column | |
| with main_col2: | |
| if uploaded_file is not None: | |
| # Configure multiselects based on uploaded DataFrame columns | |
| columns = list(df.columns) | |
| selected_gstin = st.multiselect("GST Identification Number (GSTIN)", columns, default=columns) | |
| if __name__ == "__main__": | |
| st.set_page_config(layout="wide") | |
| main() | |