Spaces:
Running
Running
Commit
·
a2fccb6
1
Parent(s):
a7a5806
3.61
Browse files
app.py
CHANGED
@@ -1063,8 +1063,63 @@ def create_output_file(df, uploaded_file, llm):
|
|
1063 |
try:
|
1064 |
wb = load_workbook("sample_file.xlsx")
|
1065 |
|
1066 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1067 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1068 |
# Update 'Анализ' sheet with modified translation handling
|
1069 |
ws = wb['Анализ']
|
1070 |
row_idx = 4
|
@@ -1085,7 +1140,15 @@ def create_output_file(df, uploaded_file, llm):
|
|
1085 |
ws.cell(row=row_idx, column=9, value=row['Выдержки из текста'])
|
1086 |
row_idx += 1
|
1087 |
|
1088 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1089 |
|
1090 |
output = io.BytesIO()
|
1091 |
wb.save(output)
|
@@ -1100,7 +1163,7 @@ def main():
|
|
1100 |
st.set_page_config(layout="wide")
|
1101 |
|
1102 |
with st.sidebar:
|
1103 |
-
st.title("::: AI-анализ мониторинга новостей (v.3.
|
1104 |
st.subheader("по материалам СКАН-ИНТЕРФАКС")
|
1105 |
|
1106 |
model_choice = st.radio(
|
|
|
1063 |
try:
|
1064 |
wb = load_workbook("sample_file.xlsx")
|
1065 |
|
1066 |
+
# Update 'Мониторинг' sheet with events
|
1067 |
+
ws = wb['Мониторинг']
|
1068 |
+
row_idx = 4
|
1069 |
+
for _, row in df.iterrows():
|
1070 |
+
if row['Event_Type'] != 'Нет':
|
1071 |
+
ws.cell(row=row_idx, column=5, value=row['Объект']) # Column E
|
1072 |
+
ws.cell(row=row_idx, column=6, value=row['Заголовок']) # Column F
|
1073 |
+
ws.cell(row=row_idx, column=7, value=row['Event_Type']) # Column G
|
1074 |
+
ws.cell(row=row_idx, column=8, value=row['Event_Summary']) # Column H
|
1075 |
+
ws.cell(row=row_idx, column=9, value=row['Выдержки из текста']) # Column I
|
1076 |
+
row_idx += 1
|
1077 |
+
|
1078 |
+
# Sort entities by number of negative publications
|
1079 |
+
entity_stats = pd.DataFrame({
|
1080 |
+
'Объект': df['Объект'].unique(),
|
1081 |
+
'Всего': df.groupby('Объект').size(),
|
1082 |
+
'Негативные': df[df['Sentiment'] == 'Negative'].groupby('Объект').size().fillna(0).astype(int),
|
1083 |
+
'Позитивные': df[df['Sentiment'] == 'Positive'].groupby('Объект').size().fillna(0).astype(int)
|
1084 |
+
}).sort_values('Негативные', ascending=False)
|
1085 |
+
|
1086 |
+
# Calculate most negative impact for each entity
|
1087 |
+
entity_impacts = {}
|
1088 |
+
for entity in df['Объект'].unique():
|
1089 |
+
entity_df = df[df['Объект'] == entity]
|
1090 |
+
negative_impacts = entity_df[entity_df['Sentiment'] == 'Negative']['Impact']
|
1091 |
+
entity_impacts[entity] = negative_impacts.iloc[0] if len(negative_impacts) > 0 else 'Неопределенный эффект'
|
1092 |
+
|
1093 |
+
# Update 'Сводка' sheet
|
1094 |
+
ws = wb['Сводка']
|
1095 |
+
for idx, (entity, row) in enumerate(entity_stats.iterrows(), start=4):
|
1096 |
+
ws.cell(row=idx, column=5, value=entity) # Column E
|
1097 |
+
ws.cell(row=idx, column=6, value=row['Всего']) # Column F
|
1098 |
+
ws.cell(row=idx, column=7, value=row['Негативные']) # Column G
|
1099 |
+
ws.cell(row=idx, column=8, value=row['Позитивные']) # Column H
|
1100 |
+
ws.cell(row=idx, column=9, value=entity_impacts[entity]) # Column I
|
1101 |
+
|
1102 |
+
# Update 'Значимые' sheet
|
1103 |
+
ws = wb['Значимые']
|
1104 |
+
row_idx = 3
|
1105 |
+
for _, row in df.iterrows():
|
1106 |
+
if row['Sentiment'] in ['Negative', 'Positive']:
|
1107 |
+
ws.cell(row=row_idx, column=3, value=row['Объект']) # Column C
|
1108 |
+
ws.cell(row=row_idx, column=4, value='релевантно') # Column D
|
1109 |
+
ws.cell(row=row_idx, column=5, value=row['Sentiment']) # Column E
|
1110 |
+
ws.cell(row=row_idx, column=6, value=row['Impact']) # Column F
|
1111 |
+
ws.cell(row=row_idx, column=7, value=row['Заголовок']) # Column G
|
1112 |
+
ws.cell(row=row_idx, column=8, value=row['Выдержки из текста']) # Column H
|
1113 |
+
row_idx += 1
|
1114 |
|
1115 |
+
# Copy 'Публикации' sheet
|
1116 |
+
original_df = pd.read_excel(uploaded_file, sheet_name='Публикации')
|
1117 |
+
ws = wb['Публикации']
|
1118 |
+
for r_idx, row in enumerate(dataframe_to_rows(original_df, index=False, header=True), start=1):
|
1119 |
+
for c_idx, value in enumerate(row, start=1):
|
1120 |
+
ws.cell(row=r_idx, column=c_idx, value=value)
|
1121 |
+
|
1122 |
+
|
1123 |
# Update 'Анализ' sheet with modified translation handling
|
1124 |
ws = wb['Анализ']
|
1125 |
row_idx = 4
|
|
|
1140 |
ws.cell(row=row_idx, column=9, value=row['Выдержки из текста'])
|
1141 |
row_idx += 1
|
1142 |
|
1143 |
+
# Update 'Тех.приложение' sheet
|
1144 |
+
tech_df = df[['Объект', 'Заголовок', 'Выдержки из текста', 'Translated', 'Sentiment', 'Impact', 'Reasoning']]
|
1145 |
+
if 'Тех.приложение' not in wb.sheetnames:
|
1146 |
+
wb.create_sheet('Тех.приложение')
|
1147 |
+
ws = wb['Тех.приложение']
|
1148 |
+
for r_idx, row in enumerate(dataframe_to_rows(tech_df, index=False, header=True), start=1):
|
1149 |
+
for c_idx, value in enumerate(row, start=1):
|
1150 |
+
ws.cell(row=r_idx, column=c_idx, value=value)
|
1151 |
+
|
1152 |
|
1153 |
output = io.BytesIO()
|
1154 |
wb.save(output)
|
|
|
1163 |
st.set_page_config(layout="wide")
|
1164 |
|
1165 |
with st.sidebar:
|
1166 |
+
st.title("::: AI-анализ мониторинга новостей (v.3.61):::")
|
1167 |
st.subheader("по материалам СКАН-ИНТЕРФАКС")
|
1168 |
|
1169 |
model_choice = st.radio(
|