pentarosarium commited on
Commit
4670145
·
1 Parent(s): b1767f6
Files changed (1) hide show
  1. app.py +12 -19
app.py CHANGED
@@ -228,25 +228,26 @@ class EventDetector:
228
  except Exception as e:
229
  logger.error(f"Sentiment analysis error: {str(e)}")
230
  return "Neutral"
231
-
232
  def estimate_impact(self, text, entity):
233
- """Estimate impact using Groq ensuring sentiment-impact alignment"""
234
  try:
235
  if not self.groq:
236
  return "Неопределенный эффект", "Groq API недоступен"
237
 
238
  template = """
239
- You are a financial risk analyst. Analyze this negative news about {entity}:
240
 
241
  News: {news}
242
 
243
- Based on the severity of negative implications, classify the impact as:
244
- 1. "Значительный риск убытков" - for severe negative events with high financial impact
245
- 2. "Умеренный риск убытков" - for moderate negative events with medium financial impact
246
- 3. "Незначительный риск убытков" - for minor negative events with low financial impact
247
- 4. "Неопределенный эффект" - if impact cannot be reliably assessed
 
248
 
249
- Format response exactly as:
250
  Impact: [category]
251
  Reasoning: [explanation in 2-3 sentences]
252
  """
@@ -266,15 +267,6 @@ class EventDetector:
266
  parts = response_text.split("Reasoning:")
267
  impact = parts[0].split("Impact:")[1].strip()
268
  reasoning = parts[1].strip()
269
-
270
- # Validate impact category
271
- valid_impacts = {
272
- "Значительный риск убытков",
273
- "Умеренный риск убытков",
274
- "Незначительный риск убытков",
275
- "Неопределенный эффект"
276
- }
277
- impact = impact if impact in valid_impacts else "Неопределенный эффект"
278
  else:
279
  impact = "Неопределенный эффект"
280
  reasoning = "Не удалось определить влияние"
@@ -285,6 +277,7 @@ class EventDetector:
285
  logger.error(f"Impact estimation error: {str(e)}")
286
  return "Неопределенный эффект", f"Ошибка анализа: {str(e)}"
287
 
 
288
  @spaces.GPU(duration=60)
289
  def process_text(self, text, entity):
290
  """Process text with Groq-driven sentiment analysis"""
@@ -657,7 +650,7 @@ def create_interface():
657
  # Create state for file data
658
  current_file = gr.State(None)
659
 
660
- gr.Markdown("# AI-анализ мониторинга новостей v.1.56")
661
 
662
  with gr.Row():
663
  file_input = gr.File(
 
228
  except Exception as e:
229
  logger.error(f"Sentiment analysis error: {str(e)}")
230
  return "Neutral"
231
+
232
  def estimate_impact(self, text, entity):
233
+ """Estimate impact using Groq for negative sentiment texts"""
234
  try:
235
  if not self.groq:
236
  return "Неопределенный эффект", "Groq API недоступен"
237
 
238
  template = """
239
+ You are a financial analyst. Analyze this news about {entity} and assess its potential impact.
240
 
241
  News: {news}
242
 
243
+ Classify the impact into one of these categories:
244
+ 1. "Значительный риск убытков" (Significant loss risk)
245
+ 2. "Умеренный риск убытков" (Moderate loss risk)
246
+ 3. "Незначительный риск убытков" (Minor loss risk)
247
+ 4. "Вероятность прибыли" (Potential profit)
248
+ 5. "Неопределенный эффект" (Uncertain effect)
249
 
250
+ Format your response exactly as:
251
  Impact: [category]
252
  Reasoning: [explanation in 2-3 sentences]
253
  """
 
267
  parts = response_text.split("Reasoning:")
268
  impact = parts[0].split("Impact:")[1].strip()
269
  reasoning = parts[1].strip()
 
 
 
 
 
 
 
 
 
270
  else:
271
  impact = "Неопределенный эффект"
272
  reasoning = "Не удалось определить влияние"
 
277
  logger.error(f"Impact estimation error: {str(e)}")
278
  return "Неопределенный эффект", f"Ошибка анализа: {str(e)}"
279
 
280
+
281
  @spaces.GPU(duration=60)
282
  def process_text(self, text, entity):
283
  """Process text with Groq-driven sentiment analysis"""
 
650
  # Create state for file data
651
  current_file = gr.State(None)
652
 
653
+ gr.Markdown("# AI-анализ мониторинга новостей v.1.57")
654
 
655
  with gr.Row():
656
  file_input = gr.File(