Update app.py
Browse files
app.py
CHANGED
|
@@ -101,8 +101,8 @@ def chatbot_response(query, chat_history):
|
|
| 101 |
similarity_scores = cosine_similarity(query_embedding.cpu().numpy(), question_embeddings.cpu().numpy())[0]
|
| 102 |
best_idx = int(np.argmax(similarity_scores))
|
| 103 |
best_score = similarity_scores[best_idx]
|
| 104 |
-
|
| 105 |
-
matched_a =
|
| 106 |
|
| 107 |
if best_score < 0.4:
|
| 108 |
response = "Sorry, but the PUP handbook does not contain such information."
|
|
@@ -119,11 +119,15 @@ def chatbot_response(query, chat_history):
|
|
| 119 |
print(f"[ERROR] HF inference failed: {e}")
|
| 120 |
response = f"(Fallback) {matched_a}"
|
| 121 |
else:
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
chat_history.append((query, response.strip()))
|
| 125 |
return "", chat_history, gr.update(visible=True)
|
| 126 |
|
|
|
|
| 127 |
def record_feedback(feedback, chat_history):
|
| 128 |
global feedback_embeddings, feedback_questions
|
| 129 |
if chat_history:
|
|
|
|
| 101 |
similarity_scores = cosine_similarity(query_embedding.cpu().numpy(), question_embeddings.cpu().numpy())[0]
|
| 102 |
best_idx = int(np.argmax(similarity_scores))
|
| 103 |
best_score = similarity_scores[best_idx]
|
| 104 |
+
matched_item = dataset[best_idx] # Changed this to get full entry including month/year
|
| 105 |
+
matched_a = matched_item.get("answer", "")
|
| 106 |
|
| 107 |
if best_score < 0.4:
|
| 108 |
response = "Sorry, but the PUP handbook does not contain such information."
|
|
|
|
| 119 |
print(f"[ERROR] HF inference failed: {e}")
|
| 120 |
response = f"(Fallback) {matched_a}"
|
| 121 |
else:
|
| 122 |
+
if "month" in matched_item and "year" in matched_item:
|
| 123 |
+
response = f"As of {matched_item['month']}, {matched_item['year']}, {matched_a}"
|
| 124 |
+
else:
|
| 125 |
+
response = f"According to 2019 Proposed PUP Handbook, {matched_a}"
|
| 126 |
|
| 127 |
chat_history.append((query, response.strip()))
|
| 128 |
return "", chat_history, gr.update(visible=True)
|
| 129 |
|
| 130 |
+
|
| 131 |
def record_feedback(feedback, chat_history):
|
| 132 |
global feedback_embeddings, feedback_questions
|
| 133 |
if chat_history:
|