File size: 2,140 Bytes
135f6a8
e26e73d
b7092bb
135f6a8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import gradio as gr
from config import Config
#from utils.database import NewsDatabase
from agents.datacollector import DataCollectionAgent
from agents.filterclassifier import FilterClassificationAgent
from agents.sentimentanalyzer import SentimentAnalysisAgent
from agents.alertcoordinator import AlertCoordinatorAgent
from agents.learningagent import LearningAgent
from agents.orchestrator import OrchestratorAgent
from apscheduler.schedulers.background import BackgroundScheduler

config = Config()
db = NewsDatabase(config.DATABASE_PATH)
datacol = DataCollectionAgent(config)
filterer = FilterClassificationAgent(config)
sentiment = SentimentAnalysisAgent()
alert = AlertCoordinatorAgent(config, db)
learner = LearningAgent(config, db)
orchestrator = OrchestratorAgent(datacol, filterer, sentiment, alert, learner)

scheduler = BackgroundScheduler()
scheduler.add_job(lambda: orchestrator.process("AAPL"), 'interval', minutes=config.CHECK_INTERVAL_MINUTES)
scheduler.add_job(learner.learn_and_optimize, 'cron', hour=0)
scheduler.start()


def user_request(user_input):
    # Simple ticker extraction (can expand this for more NLP):
    words = user_input.lower().split()
    ticker = None
    for word in words:
        if word.isalpha() and len(word) <= 5:
            ticker = word.upper()
            break
    if not ticker:
        return "Please specify a stock ticker (e.g. AAPL)."
    # Run through orchestrator:
    results = orchestrator.process(ticker)
    if not results:
        return f"No recent news found for {ticker}."
    output = []
    for r in results:
        output.append(f"Headline: {r['headline']}\nSentiment: {r['sentiment']:.2f}\nSummary: {r['summary']}\n")
    return "\n".join(output)


#def user_request(ticker):
 #   result = orchestrator.process(ticker.upper())
  #  return str(result)

#iface = gr.Interface(fn=user_request, inputs=gr.Textbox(label="Stock Symbol"), outputs=gr.Textbox(label="News/Alerts"), title="Agentic Financial News Monitor")
iface = gr.Interface(fn=user_request, inputs=gr.Textbox(label="What should I track?"), outputs=gr.Textbox(label="Latest News/Sentiment"))
iface.launch()