File size: 4,281 Bytes
7dae5d7 328500b be96b46 a9baea4 b484368 0dd14f5 21d1db3 b484368 38d0703 7dae5d7 7dcc866 453dcab b484368 3ad86cf 7914072 3ad86cf 6aa678c b484368 1326d25 f3ed293 7dcc866 453dcab 3ad86cf f3ed293 7dcc866 453dcab f3ed293 03bd826 b484368 f7e408f 47fa321 ac5c8d9 82b6c79 47fa321 82c358d 9456aa5 f7e408f 35a22c0 798f236 f7e408f d6b79a6 8a64a1b d6b79a6 8a64a1b 1cac6e9 92e1799 1cac6e9 b26a9bd 6449014 38d0703 6449014 798f236 d6b79a6 c8ff2ad 8e9eaa5 c8ff2ad f7e408f 38d0703 f7e408f 38d0703 f7e408f 9456aa5 |
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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
import os, threading
import gradio as gr
from crew import run_crew
from utils import get_questions
QUESTION_FILE_PATH = "data/gaia_validation.jsonl"
QUESTION_LEVEL = 1
def invoke(question, level, file_name, ground_truth, openai_api_key, gemini_api_key):
if not question:
raise gr.Error("Question is required.")
if not openai_api_key:
raise gr.Error("OpenAI API Key is required.")
if not gemini_api_key:
raise gr.Error("Gemini API Key is required.")
if file_name:
file_name = f"data/{file_name}"
lock = threading.Lock()
with lock:
answer = ""
try:
os.environ["OPENAI_API_KEY"] = openai_api_key
os.environ["GEMINI_API_KEY"] = gemini_api_key
answer = run_crew(question, file_name)
except Exception as e:
raise gr.Error(e)
finally:
del os.environ["OPENAI_API_KEY"]
del os.environ["GEMINI_API_KEY"]
return answer
gr.close_all()
"""
gaia = gr.Interface(fn=invoke,
inputs=[gr.Radio([1, 2, 3], label="Level", value=int(os.environ["INPUT_LEVEL"])),
gr.Textbox(label="Question *", value=os.environ["INPUT_QUESTION"]),
gr.Textbox(label="File Name"),
gr.Textbox(label="Ground Truth", value=os.environ["INPUT_GROUND_TRUTH"]),
gr.Textbox(label="OpenAI API Key *", type="password"),
gr.Textbox(label="Gemini API Key *", type="password")],
outputs=[gr.Textbox(label="Answer", lines=1, interactive=False, value=os.environ["OUTPUT"])],
title="General AI Assistant - GAIA π€π€π€",
description=os.environ["DESCRIPTION"],
examples=get_questions(QUESTION_FILE_PATH, QUESTION_LEVEL),
cache_examples=False
)
gaia.launch()
"""
examples = get_questions(QUESTION_FILE_PATH, QUESTION_LEVEL)
with gr.Blocks(title="GAIA") as gaia:
gr.Markdown("## General AI Assistant - GAIA π€π€π€")
gr.Markdown(os.environ.get("DESCRIPTION", ""))
with gr.Row():
with gr.Column(scale=3):
with gr.Row():
question = gr.Textbox(
label="Question *",
value=os.environ.get("INPUT_QUESTION", "")
)
with gr.Row():
with gr.Column(scale=1):
level = gr.Radio(
choices=[1, 2, 3],
label="Level",
value=int(os.environ.get("INPUT_LEVEL", 1))
)
with gr.Column(scale=1):
ground_truth = gr.Textbox(
label="Ground Truth",
value=os.environ.get("INPUT_GROUND_TRUTH", "")
)
with gr.Column(scale=2):
file_name = gr.Textbox(label="File Name")
with gr.Row():
openai_api_key = gr.Textbox(
label="OpenAI API Key *",
type="password"
)
gemini_api_key = gr.Textbox(
label="Gemini API Key *",
type="password"
)
with gr.Row():
clear_btn = gr.ClearButton(
components=[question, level, file_name, ground_truth, openai_api_key, gemini_api_key],
value="Clear"
)
submit_btn = gr.Button("Submit", variant="primary")
with gr.Column(scale=1):
answer = gr.Textbox(
label="Answer",
lines=1,
interactive=False,
value=os.environ.get("OUTPUT", "")
)
submit_btn.click(
fn=invoke,
inputs=[question, level, file_name, ground_truth, openai_api_key, gemini_api_key],
outputs=answer
)
gr.Examples(
examples=examples,
inputs=[question, level, file_name, ground_truth, openai_api_key, gemini_api_key],
outputs=answer,
fn=invoke,
cache_examples=False
)
gaia.launch() |