Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from langchain.agents.openai_assistant import OpenAIAssistantRunnable
|
3 |
+
from openai import OpenAI
|
4 |
+
import os
|
5 |
+
#sk
|
6 |
+
assit_public = = os.getenv('assit_public')
|
7 |
+
Secret = = os.getenv('Secret')
|
8 |
+
assit_Public_to_Compliance == os.getenv('assit_Public_to_Compliance')
|
9 |
+
Confidential_HR_Director = = os.getenv('Confidential_HR_Director')
|
10 |
+
apikey =os.getenv('openAI')
|
11 |
+
#apikey = os.getenv('openAI') #key from client
|
12 |
+
#agentkey = os.getenv('asstID')
|
13 |
+
os.environ["OPENAI_API_KEY"] = apikey
|
14 |
+
# assit_public
|
15 |
+
# Secret
|
16 |
+
# assit_Public_to_Compliance
|
17 |
+
# Confidential_HR_Director
|
18 |
+
def get_answer(selected_knowledge_base, question):
|
19 |
+
if selected_knowledge_base == "Public":
|
20 |
+
assist = assit_public # Lyft tool
|
21 |
+
elif selected_knowledge_base == "Secret":
|
22 |
+
assist = Secret # Uber tool
|
23 |
+
elif selected_knowledge_base == "Public_to_Compliance":
|
24 |
+
assist = assit_Public_to_Compliance # Uber tool
|
25 |
+
elif selected_knowledge_base == "HR_Director":
|
26 |
+
assist = Confidential_HR_Director # Uber tool
|
27 |
+
else:
|
28 |
+
return "Invalid knowledge base selected."
|
29 |
+
|
30 |
+
# # Use the selected tool to get the answer
|
31 |
+
# response = agent.chat(question) #, tools=[selected_tool]
|
32 |
+
interpreter_assistant = OpenAIAssistantRunnable(assistant_id= assist)
|
33 |
+
output = interpreter_assistant.invoke({"content": question})
|
34 |
+
response = output[0].content[0].text.value
|
35 |
+
return response
|
36 |
+
|
37 |
+
gr.Interface(
|
38 |
+
fn=get_answer,
|
39 |
+
css=css, js = js_func, theme="soft", # base. citrus. soft glass. ocean
|
40 |
+
inputs=[
|
41 |
+
gr.Dropdown(
|
42 |
+
choices=["Public", "Secret", "Public_to_Compliance","HR_Director"],
|
43 |
+
label="Select Knowledge Base"
|
44 |
+
),
|
45 |
+
gr.Textbox(label="Enter your question", lines=3)
|
46 |
+
],
|
47 |
+
outputs="text",
|
48 |
+
title="Finance Companies Control System",
|
49 |
+
description="Ask questions related to the Finance Companies Control System.",
|
50 |
+
).launch(debug = True)
|