import gradio as gr
import agentops, 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 = openai_api_key
AGENTOPS_API_KEY = serper_api_key
#logging.basicConfig(level=logging.DEBUG)
#openai = OpenAI(api_key=OPENAI_API_KEY)
agentops.init(AGENTOPS_API_KEY)
return get_crew().kickoff(inputs={"topic": topic})
description = """TODO 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 = "Topic", value="Evolution of GenAI/LLM/RAG from naive RAG to advanced RAG to agentic RAG.", lines = 1)],
outputs = [gr.Textbox(label = "Output", lines = 1)],
title = "Agentic RAG: LinkedIn Post Generation",
description = description)
demo.launch()