Spaces:
Build error
Build error
Commit ·
436586a
1
Parent(s): 24cbc9a
update
Browse files32 unmodified lines33343536363738394038394041424344424546474849505152535455454656575859606162636465666768697071144 unmodified lines21621721819819920020120220320420520620720820921021121221321421521621721922022132 unmodified lines "FN": "htmls_COT/FN"}
# Function to save session data to a file
def 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) 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')
# Function to load session data from a file 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: with open(f'session_data/{username}_session.json', 'r') as f: return json.load(f) 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 data except FileNotFoundError: logger.warning(f"No session data found for user {username}") return None except 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 data save_session_data(username, session_data)
# Write feedback to a separate JSON file os.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']):app.py+28-27