aisyahhrazak commited on
Commit
8ce4957
1 Parent(s): 01c4e47

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -12
app.py CHANGED
@@ -184,16 +184,15 @@ def generate_report(tpb_sentiment_df):
184
 
185
  def search_company(keyword):
186
  if not keyword:
187
- return None, None, None, None
188
-
189
  filtered_df = df[df['text'].str.contains(keyword, case=False)]
190
 
191
  if filtered_df.empty:
192
- return None, None, None, None
193
-
194
  # Calculate sentiment distribution
195
  sentiment_counts = filtered_df['label'].value_counts(normalize=True) * 100
196
-
197
  colors = ['red' if sentiment == 'negative' else 'gray' if sentiment == 'neutral' else 'blue' for sentiment in sentiment_counts.index]
198
 
199
  # Create the bar plot
@@ -204,7 +203,6 @@ def search_company(keyword):
204
  textposition='auto',
205
  marker_color=colors
206
  )])
207
-
208
  sentiment_fig.update_layout(
209
  title='Overall Sentiment Distribution',
210
  xaxis_title='Sentiment',
@@ -224,7 +222,6 @@ def search_company(keyword):
224
  tpb_sentiment_df = filtered_df.groupby(['tpb_label', 'label']).size().unstack(fill_value=0)
225
  tpb_sentiment_df = tpb_sentiment_df.div(tpb_sentiment_df.sum(axis=1), axis=0) * 100
226
 
227
- # Define colors for each sentiment
228
  color_map = {
229
  'negative': 'red',
230
  'neutral': 'gray',
@@ -258,23 +255,19 @@ def search_company(keyword):
258
  wordclouds[label] = generate_wordcloud(text)
259
  bigrams_data[label] = generate_bigrams(text)
260
 
261
- # Extract only the words
262
  words_only = {
263
  key: [word_pair for word_pair, _ in value]
264
  for key, value in bigrams_data.items()
265
  }
266
- # Create a single DataFrame for bigrams, with only the bigram text (no frequency)
267
  bigram_df = pd.DataFrame({
268
  label: data for label, data in words_only.items()
269
  })
270
 
271
- print(bigrams_data.items())
272
  bigram_df.index = [f"Top {i+1}" for i in range(len(bigram_df))]
273
 
274
  return (sentiment_fig, tpb_fig, tpb_sentiment_fig, filtered_df[filtered_df['text'].str.len() < 300].head(5),
275
  report, wordclouds.get('attitude'), wordclouds.get('religious knowledge'),
276
- wordclouds.get('subjective norms'), wordclouds.get('perceived behavioural control'),bigram_df)
277
-
278
 
279
 
280
  def text_classification_and_sentiment(text, keywords_df):
 
184
 
185
  def search_company(keyword):
186
  if not keyword:
187
+ return None, None, None, None, None, None, None, None, None, None
188
+
189
  filtered_df = df[df['text'].str.contains(keyword, case=False)]
190
 
191
  if filtered_df.empty:
192
+ return None, None, None, None, None, None, None, None, None, None
193
+
194
  # Calculate sentiment distribution
195
  sentiment_counts = filtered_df['label'].value_counts(normalize=True) * 100
 
196
  colors = ['red' if sentiment == 'negative' else 'gray' if sentiment == 'neutral' else 'blue' for sentiment in sentiment_counts.index]
197
 
198
  # Create the bar plot
 
203
  textposition='auto',
204
  marker_color=colors
205
  )])
 
206
  sentiment_fig.update_layout(
207
  title='Overall Sentiment Distribution',
208
  xaxis_title='Sentiment',
 
222
  tpb_sentiment_df = filtered_df.groupby(['tpb_label', 'label']).size().unstack(fill_value=0)
223
  tpb_sentiment_df = tpb_sentiment_df.div(tpb_sentiment_df.sum(axis=1), axis=0) * 100
224
 
 
225
  color_map = {
226
  'negative': 'red',
227
  'neutral': 'gray',
 
255
  wordclouds[label] = generate_wordcloud(text)
256
  bigrams_data[label] = generate_bigrams(text)
257
 
 
258
  words_only = {
259
  key: [word_pair for word_pair, _ in value]
260
  for key, value in bigrams_data.items()
261
  }
 
262
  bigram_df = pd.DataFrame({
263
  label: data for label, data in words_only.items()
264
  })
265
 
 
266
  bigram_df.index = [f"Top {i+1}" for i in range(len(bigram_df))]
267
 
268
  return (sentiment_fig, tpb_fig, tpb_sentiment_fig, filtered_df[filtered_df['text'].str.len() < 300].head(5),
269
  report, wordclouds.get('attitude'), wordclouds.get('religious knowledge'),
270
+ wordclouds.get('subjective norms'), wordclouds.get('perceived behavioural control'), bigram_df)
 
271
 
272
 
273
  def text_classification_and_sentiment(text, keywords_df):