umair894 commited on
Commit
ef7c237
1 Parent(s): e183901

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -24
app.py CHANGED
@@ -15,22 +15,22 @@ os.environ["OPENAI_API_KEY"] = apikey
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
  css = """
@@ -51,17 +51,15 @@ function refresh() {
51
  }
52
  }
53
  """
54
- gr.Interface(
55
- fn=get_answer,
56
- css=css, js = js_func, theme="soft", # base. citrus. soft glass. ocean
57
- inputs=[
58
- gr.Dropdown(
59
- choices=["Public", "Secret", "Public_to_Compliance","HR_Director"],
60
- label="Select Knowledge Base"
61
- ),
62
- gr.Textbox(label="Enter your question", lines=3)
63
- ],
64
- outputs="text",
65
- title="Finance Companies Control System",
66
- description="Ask questions related to the Finance Companies Control System.",
67
- ).launch(debug = True)
 
15
  # Secret
16
  # assit_Public_to_Compliance
17
  # Confidential_HR_Director
18
+ def get_answer(message, history, additional_input):
19
+ if additional_input == "Public":
20
+ assist = assit_public
21
+ elif additional_input == "Secret":
22
+ assist = Secret
23
+ elif additional_input == "Public_to_Compliance":
24
+ assist = assit_Public_to_Compliance
25
+ elif additional_input == "HR_Director":
26
+ assist = Confidential_HR_Director
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": message})
34
  response = output[0].content[0].text.value
35
  return response
36
  css = """
 
51
  }
52
  }
53
  """
54
+ with gr.Blocks(css=css, js = js_func, theme="soft") as demo:
55
+ chatbot = gr.Chatbot(placeholder="<strong>Your Personal AI</strong><br>Ask Me Anything")
56
+ additional_input = gr.Dropdown(choices=["Public", "Secret", "Public_to_Compliance","HR_Director"], label="Select Knowledge Base")
57
+
58
+ gr.ChatInterface(
59
+ fn=get_answer,
60
+ type="messages",
61
+ chatbot=chatbot,
62
+ additional_inputs=[additional_input] # Add the additional input to the ChatInterface
63
+ )
64
+
65
+ demo.launch(show_error=True,debug=True)