File size: 1,354 Bytes
b484368
7dae5d7
b484368
be96b46
101d6fc
b484368
 
 
9ed84b2
7dae5d7
 
03bd826
b484368
 
 
 
1326d25
f3ed293
 
1326d25
be96b46
f3ed293
 
 
 
 
03bd826
b484368
 
 
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
import gradio as gr
import os, threading

from crew import run_crew
from util import get_questions

lock = threading.Lock()

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.")

    with lock:
        answer = ""

        try:
            os.environ["OPENAI_API_KEY"] = openai_api_key
            answer = run_crew()
        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.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)],
                    title="General AI Assistant (GAIA) 🤖🤝🤖",
                    description=os.environ["DESCRIPTION"],
                    examples=get_questions(),
                    cache_examples=False
                   )

demo.launch()