Spaces:
Sleeping
Sleeping
File size: 1,504 Bytes
c4478d6 | 1 2 3 4 5 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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | import streamlit as st
import pandas as pd
import io
@st.cache_data(show_spinner=False)
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
@st.cache_data(show_spinner=False)
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()
|