luulinh90s commited on
Commit
8ffbf70
·
1 Parent(s): 51a1e1a
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -64,11 +64,9 @@ from datetime import datetime
64
 
65
  from huggingface_hub import HfApi
66
 
67
-
68
  def save_session_data(username, data):
69
  try:
70
- timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
71
- file_name = f'{username}_{timestamp}_session.json'
72
 
73
  # Convert data to JSON string
74
  json_data = json.dumps(data, indent=4)
@@ -78,7 +76,7 @@ def save_session_data(username, data):
78
  with open(temp_file_path, 'w') as f:
79
  f.write(json_data)
80
 
81
- # Upload the file to a separate Hugging Face Space dedicated to data storage
82
  api = HfApi()
83
  api.upload_file(
84
  path_or_fileobj=temp_file_path,
@@ -371,6 +369,8 @@ def completed(username):
371
  preferences[method] = round((preferences[method] / total_responses) * 100, 2)
372
 
373
  session_data['preferences'] = preferences
 
 
374
  save_session_data(username, session_data)
375
 
376
  return render_template('completed.html', preferences=preferences)
 
64
 
65
  from huggingface_hub import HfApi
66
 
 
67
  def save_session_data(username, data):
68
  try:
69
+ file_name = f'{username}_session.json'
 
70
 
71
  # Convert data to JSON string
72
  json_data = json.dumps(data, indent=4)
 
76
  with open(temp_file_path, 'w') as f:
77
  f.write(json_data)
78
 
79
+ # Upload the file to the Hugging Face Space, overwriting if it exists
80
  api = HfApi()
81
  api.upload_file(
82
  path_or_fileobj=temp_file_path,
 
369
  preferences[method] = round((preferences[method] / total_responses) * 100, 2)
370
 
371
  session_data['preferences'] = preferences
372
+
373
+ # Save the final updated session data
374
  save_session_data(username, session_data)
375
 
376
  return render_template('completed.html', preferences=preferences)