File size: 2,200 Bytes
cae66c0
 
 
 
 
e41680b
 
 
 
cae66c0
 
 
 
 
 
 
 
ef7c237
 
 
 
 
 
 
 
 
cae66c0
 
 
 
 
 
ef7c237
cae66c0
 
e183901
 
 
 
 
 
 
 
cae66c0
e183901
 
 
 
 
 
 
 
 
ef7c237
 
 
 
 
 
 
 
 
 
 
 
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
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(message, history, additional_input):
    if additional_input == "Public":
        assist = assit_public   
    elif additional_input == "Secret":
        assist = Secret   
    elif additional_input == "Public_to_Compliance":
        assist = assit_Public_to_Compliance   
    elif additional_input == "HR_Director":
        assist = Confidential_HR_Director  
    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": message})
    response = output[0].content[0].text.value
    return response
css = """
label[data-testid="block-label"] {
    display: none !important;
}
footer {
    display: none !important;
}
"""

js_func = """
function refresh() {
    const url = new URL(window.location);
    if (url.searchParams.get('__theme') !== 'dark') {
        url.searchParams.set('__theme', 'dark');
        window.location.href = url.href;
    }
}
"""
with gr.Blocks(css=css, js = js_func, theme="soft") as demo:
    chatbot = gr.Chatbot(placeholder="<strong>Your Personal AI</strong><br>Ask Me Anything")
    additional_input = gr.Dropdown(choices=["Public", "Secret", "Public_to_Compliance","HR_Director"], label="Select Knowledge Base")

    gr.ChatInterface(
        fn=get_answer,
        type="messages",
        chatbot=chatbot,
        additional_inputs=[additional_input]  # Add the additional input to the ChatInterface
    )

demo.launch(show_error=True,debug=True)