Spaces:
Sleeping
Sleeping
elibrowne
commited on
Commit
·
e079737
1
Parent(s):
287ff70
Persistence?
Browse files
app.py
CHANGED
|
@@ -40,10 +40,13 @@ def load_user_data(id):
|
|
| 40 |
if file_exists("ebrowne/test-data", "users/" + filename + ".json"):
|
| 41 |
print("File exists, downloading data.")
|
| 42 |
# If the ID exists, download the file from HuggingFace
|
| 43 |
-
hf_hub_download(repo_id="ebrowne/test-data", token = os.getenv("HF_TOKEN"), filename="users/" + filename + ".json")
|
| 44 |
# Add their current status to user_data
|
|
|
|
|
|
|
| 45 |
else:
|
| 46 |
# If the ID doesn't exist, create a format for the file and upload it to HuggingFace
|
|
|
|
| 47 |
shuffle(qIDs)
|
| 48 |
modes = []
|
| 49 |
for i in range(len(qIDs)):
|
|
@@ -61,25 +64,9 @@ def load_user_data(id):
|
|
| 61 |
# Run the update method to upload the new JSON file to HuggingFace
|
| 62 |
update_huggingface(id)
|
| 63 |
|
| 64 |
-
# DELETE ONCE LOGIN IS IMPLEMENTED
|
| 65 |
-
shuffle(qIDs)
|
| 66 |
-
modes = []
|
| 67 |
-
for i in range(len(qIDs)):
|
| 68 |
-
temp = mode_options[:]
|
| 69 |
-
shuffle(temp)
|
| 70 |
-
modes.append(temp)
|
| 71 |
-
print(modes)
|
| 72 |
-
# This is the format for a user's file on HuggingFace
|
| 73 |
-
user_data = {
|
| 74 |
-
"user_id": id, # original in email format, which was passed here
|
| 75 |
-
"order": qIDs, # randomized order for each user
|
| 76 |
-
"modes": modes, # randomized order for each user
|
| 77 |
-
"current": 0, # user starts on first question
|
| 78 |
-
"responses": [] # formatted as a list of current_responses
|
| 79 |
-
}
|
| 80 |
-
|
| 81 |
def update_huggingface(id):
|
| 82 |
global user_data
|
|
|
|
| 83 |
filename = id.replace('@', '_AT_').replace('.', '_DOT_')
|
| 84 |
# Create a local file that will be uploaded to HuggingFace
|
| 85 |
with open(filename + ".json", "w") as f:
|
|
|
|
| 40 |
if file_exists("ebrowne/test-data", "users/" + filename + ".json"):
|
| 41 |
print("File exists, downloading data.")
|
| 42 |
# If the ID exists, download the file from HuggingFace
|
| 43 |
+
path = hf_hub_download(repo_id="ebrowne/test-data", token = os.getenv("HF_TOKEN"), filename="users/" + filename + ".json")
|
| 44 |
# Add their current status to user_data
|
| 45 |
+
with open(path, "r") as f:
|
| 46 |
+
user_data = json.load(f)
|
| 47 |
else:
|
| 48 |
# If the ID doesn't exist, create a format for the file and upload it to HuggingFace
|
| 49 |
+
print("File does not exist, creating user.")
|
| 50 |
shuffle(qIDs)
|
| 51 |
modes = []
|
| 52 |
for i in range(len(qIDs)):
|
|
|
|
| 64 |
# Run the update method to upload the new JSON file to HuggingFace
|
| 65 |
update_huggingface(id)
|
| 66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
def update_huggingface(id):
|
| 68 |
global user_data
|
| 69 |
+
print("Updating data...")
|
| 70 |
filename = id.replace('@', '_AT_').replace('.', '_DOT_')
|
| 71 |
# Create a local file that will be uploaded to HuggingFace
|
| 72 |
with open(filename + ".json", "w") as f:
|