Update app.py
Browse files
app.py
CHANGED
@@ -18,6 +18,11 @@ AWS_SESSION = os.getenv('AWS_SESSION')
|
|
18 |
BUCKET_NAME = os.getenv('BUCKET_NAME')
|
19 |
EXTRACTIONS_PATH = os.getenv('EXTRACTIONS_PATH')
|
20 |
|
|
|
|
|
|
|
|
|
|
|
21 |
# Create AWS Bedrock client using environment variables
|
22 |
def create_bedrock_client():
|
23 |
|
@@ -94,12 +99,30 @@ def ask_ds(message, history):
|
|
94 |
|
95 |
if len(message) == 0:
|
96 |
return
|
|
|
|
|
97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
question = message
|
99 |
|
100 |
# RAG
|
101 |
question_embedding = get_titan_embedding(bedrock_client, 'question', question)
|
102 |
-
|
103 |
similar_documents = []
|
104 |
for file, data in extractions.items():
|
105 |
similarity = cosine_similarity(question_embedding, np.array(data['embedding']))
|
@@ -184,7 +207,6 @@ def ask_ds(message, history):
|
|
184 |
# Create necessary services and collect data
|
185 |
bedrock_client = create_bedrock_client()
|
186 |
s3_client = create_s3_client()
|
187 |
-
extractions = read_json_from_s3()
|
188 |
|
189 |
-
demo = gr.ChatInterface(fn=ask_ds, title="Ask DS", multimodal=False, chatbot=gr.Chatbot(value=[(None, "
|
190 |
demo.launch()
|
|
|
18 |
BUCKET_NAME = os.getenv('BUCKET_NAME')
|
19 |
EXTRACTIONS_PATH = os.getenv('EXTRACTIONS_PATH')
|
20 |
|
21 |
+
employee_type = None
|
22 |
+
division = None
|
23 |
+
authenticated = False
|
24 |
+
extractions = {}
|
25 |
+
|
26 |
# Create AWS Bedrock client using environment variables
|
27 |
def create_bedrock_client():
|
28 |
|
|
|
99 |
|
100 |
if len(message) == 0:
|
101 |
return
|
102 |
+
|
103 |
+
if authenticated == False:
|
104 |
|
105 |
+
if division == None:
|
106 |
+
if message.lower().strip() in ['ime', 'peer disability', 'pas']:
|
107 |
+
division = message.lower().strip().replace(' ', '_')
|
108 |
+
return "[1] CSR\n[2] QA"
|
109 |
+
else:
|
110 |
+
return "Please select a valid choice."
|
111 |
+
elif employee_type == None:
|
112 |
+
if message.lower().strip() in ['csr', 'qa']:
|
113 |
+
employee_type = message.lower().strip()
|
114 |
+
authenticated = True
|
115 |
+
EXTRACTIONS_PATH = EXTRACTIONS_PATH.replace('{employee_type}', employee_type).replace('{division}', division)
|
116 |
+
extractions = read_json_from_s3()
|
117 |
+
return "Welcome to Ask Dane Street! Whether you're new to the team or just looking for some quick information, I'm here to guide you through our company's literature and platform. Simply ask your question, and I'll provide you with the most relevant information I can."
|
118 |
+
else:
|
119 |
+
return "Please select a valid choice."
|
120 |
+
|
121 |
question = message
|
122 |
|
123 |
# RAG
|
124 |
question_embedding = get_titan_embedding(bedrock_client, 'question', question)
|
125 |
+
|
126 |
similar_documents = []
|
127 |
for file, data in extractions.items():
|
128 |
similarity = cosine_similarity(question_embedding, np.array(data['embedding']))
|
|
|
207 |
# Create necessary services and collect data
|
208 |
bedrock_client = create_bedrock_client()
|
209 |
s3_client = create_s3_client()
|
|
|
210 |
|
211 |
+
demo = gr.ChatInterface(fn=ask_ds, title="Ask DS", multimodal=False, chatbot=gr.Chatbot(value=[(None, "Select your division:\n[1] IME \n[2] PAS\n[3] Peer Disability")],),theme=theme)
|
212 |
demo.launch()
|