bstraehle's picture
Update app.py
21a2926 verified
raw
history blame
1.62 kB
import gradio as gr
import os, threading
from agents import run_gaia
from crew import get_crew
from helper import get_questions
###
LLM_MANAGER = "o1"
LLM_AGENTS = "gpt-4o"
VERBOSE = False
###
lock = threading.Lock()
def invoke(level, question, file_name, ground_truth, openai_api_key):
if not question:
raise gr.Error("Question is required.")
if not openai_api_key:
raise gr.Error("OpenAI API Key is required.")
with lock:
answer = ""
try:
os.environ["OPENAI_API_KEY"] = openai_api_key
#answer = run_gaia(question, file_name)
answer = str(get_crew(LLM_MANAGER, LLM_AGENTS, VERBOSE).kickoff(inputs={"topic": question}))
except Exception as e:
raise gr.Error(e)
finally:
del os.environ["OPENAI_API_KEY"]
return answer
gr.close_all()
demo = gr.Interface(fn = invoke,
inputs = [gr.Radio([1, 2, 3], label = "Level"),
gr.Textbox(label = "Question"),
gr.Textbox(label = "File Name"),
gr.Textbox(label = "Ground Truth"),
gr.Textbox(label = "OpenAI API Key", type = "password")],
outputs = [gr.Textbox(label = "Answer", lines = 1, interactive = False)],
title = "General AI Assistant (GAIA) 🤖🤝🤖",
description = os.environ["DESCRIPTION"],
examples = get_questions(),
cache_examples = False
)
demo.launch()