File size: 1,529 Bytes
b484368
7dae5d7
be96b46
101d6fc
b484368
6aa678c
b484368
9ed84b2
7dae5d7
 
03bd826
b484368
 
 
3ad86cf
 
 
6aa678c
 
b484368
1326d25
f3ed293
 
1326d25
3ad86cf
 
f3ed293
 
 
 
 
03bd826
b484368
 
 
08daa84
 
809adb7
08daa84
 
 
 
 
 
6aa678c
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
import gradio as gr
import os, threading
from crew import run_crew
from util import get_questions

QUESTION_FILE_PATH = "data/gaia_validation_20.jsonl"

def invoke(level, question, file_name, ground_truth, openai_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 file_name:
        file_name = f"data/{file_name}"
    
    lock = threading.Lock()
    
    with lock:
        answer = ""

        try:
            os.environ["OPENAI_API_KEY"] = openai_api_key
            
            answer = run_crew(question, file_name)
        except Exception as e:
            raise gr.Error(e)
        finally:
            del os.environ["OPENAI_API_KEY"]
        
        return answer

gr.close_all()

demo = gr.Interface(fn=invoke, 
                    inputs=[gr.Radio([1, 2, 3], label="Level"),
                            gr.Markdown(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)],
                    title="General AI Assistant (GAIA) 🤖🤝🤖",
                    description=os.environ["DESCRIPTION"],
                    examples=get_questions(QUESTION_FILE_PATH),
                    cache_examples=False
                   )

demo.launch()