Update app.py
Browse files
app.py
CHANGED
@@ -10,8 +10,17 @@ faq_embeddings = model.encode(faq_df['question'].tolist(), convert_to_tensor=Tru
|
|
10 |
def chatbot(query):
|
11 |
query_embedding = model.encode(query, convert_to_tensor=True)
|
12 |
scores = util.pytorch_cos_sim(query_embedding, faq_embeddings)[0]
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
with gr.Blocks(title="LIC Agent Assistant") as demo:
|
17 |
gr.Markdown(
|
|
|
10 |
def chatbot(query):
|
11 |
query_embedding = model.encode(query, convert_to_tensor=True)
|
12 |
scores = util.pytorch_cos_sim(query_embedding, faq_embeddings)[0]
|
13 |
+
best_score = float(scores.max()) # Get max similarity score
|
14 |
+
best_idx = int(scores.argmax())
|
15 |
+
|
16 |
+
if best_score < 0.6: # Threshold can be adjusted
|
17 |
+
return (
|
18 |
+
"🤖 I'm not confident I have the right answer for that.\n"
|
19 |
+
"Please ask a question related to LIC policies, claims, onboarding, or commissions."
|
20 |
+
)
|
21 |
+
else:
|
22 |
+
return faq_df.iloc[best_idx]['answer']
|
23 |
+
|
24 |
|
25 |
with gr.Blocks(title="LIC Agent Assistant") as demo:
|
26 |
gr.Markdown(
|