Spaces:
Running
Running
Commit
·
95deb7a
1
Parent(s):
6fe0751
4.10
Browse files
app.py
CHANGED
@@ -1408,32 +1408,102 @@ def translate_reasoning_to_russian(llm, text):
|
|
1408 |
|
1409 |
|
1410 |
def create_output_file(df, uploaded_file, llm):
|
1411 |
-
"""
|
1412 |
try:
|
1413 |
wb = load_workbook("sample_file.xlsx")
|
1414 |
|
1415 |
-
#
|
1416 |
-
|
1417 |
-
|
1418 |
-
|
1419 |
-
|
1420 |
-
|
1421 |
-
|
1422 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1423 |
output = io.BytesIO()
|
1424 |
wb.save(output)
|
1425 |
output.seek(0)
|
1426 |
return output
|
|
|
1427 |
except Exception as e:
|
1428 |
-
st.error(f"Error
|
|
|
|
|
1429 |
return None
|
1430 |
|
1431 |
-
|
1432 |
def main():
|
1433 |
st.set_page_config(layout="wide")
|
1434 |
|
1435 |
with st.sidebar:
|
1436 |
-
st.title("::: AI-анализ мониторинга новостей (v.4.
|
1437 |
st.subheader("по материалам СКАН-ИНТЕРФАКС")
|
1438 |
|
1439 |
model_choice = st.radio(
|
|
|
1408 |
|
1409 |
|
1410 |
def create_output_file(df, uploaded_file, llm):
|
1411 |
+
"""Create Excel file with multiple sheets from processed DataFrame"""
|
1412 |
try:
|
1413 |
wb = load_workbook("sample_file.xlsx")
|
1414 |
|
1415 |
+
# 1. Update 'Публикации' sheet
|
1416 |
+
ws = wb['Публикации']
|
1417 |
+
for r_idx, row in enumerate(dataframe_to_rows(df, index=False, header=True), start=1):
|
1418 |
+
for c_idx, value in enumerate(row, start=1):
|
1419 |
+
ws.cell(row=r_idx, column=c_idx, value=value)
|
1420 |
+
|
1421 |
+
# 2. Update 'Мониторинг' sheet with events
|
1422 |
+
ws = wb['Мониторинг']
|
1423 |
+
row_idx = 4
|
1424 |
+
events_df = df[df['Event_Type'] != 'Нет'].copy()
|
1425 |
+
for _, row in events_df.iterrows():
|
1426 |
+
ws.cell(row=row_idx, column=5, value=row['Объект'])
|
1427 |
+
ws.cell(row=row_idx, column=6, value=row['Заголовок'])
|
1428 |
+
ws.cell(row=row_idx, column=7, value=row['Event_Type'])
|
1429 |
+
ws.cell(row=row_idx, column=8, value=row['Event_Summary'])
|
1430 |
+
ws.cell(row=row_idx, column=9, value=row['Выдержки из текста'])
|
1431 |
+
row_idx += 1
|
1432 |
+
|
1433 |
+
# 3. Update 'Сводка' sheet
|
1434 |
+
ws = wb['Сводка']
|
1435 |
+
entity_stats = pd.DataFrame({
|
1436 |
+
'Объект': df['Объект'].unique()
|
1437 |
+
})
|
1438 |
+
entity_stats['Всего'] = df.groupby('Объект').size()
|
1439 |
+
entity_stats['Негативные'] = df[df['Sentiment'] == 'Negative'].groupby('Объект').size().fillna(0).astype(int)
|
1440 |
+
entity_stats['Позитивные'] = df[df['Sentiment'] == 'Positive'].groupby('Объект').size().fillna(0).astype(int)
|
1441 |
+
|
1442 |
+
for idx, (entity, row) in enumerate(entity_stats.iterrows(), start=4):
|
1443 |
+
ws.cell(row=idx, column=5, value=entity)
|
1444 |
+
ws.cell(row=idx, column=6, value=row['Всего'])
|
1445 |
+
ws.cell(row=idx, column=7, value=row['Негативные'])
|
1446 |
+
ws.cell(row=idx, column=8, value=row['Позитивные'])
|
1447 |
+
# Get impact for entity
|
1448 |
+
entity_df = df[df['Объект'] == entity]
|
1449 |
+
negative_df = entity_df[entity_df['Sentiment'] == 'Negative']
|
1450 |
+
impact = negative_df['Impact'].iloc[0] if len(negative_df) > 0 else 'Неопределенный эффект'
|
1451 |
+
ws.cell(row=idx, column=9, value=impact)
|
1452 |
+
|
1453 |
+
# 4. Update 'Значимые' sheet
|
1454 |
+
ws = wb['Значимые']
|
1455 |
+
row_idx = 3
|
1456 |
+
sentiment_df = df[df['Sentiment'].isin(['Negative', 'Positive'])].copy()
|
1457 |
+
for _, row in sentiment_df.iterrows():
|
1458 |
+
ws.cell(row=row_idx, column=3, value=row['Объект'])
|
1459 |
+
ws.cell(row=row_idx, column=4, value='релевантно')
|
1460 |
+
ws.cell(row=row_idx, column=5, value=row['Sentiment'])
|
1461 |
+
ws.cell(row=row_idx, column=6, value=row.get('Impact', 'Неопределенный эффект'))
|
1462 |
+
ws.cell(row=row_idx, column=7, value=row['Заголовок'])
|
1463 |
+
ws.cell(row=row_idx, column=8, value=row['Выдержки из текста'])
|
1464 |
+
row_idx += 1
|
1465 |
+
|
1466 |
+
# 5. Update 'Анализ' sheet
|
1467 |
+
ws = wb['Анализ']
|
1468 |
+
row_idx = 4
|
1469 |
+
negative_df = df[df['Sentiment'] == 'Negative'].copy()
|
1470 |
+
for _, row in negative_df.iterrows():
|
1471 |
+
ws.cell(row=row_idx, column=5, value=row['Объект'])
|
1472 |
+
ws.cell(row=row_idx, column=6, value=row['Заголовок'])
|
1473 |
+
ws.cell(row=row_idx, column=7, value="Риск убытка")
|
1474 |
+
ws.cell(row=row_idx, column=8, value=row.get('Reasoning', 'Не проанализировано'))
|
1475 |
+
ws.cell(row=row_idx, column=9, value=row['Выдержки из текста'])
|
1476 |
+
row_idx += 1
|
1477 |
+
|
1478 |
+
# 6. Update 'Тех.приложение' sheet
|
1479 |
+
if 'Тех.приложение' not in wb.sheetnames:
|
1480 |
+
wb.create_sheet('Тех.приложение')
|
1481 |
+
ws = wb['Тех.приложение']
|
1482 |
+
|
1483 |
+
tech_cols = ['Объект', 'Заголовок', 'Выдержки из текста', 'Translated', 'Sentiment', 'Impact', 'Reasoning']
|
1484 |
+
tech_df = df[tech_cols].copy()
|
1485 |
+
|
1486 |
+
for r_idx, row in enumerate(dataframe_to_rows(tech_df, index=False, header=True), start=1):
|
1487 |
+
for c_idx, value in enumerate(row, start=1):
|
1488 |
+
ws.cell(row=r_idx, column=c_idx, value=value)
|
1489 |
+
|
1490 |
+
# Save workbook
|
1491 |
output = io.BytesIO()
|
1492 |
wb.save(output)
|
1493 |
output.seek(0)
|
1494 |
return output
|
1495 |
+
|
1496 |
except Exception as e:
|
1497 |
+
st.error(f"Error creating output file: {str(e)}")
|
1498 |
+
st.error(f"DataFrame shape: {df.shape}")
|
1499 |
+
st.error(f"Available columns: {df.columns.tolist()}")
|
1500 |
return None
|
1501 |
|
|
|
1502 |
def main():
|
1503 |
st.set_page_config(layout="wide")
|
1504 |
|
1505 |
with st.sidebar:
|
1506 |
+
st.title("::: AI-анализ мониторинга новостей (v.4.10):::")
|
1507 |
st.subheader("по материалам СКАН-ИНТЕРФАКС")
|
1508 |
|
1509 |
model_choice = st.radio(
|