nlpblogs commited on
Commit
645880e
·
verified ·
1 Parent(s): caa0733

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -42
app.py CHANGED
@@ -141,47 +141,6 @@ if st.button("Sentiment Analysis", type="secondary"):
141
  df = pd.DataFrame(data, columns=["User ID", "Comment", "comment_date"])
142
  st.dataframe(df)
143
 
144
- if tokenizer and model:
145
- inputs = tokenizer(df['Comment'].tolist(), return_tensors="pt", padding=True, truncation=True)
146
- with torch.no_grad():
147
- logits = model(**inputs).logits
148
- predicted_probabilities = torch.nn.functional.softmax(logits, dim=-1)
149
- predicted_labels = predicted_probabilities.argmax(dim=1)
150
- results = []
151
- for i, label in enumerate(predicted_labels):
152
- results.append({'Review Number': i + 1, 'Sentiment': model.config.id2label[label.item()]})
153
- sentiment_df = pd.DataFrame(results)
154
-
155
- value_counts1 = sentiment_df['Sentiment'].value_counts().rename_axis('Sentiment').reset_index(name='count')
156
- final_df = value_counts1
157
- tab1, tab2 = st.tabs(["Pie Chart", "Bar Chart"])
158
- with tab1:
159
- fig1 = px.pie(final_df, values='count', names='Sentiment', hover_data=['count'], labels={'count': 'count'})
160
- fig1.update_traces(textposition='inside', textinfo='percent+label')
161
- st.plotly_chart(fig1)
162
-
163
- result = pd.concat([df, sentiment_df], axis=1)
164
- st.dataframe(result)
165
-
166
- with tab2:
167
- fig2 = px.bar(result, x="Sentiment", y="comment_date", color="Sentiment")
168
- st.plotly_chart(fig2)
169
-
170
- csv = result.to_csv(index=False)
171
- st.download_button(
172
- label="Download data as CSV",
173
- data=csv,
174
- file_name='Summary of the results.csv',
175
- mime='text/csv',
176
- )
177
-
178
- else:
179
- st.warning("Please enter a URL.")
180
- else:
181
- st.warning(f"You have reached the maximum URL attempts ({max_attempts}).")
182
-
183
- if 'url_count' in st.session_state: #added if statement.
184
- st.write(f"URL pasted {st.session_state['url_count']} times.")
185
-
186
 
187
 
 
141
  df = pd.DataFrame(data, columns=["User ID", "Comment", "comment_date"])
142
  st.dataframe(df)
143
 
144
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145
 
146