Spaces:
Running
Running
Commit
·
3cedc42
1
Parent(s):
0d683d7
progress more 70
Browse files
app.py
CHANGED
@@ -390,8 +390,9 @@ def process_file(uploaded_file):
|
|
390 |
progress_bar.empty()
|
391 |
status_text.empty()
|
392 |
|
393 |
-
|
394 |
-
|
|
|
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
|
468 |
# Filter for negative sentiments
|
469 |
negative_df = df[df[['FinBERT', 'RoBERTa', 'FinBERT-Tone']].eq('Negative').any(axis=1)]
|
470 |
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
475 |
wordcloud = WordCloud(width=800, height=400, background_color='white').generate_from_frequencies(entity_counts)
|
476 |
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
return
|
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():
|