Spaces:
Sleeping
Sleeping
Commit ·
1059c86
1
Parent(s): 913a17b
3.39 hard coded trans
Browse files
app.py
CHANGED
|
@@ -64,12 +64,12 @@ class TranslationSystem:
|
|
| 64 |
st.warning(f"Translation error: {str(e)}. Using original text.")
|
| 65 |
return text
|
| 66 |
|
| 67 |
-
def process_file(uploaded_file, model_choice):
|
| 68 |
df = None
|
| 69 |
try:
|
| 70 |
df = pd.read_excel(uploaded_file, sheet_name='Публикации')
|
| 71 |
llm = init_langchain_llm(model_choice)
|
| 72 |
-
translator = TranslationSystem(batch_size=5)
|
| 73 |
|
| 74 |
# Validate required columns
|
| 75 |
required_columns = ['Объект', 'Заголовок', 'Выдержки из текста']
|
|
@@ -115,7 +115,7 @@ def process_file(uploaded_file, model_choice):
|
|
| 115 |
sentiment = analyze_sentiment(translated_text)
|
| 116 |
df.at[idx, 'Sentiment'] = sentiment
|
| 117 |
|
| 118 |
-
# Event detection
|
| 119 |
event_type, event_summary = detect_events(
|
| 120 |
llm,
|
| 121 |
row['Выдержки из текста'],
|
|
@@ -147,7 +147,7 @@ def process_file(uploaded_file, model_choice):
|
|
| 147 |
st.warning(f"Ошибка при обработке новости {idx + 1}: {str(e)}")
|
| 148 |
continue
|
| 149 |
|
| 150 |
-
# Small delay between items
|
| 151 |
time.sleep(0.5)
|
| 152 |
|
| 153 |
# Delay between batches
|
|
@@ -159,7 +159,6 @@ def process_file(uploaded_file, model_choice):
|
|
| 159 |
st.error(f"❌ Ошибка при обработке файла: {str(e)}")
|
| 160 |
return df if df is not None else None
|
| 161 |
|
| 162 |
-
|
| 163 |
def translate_reasoning_to_russian(llm, text):
|
| 164 |
template = """
|
| 165 |
Translate this English explanation to Russian, maintaining a formal business style:
|
|
@@ -552,10 +551,9 @@ def create_output_file(df, uploaded_file, llm):
|
|
| 552 |
wb.save(output)
|
| 553 |
output.seek(0)
|
| 554 |
return output
|
| 555 |
-
|
| 556 |
def main():
|
| 557 |
with st.sidebar:
|
| 558 |
-
st.title("::: AI-анализ мониторинга новостей (v.3.
|
| 559 |
st.subheader("по материалам СКАН-ИНТЕРФАКС ")
|
| 560 |
|
| 561 |
model_choice = st.radio(
|
|
@@ -564,11 +562,12 @@ def main():
|
|
| 564 |
key="model_selector"
|
| 565 |
)
|
| 566 |
|
|
|
|
| 567 |
translation_method = st.radio(
|
| 568 |
"Выберите метод перевода:",
|
| 569 |
["googletrans", "llm"],
|
| 570 |
key="translation_selector",
|
| 571 |
-
help="
|
| 572 |
)
|
| 573 |
|
| 574 |
st.markdown(
|
|
@@ -617,18 +616,12 @@ def main():
|
|
| 617 |
uploaded_file = st.sidebar.file_uploader("Выбирайте Excel-файл", type="xlsx", key="unique_file_uploader")
|
| 618 |
|
| 619 |
if uploaded_file is not None and st.session_state.processed_df is None:
|
| 620 |
-
start_time = time.time()
|
| 621 |
-
|
| 622 |
-
# Initialize LLM with selected model
|
| 623 |
-
llm = init_langchain_llm(model_choice)
|
| 624 |
-
|
| 625 |
-
# Process file with selected translation method
|
| 626 |
st.session_state.processed_df = process_file(
|
| 627 |
-
uploaded_file,
|
| 628 |
model_choice,
|
| 629 |
-
translation_method
|
| 630 |
)
|
| 631 |
-
|
| 632 |
st.subheader("Предпросмотр данных")
|
| 633 |
preview_df = st.session_state.processed_df[['Объект', 'Заголовок', 'Sentiment', 'Impact']].head()
|
| 634 |
st.dataframe(preview_df)
|
|
|
|
| 64 |
st.warning(f"Translation error: {str(e)}. Using original text.")
|
| 65 |
return text
|
| 66 |
|
| 67 |
+
def process_file(uploaded_file, model_choice, translation_method=None): # Added translation_method parameter with default None
|
| 68 |
df = None
|
| 69 |
try:
|
| 70 |
df = pd.read_excel(uploaded_file, sheet_name='Публикации')
|
| 71 |
llm = init_langchain_llm(model_choice)
|
| 72 |
+
translator = TranslationSystem(batch_size=5) # We'll use deep-translator regardless of translation_method
|
| 73 |
|
| 74 |
# Validate required columns
|
| 75 |
required_columns = ['Объект', 'Заголовок', 'Выдержки из текста']
|
|
|
|
| 115 |
sentiment = analyze_sentiment(translated_text)
|
| 116 |
df.at[idx, 'Sentiment'] = sentiment
|
| 117 |
|
| 118 |
+
# Event detection with rate limit handling
|
| 119 |
event_type, event_summary = detect_events(
|
| 120 |
llm,
|
| 121 |
row['Выдержки из текста'],
|
|
|
|
| 147 |
st.warning(f"Ошибка при обработке новости {idx + 1}: {str(e)}")
|
| 148 |
continue
|
| 149 |
|
| 150 |
+
# Small delay between items
|
| 151 |
time.sleep(0.5)
|
| 152 |
|
| 153 |
# Delay between batches
|
|
|
|
| 159 |
st.error(f"❌ Ошибка при обработке файла: {str(e)}")
|
| 160 |
return df if df is not None else None
|
| 161 |
|
|
|
|
| 162 |
def translate_reasoning_to_russian(llm, text):
|
| 163 |
template = """
|
| 164 |
Translate this English explanation to Russian, maintaining a formal business style:
|
|
|
|
| 551 |
wb.save(output)
|
| 552 |
output.seek(0)
|
| 553 |
return output
|
|
|
|
| 554 |
def main():
|
| 555 |
with st.sidebar:
|
| 556 |
+
st.title("::: AI-анализ мониторинга новостей (v.3.39 ):::")
|
| 557 |
st.subheader("по материалам СКАН-ИНТЕРФАКС ")
|
| 558 |
|
| 559 |
model_choice = st.radio(
|
|
|
|
| 562 |
key="model_selector"
|
| 563 |
)
|
| 564 |
|
| 565 |
+
# We'll keep this for compatibility but it won't affect the translation method
|
| 566 |
translation_method = st.radio(
|
| 567 |
"Выберите метод перевода:",
|
| 568 |
["googletrans", "llm"],
|
| 569 |
key="translation_selector",
|
| 570 |
+
help="Используется deep-translator независимо от выбора"
|
| 571 |
)
|
| 572 |
|
| 573 |
st.markdown(
|
|
|
|
| 616 |
uploaded_file = st.sidebar.file_uploader("Выбирайте Excel-файл", type="xlsx", key="unique_file_uploader")
|
| 617 |
|
| 618 |
if uploaded_file is not None and st.session_state.processed_df is None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 619 |
st.session_state.processed_df = process_file(
|
| 620 |
+
uploaded_file,
|
| 621 |
model_choice,
|
| 622 |
+
translation_method # This parameter won't affect the translation method but keeps the interface consistent
|
| 623 |
)
|
| 624 |
+
|
| 625 |
st.subheader("Предпросмотр данных")
|
| 626 |
preview_df = st.session_state.processed_df[['Объект', 'Заголовок', 'Sentiment', 'Impact']].head()
|
| 627 |
st.dataframe(preview_df)
|