Spaces:
Runtime error
Runtime error
Update app.py
Browse files95 unmodified lines969798991001011021031041051061071081091101111121131141152 unmodified lines11811912012112212312495 unmodified linesif file is not None:try:df = pd.read_excel(file)# Drop rows where all columns are NaNdf = df.dropna(how='all')# Replace blank spaces with NaN, then drop rows where all columns are NaN againdf = df.replace(r'^\s*$', np.nan, regex=True)df = df.dropna(how='all')review_column = st.selectbox('Select the column from your excel file containing text', df.columns)df[review_column] = df[review_column].astype(str)filter_words_input = st.text_input('Enter words to filter the data by, separated by comma (or leave empty)') # New input field for filter wordsfilter_words = [] if filter_words_input.strip() == "" else process_filter_words(filter_words_input) # Process the filter wordsclass_names = st.text_input('Enter the possible class names separated by comma') # New input field for class namesdf = filter_dataframe(df, review_column, filter_words) # Filter the DataFrameexcept Exception as e:st.write("An error occurred while reading the uploaded file. Please make sure it's a valid Excel file.")return2 unmodified linesif start_button and df is not None:# Drop rows with NaN or blank values in the review_columndf = df[df[review_column].notna()]df = df[df[review_column].str.strip() != '']95 unmodified lines969798991001011021031041051061071081091101111121131141151161171181192 unmodified lines12212312412512612795 unmodified linesif file is not None:try:# Reading Excel file in chunkschunk_size = 1000 # you can adjust this value according to your memorychunks = []for chunk in pd.read_excel(file, chunksize=chunk_size):chunk = chunk.dropna(how='all')chunk = chunk.replace(r'^\s*$', np.nan, regex=True)chunk = chunk.dropna(how='all')review_column = st.selectbox('Select the column from your excel file containing text', chunk.columns)chunk[review_column] = chunk[review_column].astype(str)filter_words_input = st.text_input('Enter words to filter the data by, separated by comma (or leave empty)') # New input field for filter wordsfilter_words = [] if filter_words_input.strip() == "" else process_filter_words(filter_words_input) # Process the filter wordsclass_names = st.text_input('Enter the possible class names separated by comma') # New input field for class nameschunk = filter_dataframe(chunk, review_column, filter_words) # Filter the DataFramechunks.append(chunk)df = pd.concat(chunks, ignore_index=True)except Exception as e:st.write("An error occurred while reading the uploaded file. Please make sure it's a valid Excel file.")return2 unmodified linesif start_button and df is not None:df = df[df[review_column].notna()]df = df[df[review_column].str.strip() != '']
app.py+17-14