grady / app.py
bstraehle's picture
Update app.py
1ded0b3 verified
raw
history blame
1.71 kB
import gradio as gr
import os, threading
from agent import run_agent
from helper import get_questions
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, final_answer = run_agent(level, question, file_name)
del os.environ["OPENAI_API_KEY"]
return answer, final_answer, str(final_answer == 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.Textbox(label = "Final 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(),
cache_examples = False
)
demo.launch()