import gradio as gr import os, threading from crew import get_crew from util import get_questions 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 = get_crew().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()