BulatF commited on
Commit
8a6b406
1 Parent(s): 5580d32

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -17
app.py CHANGED
@@ -101,48 +101,42 @@ def main():
101
  file = st.file_uploader("Upload an excel file", type=['xlsx'])
102
  review_column = None
103
  df = None
104
- class_names = None # New variable for class names
105
 
106
  if file is not None:
107
  try:
108
  chunk_size = 10000 # adjust this value depending on your available memory
109
  df = pd.concat(pd.read_excel(file, chunksize=chunk_size))
110
-
111
- # Drop rows where all columns are NaN
112
  df = df.dropna(how='all')
113
- # Replace blank spaces with NaN, then drop rows where all columns are NaN again
114
  df = df.replace(r'^\s*$', np.nan, regex=True)
115
  df = df.dropna(how='all')
116
  review_column = st.selectbox('Select the column from your excel file containing text', df.columns)
117
  df[review_column] = df[review_column].astype(str)
118
 
119
-
120
- filter_words_input = st.text_input('Enter words to filter the data by, separated by comma (or leave empty)') # New input field for filter words
121
- filter_words = [] if filter_words_input.strip() == "" else process_filter_words(filter_words_input) # Process the filter words
122
- class_names = st.text_input('Enter the possible class names separated by comma') # New input field for class names
123
- df = filter_dataframe(df, review_column, filter_words) # Filter the DataFrame
124
  except Exception as e:
125
  st.write("An error occurred while reading the uploaded file. Please make sure it's a valid Excel file.")
126
  return
127
 
128
  start_button = st.button('Start Analysis')
129
 
130
-
131
  if start_button and df is not None:
132
- # Drop rows with NaN or blank values in the review_column
133
  df = df[df[review_column].notna()]
134
  df = df[df[review_column].str.strip() != '']
135
-
136
- class_names = [name.strip() for name in class_names.split(',')] # Split class names into a list
137
- for name in class_names: # Add a new column for each class name
138
  if name not in df.columns:
139
  df[name] = 0.0
140
-
141
  if review_column in df.columns:
142
  with st.spinner('Performing sentiment analysis...'):
143
  df, df_display = process_reviews(df, review_column, class_names)
144
-
145
- display_ratings(df, review_column) # updated this line
146
  display_dataframe(df, df_display)
147
  else:
148
  st.write(f'No column named "{review_column}" found in the uploaded file.')
@@ -153,6 +147,7 @@ def main():
153
 
154
 
155
 
 
156
  def process_reviews(df, review_column, class_names):
157
  with st.spinner('Classifying reviews...'):
158
  progress_bar = st.progress(0)
 
101
  file = st.file_uploader("Upload an excel file", type=['xlsx'])
102
  review_column = None
103
  df = None
104
+ class_names = None
105
 
106
  if file is not None:
107
  try:
108
  chunk_size = 10000 # adjust this value depending on your available memory
109
  df = pd.concat(pd.read_excel(file, chunksize=chunk_size))
 
 
110
  df = df.dropna(how='all')
 
111
  df = df.replace(r'^\s*$', np.nan, regex=True)
112
  df = df.dropna(how='all')
113
  review_column = st.selectbox('Select the column from your excel file containing text', df.columns)
114
  df[review_column] = df[review_column].astype(str)
115
 
116
+ filter_words_input = st.text_input('Enter words to filter the data by, separated by comma (or leave empty)')
117
+ filter_words = [] if filter_words_input.strip() == "" else process_filter_words(filter_words_input)
118
+ class_names = st.text_input('Enter the possible class names separated by comma')
119
+ df = filter_dataframe(df, review_column, filter_words)
 
120
  except Exception as e:
121
  st.write("An error occurred while reading the uploaded file. Please make sure it's a valid Excel file.")
122
  return
123
 
124
  start_button = st.button('Start Analysis')
125
 
 
126
  if start_button and df is not None:
 
127
  df = df[df[review_column].notna()]
128
  df = df[df[review_column].str.strip() != '']
129
+
130
+ class_names = [name.strip() for name in class_names.split(',')]
131
+ for name in class_names:
132
  if name not in df.columns:
133
  df[name] = 0.0
134
+
135
  if review_column in df.columns:
136
  with st.spinner('Performing sentiment analysis...'):
137
  df, df_display = process_reviews(df, review_column, class_names)
138
+
139
+ display_ratings(df, review_column)
140
  display_dataframe(df, df_display)
141
  else:
142
  st.write(f'No column named "{review_column}" found in the uploaded file.')
 
147
 
148
 
149
 
150
+
151
  def process_reviews(df, review_column, class_names):
152
  with st.spinner('Classifying reviews...'):
153
  progress_bar = st.progress(0)