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()