BulatF commited on
Commit
3ce85f6
·
1 Parent(s): 4d924ac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -10,7 +10,7 @@ import io
10
  import base64
11
  from stqdm import stqdm
12
  import nltk
13
-
14
  from nltk.corpus import stopwords
15
  nltk.download('stopwords')
16
  import matplotlib.pyplot as plt
@@ -89,17 +89,21 @@ def main():
89
  st.title('Sentiment Analysis')
90
  st.markdown('Upload an Excel file to get sentiment analytics')
91
 
92
- file = st.file_uploader("Upload an excel file", type=['xlsx'])
93
  review_column = None
94
  df = None
95
  class_names = None # New variable for class names
96
 
97
- if file is not None:
 
 
 
 
98
  try:
99
  # Reading Excel file in chunks
100
  chunk_size = 1000 # you can adjust this value according to your memory
101
  chunks = []
102
- for chunk in pd.read_excel(file, chunksize=chunk_size):
103
  chunk = chunk.dropna(how='all')
104
  chunk = chunk.replace(r'^\s*$', np.nan, regex=True)
105
  chunk = chunk.dropna(how='all')
@@ -265,7 +269,8 @@ def display_ratings(df, review_column):
265
 
266
 
267
 
268
-
 
269
 
270
  if __name__ == "__main__":
271
  main()
 
10
  import base64
11
  from stqdm import stqdm
12
  import nltk
13
+ import tempfile
14
  from nltk.corpus import stopwords
15
  nltk.download('stopwords')
16
  import matplotlib.pyplot as plt
 
89
  st.title('Sentiment Analysis')
90
  st.markdown('Upload an Excel file to get sentiment analytics')
91
 
92
+ uploaded_file = st.file_uploader("Upload an excel file", type=['xlsx'])
93
  review_column = None
94
  df = None
95
  class_names = None # New variable for class names
96
 
97
+ if uploaded_file is not None:
98
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".xlsx") as tmp:
99
+ tmp.write(uploaded_file.getvalue())
100
+ tmp_file_name = tmp.name
101
+
102
  try:
103
  # Reading Excel file in chunks
104
  chunk_size = 1000 # you can adjust this value according to your memory
105
  chunks = []
106
+ for chunk in pd.read_excel(tmp_file_name, chunksize=chunk_size):
107
  chunk = chunk.dropna(how='all')
108
  chunk = chunk.replace(r'^\s*$', np.nan, regex=True)
109
  chunk = chunk.dropna(how='all')
 
269
 
270
 
271
 
272
+ # At the end of your code, or after you have finished processing the file
273
+ os.remove(tmp_file_name)
274
 
275
  if __name__ == "__main__":
276
  main()