Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,40 +1,35 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
import os
|
| 3 |
|
| 4 |
-
from
|
| 5 |
|
| 6 |
-
|
| 7 |
-
"max_tokens": 1000,
|
| 8 |
-
"model": "gpt-4",
|
| 9 |
-
"temperature": 0
|
| 10 |
-
}
|
| 11 |
-
|
| 12 |
-
def invoke(openai_api_key, prompt):
|
| 13 |
if (openai_api_key == ""):
|
| 14 |
raise gr.Error("OpenAI API Key is required.")
|
| 15 |
-
if (
|
| 16 |
-
raise gr.Error("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
os.environ["OPENAI_API_KEY"] = openai_api_key
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
messages = [{"role": "user", "content": prompt}],
|
| 28 |
-
model = config["model"],
|
| 29 |
-
temperature = config["temperature"])
|
| 30 |
|
| 31 |
-
|
| 32 |
-
except Exception as e:
|
| 33 |
-
err_msg = e
|
| 34 |
-
|
| 35 |
-
raise gr.Error(e)
|
| 36 |
-
|
| 37 |
-
return content
|
| 38 |
|
| 39 |
description = """<a href='https://www.gradio.app/'>Gradio</a> UI using the <a href='https://openai.com/'>OpenAI</a> SDK
|
| 40 |
with <a href='https://openai.com/research/gpt-4'>gpt-4</a> model."""
|
|
@@ -43,9 +38,14 @@ gr.close_all()
|
|
| 43 |
|
| 44 |
demo = gr.Interface(fn = invoke,
|
| 45 |
inputs = [gr.Textbox(label = "OpenAI API Key", type = "password", lines = 1),
|
| 46 |
-
gr.Textbox(label = "
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
description = description)
|
| 50 |
|
| 51 |
demo.launch()
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
|
| 3 |
+
from crews import get_financial_trading_crew
|
| 4 |
|
| 5 |
+
def invoke(openai_api_key, serper_api_key, stock_selection, initial_capital, risk_tolerance, trading_strategy_preference, news_impact_consideration):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
if (openai_api_key == ""):
|
| 7 |
raise gr.Error("OpenAI API Key is required.")
|
| 8 |
+
if (serp_api_key == ""):
|
| 9 |
+
raise gr.Error("SERPER API Key is required.")
|
| 10 |
+
if (stock_selection == ""):
|
| 11 |
+
raise gr.Error("Stock Ticker is required.")
|
| 12 |
+
if (initial_capital == ""):
|
| 13 |
+
raise gr.Error("Initial Capital is required.")
|
| 14 |
+
if (risk_tolerance == ""):
|
| 15 |
+
raise gr.Error("Risk Tolerance is required.")
|
| 16 |
+
if (trading_strategy_preference == ""):
|
| 17 |
+
raise gr.Error("Trading Strategy Preference is required.")
|
| 18 |
+
if (news_impact_consideration == ""):
|
| 19 |
+
raise gr.Error("News Impact Consideration is required.")
|
| 20 |
|
| 21 |
os.environ["OPENAI_API_KEY"] = openai_api_key
|
| 22 |
+
os.environ["SERPER_API_KEY"] = serper_api_key
|
| 23 |
|
| 24 |
+
financial_trading_inputs = {
|
| 25 |
+
'stock_selection': stock_selection,
|
| 26 |
+
'initial_capital': initial_capital,
|
| 27 |
+
'risk_tolerance': risk_tolerance,
|
| 28 |
+
'trading_strategy_preference': trading_strategy_preference,
|
| 29 |
+
'news_impact_consideration': news_impact_consideration
|
| 30 |
+
}
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
+
return financial_trading_crew.kickoff(inputs=financial_trading_inputs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
description = """<a href='https://www.gradio.app/'>Gradio</a> UI using the <a href='https://openai.com/'>OpenAI</a> SDK
|
| 35 |
with <a href='https://openai.com/research/gpt-4'>gpt-4</a> model."""
|
|
|
|
| 38 |
|
| 39 |
demo = gr.Interface(fn = invoke,
|
| 40 |
inputs = [gr.Textbox(label = "OpenAI API Key", type = "password", lines = 1),
|
| 41 |
+
gr.Textbox(label = "SERPER API Key", type = "password", lines = 1),
|
| 42 |
+
gr.Textbox(label = "Stock Ticker", value="SAN", lines = 1),
|
| 43 |
+
gr.Textbox(label = "Initial Capital", value=1000, lines = 1),
|
| 44 |
+
gr.Textbox(label = "Risk Tolerance", value="Medium", lines = 1),
|
| 45 |
+
gr.Textbox(label = "Trading Strategy Preference", value="Day Trading", lines = 1),
|
| 46 |
+
gr.Textbox(label = "News Impact Consideration", value=True, lines = 1)],
|
| 47 |
+
outputs = [gr.Textbox(label = "Output", lines = 1)],
|
| 48 |
+
title = "Agentic RAG: Financial Analysis",
|
| 49 |
description = description)
|
| 50 |
|
| 51 |
demo.launch()
|