import gradio as gr import agentops, os from crew import get_financial_trading_crew AGENTOPS_API_KEY = os.environ["AGENTOPS_API_KEY"] agentops.init() def invoke(openai_api_key, serper_api_key, stock_selection, initial_capital, risk_tolerance, trading_strategy_preference, news_impact_consideration): if (openai_api_key == ""): raise gr.Error("OpenAI API Key is required.") if (serper_api_key == ""): raise gr.Error("Serper API Key is required.") if (stock_selection == ""): raise gr.Error("Stock Ticker is required.") if (initial_capital == ""): raise gr.Error("Initial Capital is required.") if (risk_tolerance == ""): raise gr.Error("Risk Tolerance is required.") if (trading_strategy_preference == ""): raise gr.Error("Trading Strategy Preference is required.") if (news_impact_consideration == ""): raise gr.Error("News Impact Consideration is required.") os.environ["OPENAI_API_KEY"] = openai_api_key os.environ["SERPER_API_KEY"] = serper_api_key financial_trading_inputs = { "stock_selection": stock_selection, "initial_capital": initial_capital, "risk_tolerance": risk_tolerance, "trading_strategy_preference": trading_strategy_preference, "news_impact_consideration": news_impact_consideration } return get_financial_trading_crew().kickoff(inputs=financial_trading_inputs) description = """Gradio UI using the OpenAI SDK with gpt-4 model.""" gr.close_all() demo = gr.Interface(fn = invoke, inputs = [gr.Textbox(label = "OpenAI API Key", type = "password", lines = 1), gr.Textbox(label = "Serper API Key", type = "password", lines = 1), gr.Textbox(label = "Stock Ticker", value="SAN", lines = 1), gr.Textbox(label = "Initial Capital", value=1000, lines = 1), gr.Textbox(label = "Risk Tolerance", value="Medium", lines = 1), gr.Textbox(label = "Trading Strategy Preference", value="Day Trading", lines = 1), gr.Checkbox(label = "News Impact Consideration", value=True)], outputs = [gr.Textbox(label = "Output", lines = 1)], title = "Agentic RAG: Financial Analysis", description = description) demo.launch()