bstraehle's picture
Update app.py
37d316b verified
raw
history blame
1.8 kB
import gradio as gr
import agentops, logging, os
from crew import get_crew
from openai import OpenAI
def invoke(openai_api_key, serper_api_key, topic):
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 (topic == ""):
raise gr.Error("Topic is required.")
os.environ["OPENAI_API_KEY"] = openai_api_key
os.environ["SERPER_API_KEY"] = serper_api_key
OPENAI_API_KEY = os.environ["OPENAI_API_KEY"]
AGENTOPS_API_KEY = os.environ["AGENTOPS_API_KEY"]
logging.basicConfig(level=logging.DEBUG)
openai = OpenAI(api_key=OPENAI_API_KEY)
agentops.init(AGENTOPS_API_KEY)
financial_trading_inputs = {
'stock_selection': 'AAPL',
'initial_capital': '100000',
'risk_tolerance': 'Medium',
'trading_strategy_preference': 'Day Trading',
'news_impact_consideration': True
}
return get_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 = "Topic", value="Agentic Retrieval-Augmented Generation", lines = 1)],
outputs = [gr.Textbox(label = "Output", lines = 1)],
title = "Agentic RAG: Write Blog Post",
description = description)
demo.launch()