Spaces:
Running
Running
Commit
·
9bce4d4
1
Parent(s):
5e55eb8
4.6 more stop management
Browse files
app.py
CHANGED
@@ -971,18 +971,26 @@ def process_file(uploaded_file, model_choice, translation_method=None):
|
|
971 |
if groq_llm is None:
|
972 |
st.warning("Failed to initialize Groq LLM for impact estimation. Using fallback model.")
|
973 |
|
974 |
-
#
|
975 |
-
|
976 |
-
|
977 |
-
|
978 |
-
|
979 |
-
|
980 |
-
|
981 |
-
|
982 |
-
|
983 |
-
|
984 |
-
|
985 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
986 |
|
987 |
# Deduplication
|
988 |
original_count = len(df)
|
@@ -1000,37 +1008,24 @@ def process_file(uploaded_file, model_choice, translation_method=None):
|
|
1000 |
# In process_file function, replace the stop handling section:
|
1001 |
if st.session_state.control.is_stopped():
|
1002 |
st.warning("Обработку остановили")
|
1003 |
-
|
1004 |
-
|
1005 |
-
|
1006 |
-
|
1007 |
-
for col in required_columns:
|
1008 |
-
if col not in processed_rows_df.columns:
|
1009 |
-
processed_rows_df[col] = ''
|
1010 |
|
1011 |
-
|
1012 |
-
|
1013 |
-
processed_rows_df['Impact'] = 'Неопределенный эффект'
|
1014 |
-
if 'Reasoning' not in processed_rows_df.columns:
|
1015 |
-
processed_rows_df['Reasoning'] = 'Обработка была остановлена'
|
1016 |
-
|
1017 |
-
# Create output file
|
1018 |
output = create_output_file(processed_rows_df, uploaded_file, llm)
|
1019 |
-
|
1020 |
if output is not None:
|
1021 |
st.download_button(
|
1022 |
-
label=f"📊 Скачать результат ({len(processed_rows_df)} из {
|
1023 |
data=output,
|
1024 |
file_name="partial_analysis.xlsx",
|
1025 |
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
1026 |
key="partial_download"
|
1027 |
)
|
1028 |
-
else:
|
1029 |
-
st.error("Не удалось создать файл с частичными результатами")
|
1030 |
-
|
1031 |
except Exception as e:
|
1032 |
st.error(f"Ошибка при создании файла с частичными результатами: {str(e)}")
|
1033 |
-
|
1034 |
return processed_rows_df
|
1035 |
|
1036 |
st.session_state.control.wait_if_paused()
|
@@ -1591,7 +1586,7 @@ def main():
|
|
1591 |
st.set_page_config(layout="wide")
|
1592 |
|
1593 |
with st.sidebar:
|
1594 |
-
st.title("::: AI-анализ мониторинга новостей (v.)
|
1595 |
st.subheader("по материалам СКАН-ИНТЕРФАКС")
|
1596 |
|
1597 |
model_choice = st.radio(
|
|
|
971 |
if groq_llm is None:
|
972 |
st.warning("Failed to initialize Groq LLM for impact estimation. Using fallback model.")
|
973 |
|
974 |
+
# Initialize all required columns at the start
|
975 |
+
required_columns = {
|
976 |
+
'Объект': '',
|
977 |
+
'Заголовок': '',
|
978 |
+
'Выдержки из текста': '',
|
979 |
+
'Translated': '',
|
980 |
+
'Sentiment': 'Neutral', # Default sentiment
|
981 |
+
'Impact': 'Неопределенный эффект', # Default impact
|
982 |
+
'Reasoning': 'Не проанализировано', # Default reasoning
|
983 |
+
'Event_Type': 'Нет', # Default event type
|
984 |
+
'Event_Summary': '' # Default event summary
|
985 |
+
}
|
986 |
+
|
987 |
+
# Ensure all required columns exist in DataFrame
|
988 |
+
for col, default_value in required_columns.items():
|
989 |
+
if col not in df.columns:
|
990 |
+
df[col] = default_value
|
991 |
+
|
992 |
+
# Copy all columns to processed_rows_df
|
993 |
+
processed_rows_df = pd.DataFrame(columns=df.columns)
|
994 |
|
995 |
# Deduplication
|
996 |
original_count = len(df)
|
|
|
1008 |
# In process_file function, replace the stop handling section:
|
1009 |
if st.session_state.control.is_stopped():
|
1010 |
st.warning("Обработку остановили")
|
1011 |
+
# Ensure all required columns exist in processed_rows_df
|
1012 |
+
for col, default_value in required_columns.items():
|
1013 |
+
if col not in processed_rows_df.columns:
|
1014 |
+
processed_rows_df[col] = default_value
|
|
|
|
|
|
|
1015 |
|
1016 |
+
if not processed_rows_df.empty:
|
1017 |
+
try:
|
|
|
|
|
|
|
|
|
|
|
1018 |
output = create_output_file(processed_rows_df, uploaded_file, llm)
|
|
|
1019 |
if output is not None:
|
1020 |
st.download_button(
|
1021 |
+
label=f"📊 Скачать результат ({len(processed_rows_df)} из {len(df)} строк)",
|
1022 |
data=output,
|
1023 |
file_name="partial_analysis.xlsx",
|
1024 |
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
1025 |
key="partial_download"
|
1026 |
)
|
|
|
|
|
|
|
1027 |
except Exception as e:
|
1028 |
st.error(f"Ошибка при создании файла с частичными результатами: {str(e)}")
|
|
|
1029 |
return processed_rows_df
|
1030 |
|
1031 |
st.session_state.control.wait_if_paused()
|
|
|
1586 |
st.set_page_config(layout="wide")
|
1587 |
|
1588 |
with st.sidebar:
|
1589 |
+
st.title("::: AI-анализ мониторинга новостей (v.)4.6:::")
|
1590 |
st.subheader("по материалам СКАН-ИНТЕРФАКС")
|
1591 |
|
1592 |
model_choice = st.radio(
|