pentarosarium commited on
Commit
4864457
·
1 Parent(s): e3e54f2
Files changed (1) hide show
  1. app.py +40 -23
app.py CHANGED
@@ -484,35 +484,52 @@ def analyze_sentiment(text):
484
 
485
 
486
  def detect_events(llm, text, entity):
487
- template = """
488
- Проанализируйте следующую новость о компании "{entity}" и определите наличие следующих событий:
489
- 1. Публикация отчетности и ключевые показатели (выручка, прибыль, EBITDA)
490
- 2. События на рынке ценных бумаг (погашение облигаций, выплата/невыплата купона, дефолт, реструктуризация)
491
- 3. Судебные иски или юридические действия против компании, акционеров, менеджеров
492
-
493
- Новость: {text}
494
-
495
- Ответьте в следующем формате:
496
- Тип: ["Отчетность" или "РЦБ" или "Суд" или "Нет"]
497
- Краткое описание: [краткое описание события на русском языке, не более 2 предложений]
498
  """
499
-
500
- prompt = PromptTemplate(template=template, input_variables=["entity", "text"])
501
- chain = prompt | llm
502
- response = chain.invoke({"entity": entity, "text": text})
503
-
504
  event_type = "Нет"
505
  summary = ""
506
 
507
  try:
508
- response_text = response.content if hasattr(response, 'content') else str(response)
509
- if "Тип:" in response_text and "Краткое описание:" in response_text:
510
- type_part, summary_part = response_text.split("Краткое описание:")
511
- event_type = type_part.split("Тип:")[1].strip()
512
- summary = summary_part.strip()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
513
  except Exception as e:
514
  st.warning(f"Ошибка при анализе событий: {str(e)}")
515
-
516
  return event_type, summary
517
 
518
  def fuzzy_deduplicate(df, column, threshold=50):
@@ -762,7 +779,7 @@ def create_output_file(df, uploaded_file, llm):
762
  return output
763
  def main():
764
  with st.sidebar:
765
- st.title("::: AI-анализ мониторинга новостей (v.3.48):::")
766
  st.subheader("по материалам СКАН-ИНТЕРФАКС ")
767
 
768
 
 
484
 
485
 
486
  def detect_events(llm, text, entity):
 
 
 
 
 
 
 
 
 
 
 
487
  """
488
+ Detect events in news text. This function works with both API-based LLMs and local models.
489
+ """
490
+ # Initialize default return values
 
 
491
  event_type = "Нет"
492
  summary = ""
493
 
494
  try:
495
+ # Handle API-based LLMs (Groq, GPT-4, Qwen)
496
+ if hasattr(llm, 'invoke'):
497
+ template = """
498
+ Проанализируйте следующую новость о компании "{entity}" и определите наличие следующих событий:
499
+ 1. Публикация отчетности и ключевые показатели (выручка, прибыль, EBITDA)
500
+ 2. События на рынке ценных бумаг (погашение облигаций, выплата/невыплата купона, дефолт, реструктуризация)
501
+ 3. Судебные иски или юридические действия против компании, акционеров, менеджеров
502
+
503
+ Новость: {text}
504
+
505
+ Ответьте в следующем формате:
506
+ Тип: ["Отчетность" или "РЦБ" или "Суд" или "Нет"]
507
+ Краткое описание: [краткое описание события на русском языке, не более 2 предложений]
508
+ """
509
+
510
+ prompt = PromptTemplate(template=template, input_variables=["entity", "text"])
511
+ chain = prompt | llm
512
+ response = chain.invoke({"entity": entity, "text": text})
513
+
514
+ response_text = response.content if hasattr(response, 'content') else str(response)
515
+
516
+ if "Тип:" in response_text and "Краткое описание:" in response_text:
517
+ type_part, summary_part = response_text.split("Краткое описание:")
518
+ event_type_temp = type_part.split("Тип:")[1].strip()
519
+ # Validate event type
520
+ valid_types = ["Отчетность", "РЦБ", "Суд", "Нет"]
521
+ if event_type_temp in valid_types:
522
+ event_type = event_type_temp
523
+ summary = summary_part.strip()
524
+
525
+ # Handle local MT5 model
526
+ else:
527
+ # Assuming llm is FallbackLLMSystem instance
528
+ event_type, summary = llm.detect_events(text, entity)
529
+
530
  except Exception as e:
531
  st.warning(f"Ошибка при анализе событий: {str(e)}")
532
+
533
  return event_type, summary
534
 
535
  def fuzzy_deduplicate(df, column, threshold=50):
 
779
  return output
780
  def main():
781
  with st.sidebar:
782
+ st.title("::: AI-анализ мониторинга новостей (v.3.49):::")
783
  st.subheader("по материалам СКАН-ИНТЕРФАКС ")
784
 
785