Spaces:
Sleeping
Sleeping
Update rag.py
Browse files
rag.py
CHANGED
@@ -8,7 +8,7 @@ from PIL import Image, ImageDraw, ImageFont
|
|
8 |
import numpy as np
|
9 |
from dotenv import load_dotenv
|
10 |
import os
|
11 |
-
import pandas as pd
|
12 |
import csv
|
13 |
import os
|
14 |
|
@@ -66,21 +66,26 @@ def get_best_answer(user_input):
|
|
66 |
# βοΈ If not matched well, log to CSV
|
67 |
if best_score < 0.65:
|
68 |
file_path = "unmatched_queries.csv"
|
|
|
69 |
|
70 |
# Check if file exists
|
71 |
if not os.path.exists(file_path):
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
|
|
76 |
|
77 |
try:
|
78 |
-
# Append new query
|
79 |
with open(file_path, mode="a", newline="", encoding="utf-8") as file:
|
80 |
writer = csv.writer(file)
|
81 |
writer.writerow([user_input])
|
|
|
82 |
except Exception as e:
|
83 |
-
print(f"
|
84 |
|
85 |
# π§ Prompt construction
|
86 |
if best_score >= 0.65:
|
@@ -114,4 +119,3 @@ def get_best_answer(user_input):
|
|
114 |
π ue.edu.pk"""
|
115 |
|
116 |
return response
|
117 |
-
|
|
|
8 |
import numpy as np
|
9 |
from dotenv import load_dotenv
|
10 |
import os
|
11 |
+
import pandas as pd
|
12 |
import csv
|
13 |
import os
|
14 |
|
|
|
66 |
# βοΈ If not matched well, log to CSV
|
67 |
if best_score < 0.65:
|
68 |
file_path = "unmatched_queries.csv"
|
69 |
+
print(f"[DEBUG] Similarity score too low: {best_score}. Logging query to: {file_path}")
|
70 |
|
71 |
# Check if file exists
|
72 |
if not os.path.exists(file_path):
|
73 |
+
print(f"[DEBUG] File {file_path} does not exist. Creating file with header.")
|
74 |
+
try:
|
75 |
+
with open(file_path, mode="w", newline="", encoding="utf-8") as file:
|
76 |
+
writer = csv.writer(file)
|
77 |
+
writer.writerow(["Unmatched Queries"])
|
78 |
+
print(f"[DEBUG] Header written successfully.")
|
79 |
+
except Exception as e:
|
80 |
+
print(f"[ERROR] Failed to create file: {e}")
|
81 |
|
82 |
try:
|
|
|
83 |
with open(file_path, mode="a", newline="", encoding="utf-8") as file:
|
84 |
writer = csv.writer(file)
|
85 |
writer.writerow([user_input])
|
86 |
+
print(f"[DEBUG] Query logged: {user_input}")
|
87 |
except Exception as e:
|
88 |
+
print(f"[ERROR] Failed to write query to CSV: {e}")
|
89 |
|
90 |
# π§ Prompt construction
|
91 |
if best_score >= 0.65:
|
|
|
119 |
π ue.edu.pk"""
|
120 |
|
121 |
return response
|
|