Spaces:
Runtime error
Runtime error
Update app.py
Browse files100 unmodified lines1011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471484 unmodified lines153154155156157158100 unmodified linesfile = st.file_uploader("Upload an excel file", type=['xlsx'])review_column = Nonedf = Noneclass_names = None # New variable for class namesif file is not None:try:chunk_size = 10000 # adjust this value depending on your available memorydf = pd.concat(pd.read_excel(file, chunksize=chunk_size))# 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.")returnstart_button = st.button('Start Analysis')if 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() != '']class_names = [name.strip() for name in class_names.split(',')] # Split class names into a listfor name in class_names: # Add a new column for each class nameif name not in df.columns:df[name] = 0.0if review_column in df.columns:with st.spinner('Performing sentiment analysis...'):df, df_display = process_reviews(df, review_column, class_names)display_ratings(df, review_column) # updated this linedisplay_dataframe(df, df_display)else:st.write(f'No column named "{review_column}" found in the uploaded file.')4 unmodified linesdef process_reviews(df, review_column, class_names):with st.spinner('Classifying reviews...'):progress_bar = st.progress(0)100 unmodified lines1011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411424 unmodified lines147148149150151152153100 unmodified linesfile = st.file_uploader("Upload an excel file", type=['xlsx'])review_column = Nonedf = Noneclass_names = Noneif file is not None:try:chunk_size = 10000 # adjust this value depending on your available memorydf = pd.concat(pd.read_excel(file, chunksize=chunk_size))df = df.dropna(how='all')df = 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)')filter_words = [] if filter_words_input.strip() == "" else process_filter_words(filter_words_input)class_names = st.text_input('Enter the possible class names separated by comma')df = filter_dataframe(df, review_column, filter_words)except Exception as e:st.write("An error occurred while reading the uploaded file. Please make sure it's a valid Excel file.")returnstart_button = st.button('Start Analysis')if start_button and df is not None:df = df[df[review_column].notna()]df = df[df[review_column].str.strip() != '']class_names = [name.strip() for name in class_names.split(',')]for name in class_names:if name not in df.columns:df[name] = 0.0if review_column in df.columns:with st.spinner('Performing sentiment analysis...'):df, df_display = process_reviews(df, review_column, class_names)display_ratings(df, review_column)display_dataframe(df, df_display)else:st.write(f'No column named "{review_column}" found in the uploaded file.')4 unmodified linesdef process_reviews(df, review_column, class_names):with st.spinner('Classifying reviews...'):progress_bar = st.progress(0)
app.py+12-17