Spaces:
Running
Running
Commit
·
9da9717
1
Parent(s):
e2a84d3
4.15 attempt at summary
Browse files
app.py
CHANGED
@@ -1433,23 +1433,44 @@ def create_output_file(df, uploaded_file):
|
|
1433 |
|
1434 |
# 3. Update 'Сводка' sheet
|
1435 |
ws = wb['Сводка']
|
1436 |
-
|
1437 |
-
|
1438 |
-
|
1439 |
-
entity_stats['Всего'] = df.groupby('Объект').size()
|
1440 |
-
entity_stats['Негативные'] = df[df['Sentiment'] == 'Negative'].groupby('Объект').size().fillna(0).astype(int)
|
1441 |
-
entity_stats['Позитивные'] = df[df['Sentiment'] == 'Positive'].groupby('Объект').size().fillna(0).astype(int)
|
1442 |
-
|
1443 |
-
for idx, (entity, row) in enumerate(entity_stats.iterrows(), start=4):
|
1444 |
-
ws.cell(row=idx, column=5, value=row['Объект'])
|
1445 |
-
ws.cell(row=idx, column=6, value=row['Всего'])
|
1446 |
-
ws.cell(row=idx, column=7, value=row['Негативные'])
|
1447 |
-
ws.cell(row=idx, column=8, value=row['Позитивные'])
|
1448 |
-
# Get impact for entity
|
1449 |
entity_df = df[df['Объект'] == entity]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1450 |
negative_df = entity_df[entity_df['Sentiment'] == 'Negative']
|
1451 |
-
|
1452 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1453 |
|
1454 |
# 4. Update 'Значимые' sheet
|
1455 |
ws = wb['Значимые']
|
@@ -1504,7 +1525,7 @@ def main():
|
|
1504 |
st.set_page_config(layout="wide")
|
1505 |
|
1506 |
with st.sidebar:
|
1507 |
-
st.title("::: AI-анализ мониторинга новостей (v.4.
|
1508 |
st.subheader("по материалам СКАН-ИНТЕРФАКС")
|
1509 |
|
1510 |
model_choice = st.radio(
|
|
|
1433 |
|
1434 |
# 3. Update 'Сводка' sheet
|
1435 |
ws = wb['Сводка']
|
1436 |
+
unique_entities = df['Объект'].unique()
|
1437 |
+
entity_stats = []
|
1438 |
+
for entity in unique_entities:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1439 |
entity_df = df[df['Объект'] == entity]
|
1440 |
+
stats = {
|
1441 |
+
'Объект': entity,
|
1442 |
+
'Всего': len(entity_df),
|
1443 |
+
'Негативные': len(entity_df[entity_df['Sentiment'] == 'Negative']),
|
1444 |
+
'Позитивные': len(entity_df[entity_df['Sentiment'] == 'Positive'])
|
1445 |
+
}
|
1446 |
+
|
1447 |
+
# Get most severe impact for entity
|
1448 |
negative_df = entity_df[entity_df['Sentiment'] == 'Negative']
|
1449 |
+
if len(negative_df) > 0:
|
1450 |
+
impacts = negative_df['Impact'].dropna()
|
1451 |
+
if len(impacts) > 0:
|
1452 |
+
stats['Impact'] = impacts.iloc[0]
|
1453 |
+
else:
|
1454 |
+
stats['Impact'] = 'Неопределенный эффект'
|
1455 |
+
else:
|
1456 |
+
stats['Impact'] = 'Неопределенный эффект'
|
1457 |
+
|
1458 |
+
entity_stats.append(stats)
|
1459 |
+
|
1460 |
+
|
1461 |
+
# Sort by number of negative mentions
|
1462 |
+
entity_stats = sorted(entity_stats, key=lambda x: x['Негативные'], reverse=True)
|
1463 |
+
|
1464 |
+
# Write to sheet
|
1465 |
+
row_idx = 4 # Starting row in Сводка sheet
|
1466 |
+
for stats in entity_stats:
|
1467 |
+
ws.cell(row=row_idx, column=5, value=stats['Объект'])
|
1468 |
+
ws.cell(row=row_idx, column=6, value=stats['Всего'])
|
1469 |
+
ws.cell(row=row_idx, column=7, value=stats['Негативные'])
|
1470 |
+
ws.cell(row=row_idx, column=8, value=stats['Позитивные'])
|
1471 |
+
ws.cell(row=row_idx, column=9, value=stats['Impact'])
|
1472 |
+
row_idx += 1
|
1473 |
+
|
1474 |
|
1475 |
# 4. Update 'Значимые' sheet
|
1476 |
ws = wb['Значимые']
|
|
|
1525 |
st.set_page_config(layout="wide")
|
1526 |
|
1527 |
with st.sidebar:
|
1528 |
+
st.title("::: AI-анализ мониторинга новостей (v.4.15):::")
|
1529 |
st.subheader("по материалам СКАН-ИНТЕРФАКС")
|
1530 |
|
1531 |
model_choice = st.radio(
|