Spaces:
Build error
Build error
Commit ·
436586a
1
Parent(s): 24cbc9a
update
Browse files32 unmodified lines333435363738394041424344454647484950144 unmodified lines19519619719819920020120220320420520620720820921021121221321421521621721821922032 unmodified lines"FN": "htmls_COT/FN"}# Function to save session data to a filedef save_session_data(username, data):os.makedirs('session_data', exist_ok=True)with open(f'session_data/{username}_session.json', 'w') as f:json.dump(data, f)# Function to load session data from a filedef load_session_data(username):try:with open(f'session_data/{username}_session.json', 'r') as f:return json.load(f)except FileNotFoundError:return None# Load all sample files from the directories based on the selected method144 unmodified lines# Save updated session datasave_session_data(username, session_data)# Write feedback to a separate JSON fileos.makedirs('session_data', exist_ok=True)feedback_file = f'session_data/{username}_feedback.json'if os.path.exists(feedback_file):with open(feedback_file, 'r') as f:feedback_data = json.load(f)else:feedback_data = []feedback_data.append({'sample_id': session_data['current_index'] - 1,'feedback': feedback,'timestamp': datetime.now().isoformat()})with open(feedback_file, 'w') as f:json.dump(feedback_data, f, indent=4)logger.info(f"Feedback saved for user {username}, sample {session_data['current_index'] - 1}")if session_data['current_index'] >= len(session_data['selected_samples']):32 unmodified lines333435363738394041424344454647484950515253545556575859606162636465666768697071144 unmodified lines21621721821922022132 unmodified lines"FN": "htmls_COT/FN"}def save_session_data(username, data):try:base_dir = os.path.dirname(os.path.abspath(__file__))session_dir = os.path.join(base_dir, 'session_data')os.makedirs(session_dir, exist_ok=True)file_path = os.path.join(session_dir, f'{username}_session.json')with open(file_path, 'w') as f:json.dump(data, f, indent=4)logger.info(f"Session data saved for user {username} at {file_path}")except Exception as e:logger.exception(f"Error saving session data for user {username}: {e}")# Similarly, update the load_session_data functiondef load_session_data(username):try:base_dir = os.path.dirname(os.path.abspath(__file__))file_path = os.path.join(base_dir, 'session_data', f'{username}_session.json')with open(file_path, 'r') as f:data = json.load(f)logger.info(f"Session data loaded for user {username} from {file_path}")return dataexcept FileNotFoundError:logger.warning(f"No session data found for user {username}")return Noneexcept Exception as e:logger.exception(f"Error loading session data for user {username}: {e}")return None# Load all sample files from the directories based on the selected method144 unmodified lines# Save updated session datasave_session_data(username, session_data)logger.info(f"Feedback saved for user {username}, sample {session_data['current_index'] - 1}")if session_data['current_index'] >= len(session_data['selected_samples']):
app.py+28-27