Spaces:
Build error
Build error
Commit ·
4670145
1
Parent(s): b1767f6
v.1.57
Browse files
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
|
| 234 |
try:
|
| 235 |
if not self.groq:
|
| 236 |
return "Неопределенный эффект", "Groq API недоступен"
|
| 237 |
|
| 238 |
template = """
|
| 239 |
-
You are a financial
|
| 240 |
|
| 241 |
News: {news}
|
| 242 |
|
| 243 |
-
|
| 244 |
-
1. "Значительный риск убытков"
|
| 245 |
-
2. "Умеренный риск убытков"
|
| 246 |
-
3. "Незначительный риск убытков"
|
| 247 |
-
4. "
|
|
|
|
| 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.
|
| 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(
|