bstraehle's picture
Update app.py
d015f88 verified
raw
history blame
2.48 kB
import os
from crews import get_financial_trading_crew
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 (serp_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 financial_trading_crew.kickoff(inputs=financial_trading_inputs)
description = """<a href='https://www.gradio.app/'>Gradio</a> UI using the <a href='https://openai.com/'>OpenAI</a> SDK
with <a href='https://openai.com/research/gpt-4'>gpt-4</a> 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.Textbox(label = "News Impact Consideration", value=True, lines = 1)],
outputs = [gr.Textbox(label = "Output", lines = 1)],
title = "Agentic RAG: Financial Analysis",
description = description)
demo.launch()