File size: 1,907 Bytes
cae66c0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from langchain.agents.openai_assistant import OpenAIAssistantRunnable
from openai import OpenAI
import os
#sk
assit_public = = os.getenv('assit_public')
Secret = = os.getenv('Secret')
assit_Public_to_Compliance == os.getenv('assit_Public_to_Compliance')
Confidential_HR_Director = = os.getenv('Confidential_HR_Director') 
apikey =os.getenv('openAI') 
#apikey = os.getenv('openAI')  #key from client
#agentkey = os.getenv('asstID')
os.environ["OPENAI_API_KEY"] = apikey
# assit_public 
# Secret 
# assit_Public_to_Compliance 
# Confidential_HR_Director
def get_answer(selected_knowledge_base, question):
    if selected_knowledge_base == "Public":
        assist = assit_public   # Lyft tool
    elif selected_knowledge_base == "Secret":
        assist = Secret   # Uber tool
    elif selected_knowledge_base == "Public_to_Compliance":
        assist = assit_Public_to_Compliance   # Uber tool
    elif selected_knowledge_base == "HR_Director":
        assist = Confidential_HR_Director  # Uber tool
    else:
        return "Invalid knowledge base selected."

    # # Use the selected tool to get the answer
    # response = agent.chat(question) #, tools=[selected_tool]
    interpreter_assistant = OpenAIAssistantRunnable(assistant_id= assist)
    output = interpreter_assistant.invoke({"content": question})
    response = output[0].content[0].text.value
    return response

gr.Interface(
    fn=get_answer,
    css=css, js = js_func, theme="soft", # base. citrus. soft glass. ocean
    inputs=[
        gr.Dropdown(
            choices=["Public", "Secret", "Public_to_Compliance","HR_Director"],
            label="Select Knowledge Base"
        ),
        gr.Textbox(label="Enter your question", lines=3)
    ],
    outputs="text",
    title="Finance Companies Control System",
    description="Ask questions related to the Finance Companies Control System.",
).launch(debug = True)