app.py
Browse files
app.py
CHANGED
@@ -49,6 +49,14 @@ tab1, tab2 = st.tabs(["Contract", "Technical"])
|
|
49 |
|
50 |
FLAGGED_RESPONSES_FILE = "/mnt/data/flagged_responses.json"
|
51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
def save_flagged_response(user_query, ai_response):
|
53 |
flagged_data = {
|
54 |
"query": user_query,
|
@@ -56,14 +64,11 @@ def save_flagged_response(user_query, ai_response):
|
|
56 |
"timestamp": datetime.now().isoformat()
|
57 |
}
|
58 |
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
existing_data = []
|
65 |
-
else:
|
66 |
-
existing_data = []
|
67 |
|
68 |
existing_data.append(flagged_data)
|
69 |
|
|
|
49 |
|
50 |
FLAGGED_RESPONSES_FILE = "/mnt/data/flagged_responses.json"
|
51 |
|
52 |
+
# Ensure the flagged responses file exists
|
53 |
+
def ensure_flagged_file():
|
54 |
+
if not os.path.exists(FLAGGED_RESPONSES_FILE):
|
55 |
+
with open(FLAGGED_RESPONSES_FILE, "w") as file:
|
56 |
+
json.dump([], file) # Initialize with an empty list
|
57 |
+
|
58 |
+
ensure_flagged_file()
|
59 |
+
|
60 |
def save_flagged_response(user_query, ai_response):
|
61 |
flagged_data = {
|
62 |
"query": user_query,
|
|
|
64 |
"timestamp": datetime.now().isoformat()
|
65 |
}
|
66 |
|
67 |
+
with open(FLAGGED_RESPONSES_FILE, "r") as file:
|
68 |
+
try:
|
69 |
+
existing_data = json.load(file)
|
70 |
+
except json.JSONDecodeError:
|
71 |
+
existing_data = []
|
|
|
|
|
|
|
72 |
|
73 |
existing_data.append(flagged_data)
|
74 |
|