File size: 1,988 Bytes
7dae5d7 328500b be96b46 101d6fc b484368 4ca4c72 21d1db3 b484368 453dcab 7dae5d7 7dcc866 453dcab b484368 3ad86cf 7914072 3ad86cf 6aa678c b484368 1326d25 f3ed293 7dcc866 453dcab 3ad86cf f3ed293 7dcc866 453dcab f3ed293 03bd826 b484368 08daa84 81ef95c fde0c14 e9b9ab3 0c29cd6 fde0c14 0c29cd6 ef1c64c 08daa84 21d1db3 08daa84 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 45 46 47 48 49 50 51 52 53 54 55 56 |
import os, threading
import gradio as gr
from crew import run_crew
from util import get_questions
QUESTION_FILE_PATH = "data/gaia_validation.jsonl"
QUESTION_LEVEL = 1
def invoke(level, question, 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()
demo = 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 🤖🤝🤖",
description=os.environ["DESCRIPTION"],
examples=get_questions(QUESTION_FILE_PATH, QUESTION_LEVEL),
cache_examples=False
)
demo.launch() |