luulinh90s
commited on
Commit
·
436586a
1
Parent(s):
24cbc9a
update
Browse files
app.py
CHANGED
@@ -33,18 +33,39 @@ VISUALIZATION_DIRS_CHAIN_OF_TABLE = {
|
|
33 |
"FN": "htmls_COT/FN"
|
34 |
}
|
35 |
|
36 |
-
|
37 |
def save_session_data(username, data):
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
41 |
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
def load_session_data(username):
|
44 |
try:
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
except FileNotFoundError:
|
|
|
|
|
|
|
|
|
48 |
return None
|
49 |
|
50 |
# Load all sample files from the directories based on the selected method
|
@@ -195,26 +216,6 @@ def feedback():
|
|
195 |
|
196 |
# Save updated session data
|
197 |
save_session_data(username, session_data)
|
198 |
-
|
199 |
-
# Write feedback to a separate JSON file
|
200 |
-
os.makedirs('session_data', exist_ok=True)
|
201 |
-
feedback_file = f'session_data/{username}_feedback.json'
|
202 |
-
|
203 |
-
if os.path.exists(feedback_file):
|
204 |
-
with open(feedback_file, 'r') as f:
|
205 |
-
feedback_data = json.load(f)
|
206 |
-
else:
|
207 |
-
feedback_data = []
|
208 |
-
|
209 |
-
feedback_data.append({
|
210 |
-
'sample_id': session_data['current_index'] - 1,
|
211 |
-
'feedback': feedback,
|
212 |
-
'timestamp': datetime.now().isoformat()
|
213 |
-
})
|
214 |
-
|
215 |
-
with open(feedback_file, 'w') as f:
|
216 |
-
json.dump(feedback_data, f, indent=4)
|
217 |
-
|
218 |
logger.info(f"Feedback saved for user {username}, sample {session_data['current_index'] - 1}")
|
219 |
|
220 |
if session_data['current_index'] >= len(session_data['selected_samples']):
|
|
|
33 |
"FN": "htmls_COT/FN"
|
34 |
}
|
35 |
|
36 |
+
|
37 |
def save_session_data(username, data):
|
38 |
+
try:
|
39 |
+
base_dir = os.path.dirname(os.path.abspath(__file__))
|
40 |
+
session_dir = os.path.join(base_dir, 'session_data')
|
41 |
+
os.makedirs(session_dir, exist_ok=True)
|
42 |
+
|
43 |
+
file_path = os.path.join(session_dir, f'{username}_session.json')
|
44 |
|
45 |
+
with open(file_path, 'w') as f:
|
46 |
+
json.dump(data, f, indent=4)
|
47 |
+
|
48 |
+
logger.info(f"Session data saved for user {username} at {file_path}")
|
49 |
+
except Exception as e:
|
50 |
+
logger.exception(f"Error saving session data for user {username}: {e}")
|
51 |
+
|
52 |
+
|
53 |
+
# Similarly, update the load_session_data function
|
54 |
def load_session_data(username):
|
55 |
try:
|
56 |
+
base_dir = os.path.dirname(os.path.abspath(__file__))
|
57 |
+
file_path = os.path.join(base_dir, 'session_data', f'{username}_session.json')
|
58 |
+
|
59 |
+
with open(file_path, 'r') as f:
|
60 |
+
data = json.load(f)
|
61 |
+
|
62 |
+
logger.info(f"Session data loaded for user {username} from {file_path}")
|
63 |
+
return data
|
64 |
except FileNotFoundError:
|
65 |
+
logger.warning(f"No session data found for user {username}")
|
66 |
+
return None
|
67 |
+
except Exception as e:
|
68 |
+
logger.exception(f"Error loading session data for user {username}: {e}")
|
69 |
return None
|
70 |
|
71 |
# Load all sample files from the directories based on the selected method
|
|
|
216 |
|
217 |
# Save updated session data
|
218 |
save_session_data(username, session_data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
219 |
logger.info(f"Feedback saved for user {username}, sample {session_data['current_index'] - 1}")
|
220 |
|
221 |
if session_data['current_index'] >= len(session_data['selected_samples']):
|