| import gradio as gr | |
| import os, threading | |
| from agent import run_agent, get_final_answer | |
| from helper import get_questions | |
| LEVEL = 1 | |
| lock = threading.Lock() | |
| def invoke(level, question, file_name, ground_truth, openai_api_key): | |
| if not level: | |
| raise gr.Error("Level is required.") | |
| if not question: | |
| raise gr.Error("Question is required.") | |
| if not ground_truth: | |
| raise gr.Error("Ground Truth is required.") | |
| if not openai_api_key: | |
| raise gr.Error("OpenAI API Key is required.") | |
| with lock: | |
| os.environ["OPENAI_API_KEY"] = openai_api_key | |
| answer, matches_ground_truth = run_agent(level, question, file_name, ground_truth) | |
| final_answer = get_final_answer(question, answer) | |
| del os.environ["OPENAI_API_KEY"] | |
| return final_answer, matches_ground_truth | |
| 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), | |
| gr.Radio(["True", "False"], label = "Matches Ground Truth", interactive = False)], | |
| title = "General AI Assistant (GAIA)", | |
| description = os.environ["DESCRIPTION"], | |
| examples = get_questions(LEVEL), | |
| cache_examples = False | |
| ) | |
| demo.launch() |