pentarosarium commited on
Commit
3cedc42
·
1 Parent(s): 0d683d7

progress more 70

Browse files
Files changed (1) hide show
  1. app.py +40 -13
app.py CHANGED
@@ -390,8 +390,9 @@ def process_file(uploaded_file):
390
  progress_bar.empty()
391
  status_text.empty()
392
 
393
- word_cloud_plot = generate_word_cloud(df)
394
- st.pyplot(word_cloud_plot)
 
395
 
396
  return df
397
 
@@ -464,22 +465,48 @@ def create_output_file(df, uploaded_file, analysis_df):
464
 
465
  return output
466
 
467
- def generate_word_cloud(df):
468
  # Filter for negative sentiments
469
  negative_df = df[df[['FinBERT', 'RoBERTa', 'FinBERT-Tone']].eq('Negative').any(axis=1)]
470
 
471
- # Combine entity names with their frequency of negative mentions
472
- entity_counts = Counter(negative_df['Объект'])
473
-
474
- # Create and generate a word cloud image
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
475
  wordcloud = WordCloud(width=800, height=400, background_color='white').generate_from_frequencies(entity_counts)
476
 
477
- # Display the generated image
478
- plt.figure(figsize=(10, 5))
479
- plt.imshow(wordcloud, interpolation='bilinear')
480
- plt.axis('off')
481
- plt.title('Облако слов: Объекты с негативными упоминаниями')
482
- return plt
483
 
484
 
485
  def main():
 
390
  progress_bar.empty()
391
  status_text.empty()
392
 
393
+ visualization = generate_sentiment_visualization(df)
394
+ if visualization:
395
+ st.pyplot(visualization)
396
 
397
  return df
398
 
 
465
 
466
  return output
467
 
468
+ def generate_sentiment_visualization(df):
469
  # Filter for negative sentiments
470
  negative_df = df[df[['FinBERT', 'RoBERTa', 'FinBERT-Tone']].eq('Negative').any(axis=1)]
471
 
472
+ if negative_df.empty:
473
+ st.warning("Не обнаружено негативных упоминаний. Отображаем общую статистику по объектам.")
474
+ entity_counts = df['Объект'].value_counts()
475
+ else:
476
+ entity_counts = negative_df['Объект'].value_counts()
477
+
478
+ if len(entity_counts) == 0:
479
+ st.warning("Нет данных для визуализации.")
480
+ return None
481
+
482
+ if len(entity_counts) == 1:
483
+ st.warning("Обнаружен только один объект. Отображаем статистику в виде столбчатой диаграммы.")
484
+ fig, ax = plt.subplots()
485
+ entity_counts.plot(kind='bar', ax=ax)
486
+ ax.set_title('Количество упоминаний объекта')
487
+ ax.set_ylabel('Количество упоминаний')
488
+ plt.tight_layout()
489
+ return fig
490
+
491
+ if len(entity_counts) <= 5:
492
+ st.info("Обнаружено малое количество объектов. Отображаем статистику в виде столбчатой диаграммы.")
493
+ fig, ax = plt.subplots(figsize=(10, 5))
494
+ entity_counts.plot(kind='bar', ax=ax)
495
+ ax.set_title('Количество упоминаний объектов')
496
+ ax.set_ylabel('Количество упоминаний')
497
+ plt.xticks(rotation=45, ha='right')
498
+ plt.tight_layout()
499
+ return fig
500
+
501
+ # If we have enough data, create a word cloud
502
  wordcloud = WordCloud(width=800, height=400, background_color='white').generate_from_frequencies(entity_counts)
503
 
504
+ fig, ax = plt.subplots(figsize=(10, 5))
505
+ ax.imshow(wordcloud, interpolation='bilinear')
506
+ ax.axis('off')
507
+ ax.set_title('Облако слов: Объекты с негативными упоминаниями' if not negative_df.empty else 'Облако слов: Все упоминания объектов')
508
+
509
+ return fig
510
 
511
 
512
  def main():