File size: 1,598 Bytes
b484368 7dae5d7 b484368 615dca2 270acfd b484368 7dae5d7 e74736a 7dae5d7 e74736a b484368 2e1dae7 7dae5d7 d17ffb8 b484368 7dae5d7 d7fec4a 7dae5d7 d7fec4a 7dae5d7 30d8c4c 7dae5d7 b484368 8766042 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
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 = run_agent(level, question, file_name)
del os.environ["OPENAI_API_KEY"]
return answer, str(answer.casefold() == ground_truth.casefold())
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(),
cache_examples = False
)
demo.launch() |