Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,9 +12,6 @@ import re
|
|
| 12 |
from dataclasses import dataclass
|
| 13 |
import logging
|
| 14 |
from bs4 import BeautifulSoup
|
| 15 |
-
import speech_recognition as sr
|
| 16 |
-
import pyttsx3
|
| 17 |
-
import io
|
| 18 |
import tempfile
|
| 19 |
import os
|
| 20 |
from threading import Thread
|
|
@@ -354,31 +351,19 @@ class LanguageAgent:
|
|
| 354 |
return brief.strip()
|
| 355 |
|
| 356 |
class VoiceAgent:
|
|
|
|
| 357 |
def __init__(self):
|
| 358 |
-
self.
|
| 359 |
-
|
| 360 |
-
self.tts_engine.setProperty('rate', 150)
|
| 361 |
-
self.tts_engine.setProperty('volume', 0.9)
|
| 362 |
|
| 363 |
def speech_to_text(self, audio_file) -> str:
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
audio = self.recognizer.record(source)
|
| 367 |
-
text = self.recognizer.recognize_google(audio)
|
| 368 |
-
return text
|
| 369 |
-
except Exception as e:
|
| 370 |
-
logger.error(f"Speech recognition error: {e}")
|
| 371 |
-
return "Could not understand audio"
|
| 372 |
|
| 373 |
def text_to_speech(self, text: str) -> str:
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
self.tts_engine.runAndWait()
|
| 378 |
-
return tmp_file.name
|
| 379 |
-
except Exception as e:
|
| 380 |
-
logger.error(f"Text-to-speech error: {e}")
|
| 381 |
-
return None
|
| 382 |
|
| 383 |
class FinanceAssistantOrchestrator:
|
| 384 |
def __init__(self):
|
|
@@ -498,8 +483,8 @@ def create_stock_performance_chart(viz_data):
|
|
| 498 |
|
| 499 |
async def process_query(query, audio_input):
|
| 500 |
if audio_input:
|
| 501 |
-
#
|
| 502 |
-
query =
|
| 503 |
|
| 504 |
if not query:
|
| 505 |
query = "Generate morning market brief for Asia tech stocks"
|
|
@@ -510,8 +495,8 @@ async def process_query(query, audio_input):
|
|
| 510 |
# Create visualization
|
| 511 |
chart = create_stock_performance_chart(viz_data)
|
| 512 |
|
| 513 |
-
#
|
| 514 |
-
audio_file =
|
| 515 |
|
| 516 |
# Prepare metrics display
|
| 517 |
metrics_html = ""
|
|
@@ -553,8 +538,8 @@ with gr.Blocks(css=custom_css, title="π Multi-Agent Finance Assistant") as de
|
|
| 553 |
gr.HTML("""
|
| 554 |
<div style="text-align: center; padding: 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); border-radius: 15px; margin-bottom: 20px;">
|
| 555 |
<h1 style="color: white; font-size: 2.5em; margin: 0;">π Multi-Agent Finance Assistant</h1>
|
| 556 |
-
<p style="color: white; font-size: 1.2em; margin: 10px 0;">AI-Powered Market Analysis with
|
| 557 |
-
<p style="color: #FFD700; font-size: 1em;">Real-time data β’ Multi-agent orchestration β’
|
| 558 |
</div>
|
| 559 |
""")
|
| 560 |
|
|
@@ -566,7 +551,6 @@ with gr.Blocks(css=custom_css, title="π Multi-Agent Finance Assistant") as de
|
|
| 566 |
placeholder="Ask about Asia tech stocks, risk exposure, earnings surprises...",
|
| 567 |
lines=2
|
| 568 |
)
|
| 569 |
-
audio_input = gr.Audio(label="π€ Voice Input (Optional)", type="filepath")
|
| 570 |
|
| 571 |
with gr.Row():
|
| 572 |
submit_btn = gr.Button("π Generate Market Brief", variant="primary", size="lg")
|
|
@@ -586,7 +570,6 @@ with gr.Blocks(css=custom_css, title="π Multi-Agent Finance Assistant") as de
|
|
| 586 |
lines=10,
|
| 587 |
max_lines=15
|
| 588 |
)
|
| 589 |
-
audio_output = gr.Audio(label="π Voice Output")
|
| 590 |
|
| 591 |
with gr.Column():
|
| 592 |
chart_output = gr.Plot(label="π Market Visualization")
|
|
@@ -596,34 +579,35 @@ with gr.Blocks(css=custom_css, title="π Multi-Agent Finance Assistant") as de
|
|
| 596 |
# Event handlers
|
| 597 |
submit_btn.click(
|
| 598 |
fn=process_query,
|
| 599 |
-
inputs=[query_input,
|
| 600 |
-
outputs=[brief_output, chart_output, metrics_display,
|
| 601 |
)
|
| 602 |
|
| 603 |
morning_brief_btn.click(
|
| 604 |
-
fn=lambda: process_query("Generate comprehensive morning market brief for Asia tech stocks with risk analysis", None),
|
| 605 |
-
outputs=[brief_output, chart_output, metrics_display,
|
| 606 |
)
|
| 607 |
|
| 608 |
risk_analysis_btn.click(
|
| 609 |
-
fn=lambda: process_query("Analyze current risk exposure and portfolio allocation", None),
|
| 610 |
-
outputs=[brief_output, chart_output, metrics_display,
|
| 611 |
)
|
| 612 |
|
| 613 |
earnings_update_btn.click(
|
| 614 |
-
fn=lambda: process_query("Provide latest earnings surprises and analyst updates", None),
|
| 615 |
-
outputs=[brief_output, chart_output, metrics_display,
|
| 616 |
)
|
| 617 |
|
| 618 |
clear_btn.click(
|
| 619 |
-
fn=lambda: ("",
|
| 620 |
-
outputs=[query_input,
|
| 621 |
)
|
| 622 |
|
| 623 |
gr.HTML("""
|
| 624 |
<div style="text-align: center; padding: 15px; background: linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%); border-radius: 10px; margin-top: 20px;">
|
| 625 |
-
<p style="color: white; margin: 0;"><strong>π€ AI Agents Active:</strong> API Agent | Scraping Agent | RAG Retriever | Analysis Agent | Language Agent
|
| 626 |
<p style="color: white; margin: 5px 0 0 0; font-size: 0.9em;">Powered by Gemini 2.0 Flash β’ Real-time market data β’ Multi-source intelligence</p>
|
|
|
|
| 627 |
</div>
|
| 628 |
""")
|
| 629 |
|
|
|
|
| 12 |
from dataclasses import dataclass
|
| 13 |
import logging
|
| 14 |
from bs4 import BeautifulSoup
|
|
|
|
|
|
|
|
|
|
| 15 |
import tempfile
|
| 16 |
import os
|
| 17 |
from threading import Thread
|
|
|
|
| 351 |
return brief.strip()
|
| 352 |
|
| 353 |
class VoiceAgent:
|
| 354 |
+
"""Simplified voice agent without PyAudio dependencies"""
|
| 355 |
def __init__(self):
|
| 356 |
+
self.enabled = False
|
| 357 |
+
logger.info("Voice agent initialized in text-only mode (audio libraries not available)")
|
|
|
|
|
|
|
| 358 |
|
| 359 |
def speech_to_text(self, audio_file) -> str:
|
| 360 |
+
"""Placeholder for speech-to-text functionality"""
|
| 361 |
+
return "Voice input not available in this deployment. Please use text input."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 362 |
|
| 363 |
def text_to_speech(self, text: str) -> str:
|
| 364 |
+
"""Placeholder for text-to-speech functionality"""
|
| 365 |
+
logger.info("Text-to-speech requested but not available in this deployment")
|
| 366 |
+
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 367 |
|
| 368 |
class FinanceAssistantOrchestrator:
|
| 369 |
def __init__(self):
|
|
|
|
| 483 |
|
| 484 |
async def process_query(query, audio_input):
|
| 485 |
if audio_input:
|
| 486 |
+
# Note: Audio processing disabled in this version
|
| 487 |
+
query = "Audio input not supported in this deployment. Please use text input."
|
| 488 |
|
| 489 |
if not query:
|
| 490 |
query = "Generate morning market brief for Asia tech stocks"
|
|
|
|
| 495 |
# Create visualization
|
| 496 |
chart = create_stock_performance_chart(viz_data)
|
| 497 |
|
| 498 |
+
# Audio output disabled
|
| 499 |
+
audio_file = None
|
| 500 |
|
| 501 |
# Prepare metrics display
|
| 502 |
metrics_html = ""
|
|
|
|
| 538 |
gr.HTML("""
|
| 539 |
<div style="text-align: center; padding: 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); border-radius: 15px; margin-bottom: 20px;">
|
| 540 |
<h1 style="color: white; font-size: 2.5em; margin: 0;">π Multi-Agent Finance Assistant</h1>
|
| 541 |
+
<p style="color: white; font-size: 1.2em; margin: 10px 0;">AI-Powered Market Analysis with RAG Integration</p>
|
| 542 |
+
<p style="color: #FFD700; font-size: 1em;">Real-time data β’ Multi-agent orchestration β’ RAG-powered insights</p>
|
| 543 |
</div>
|
| 544 |
""")
|
| 545 |
|
|
|
|
| 551 |
placeholder="Ask about Asia tech stocks, risk exposure, earnings surprises...",
|
| 552 |
lines=2
|
| 553 |
)
|
|
|
|
| 554 |
|
| 555 |
with gr.Row():
|
| 556 |
submit_btn = gr.Button("π Generate Market Brief", variant="primary", size="lg")
|
|
|
|
| 570 |
lines=10,
|
| 571 |
max_lines=15
|
| 572 |
)
|
|
|
|
| 573 |
|
| 574 |
with gr.Column():
|
| 575 |
chart_output = gr.Plot(label="π Market Visualization")
|
|
|
|
| 579 |
# Event handlers
|
| 580 |
submit_btn.click(
|
| 581 |
fn=process_query,
|
| 582 |
+
inputs=[query_input, None], # Audio input disabled
|
| 583 |
+
outputs=[brief_output, chart_output, metrics_display, None, status_output]
|
| 584 |
)
|
| 585 |
|
| 586 |
morning_brief_btn.click(
|
| 587 |
+
fn=lambda: asyncio.run(process_query("Generate comprehensive morning market brief for Asia tech stocks with risk analysis", None)),
|
| 588 |
+
outputs=[brief_output, chart_output, metrics_display, None, status_output]
|
| 589 |
)
|
| 590 |
|
| 591 |
risk_analysis_btn.click(
|
| 592 |
+
fn=lambda: asyncio.run(process_query("Analyze current risk exposure and portfolio allocation", None)),
|
| 593 |
+
outputs=[brief_output, chart_output, metrics_display, None, status_output]
|
| 594 |
)
|
| 595 |
|
| 596 |
earnings_update_btn.click(
|
| 597 |
+
fn=lambda: asyncio.run(process_query("Provide latest earnings surprises and analyst updates", None)),
|
| 598 |
+
outputs=[brief_output, chart_output, metrics_display, None, status_output]
|
| 599 |
)
|
| 600 |
|
| 601 |
clear_btn.click(
|
| 602 |
+
fn=lambda: ("", "", "", None, ""),
|
| 603 |
+
outputs=[query_input, brief_output, metrics_display, chart_output, status_output]
|
| 604 |
)
|
| 605 |
|
| 606 |
gr.HTML("""
|
| 607 |
<div style="text-align: center; padding: 15px; background: linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%); border-radius: 10px; margin-top: 20px;">
|
| 608 |
+
<p style="color: white; margin: 0;"><strong>π€ AI Agents Active:</strong> API Agent | Scraping Agent | RAG Retriever | Analysis Agent | Language Agent</p>
|
| 609 |
<p style="color: white; margin: 5px 0 0 0; font-size: 0.9em;">Powered by Gemini 2.0 Flash β’ Real-time market data β’ Multi-source intelligence</p>
|
| 610 |
+
<p style="color: #FFD700; margin: 5px 0 0 0; font-size: 0.8em;">Note: Voice features disabled for compatibility</p>
|
| 611 |
</div>
|
| 612 |
""")
|
| 613 |
|