Spaces:
Sleeping
Sleeping
elibrowne
commited on
Commit
Β·
fdd4e85
1
Parent(s):
e65ac7c
Load first question from list
Browse files
app.py
CHANGED
@@ -37,7 +37,7 @@ mode = 0
|
|
37 |
def load_user_data(id):
|
38 |
global user_data
|
39 |
filename = id.replace('@', '_AT_').replace('.', '_DOT_')
|
40 |
-
if file_exists(filename = "users/" + filename + ".json", repo_id = "ebrowne/test-data", repo_type = "dataset"):
|
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", repo_type = "dataset")
|
@@ -97,6 +97,16 @@ def reset_current_response():
|
|
97 |
"gold_generation": []
|
98 |
}
|
99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
# This method is being used to save each set of individual scores (in case the main files have issues, the data should be saved)
|
101 |
def commit_current_and_reset():
|
102 |
with scheduler.lock:
|
@@ -105,11 +115,6 @@ def commit_current_and_reset():
|
|
105 |
f.write("\n")
|
106 |
reset_current_response()
|
107 |
|
108 |
-
# VARIABLES: will eventually be loaded with JSON from a dataset
|
109 |
-
|
110 |
-
with open("example.json", "r") as f:
|
111 |
-
current_question = json.load(f)
|
112 |
-
|
113 |
# THEMING: colors and styles (Gradio native)
|
114 |
|
115 |
theme = gr.themes.Soft(
|
@@ -344,6 +349,7 @@ with gr.Blocks(theme = theme) as user_eval:
|
|
344 |
user_id = email
|
345 |
load_user_data(user_id) # calls login, downloads data, initializes session
|
346 |
# After loading user data, update with current question
|
|
|
347 |
new_answers = current_question["answers"].copy()
|
348 |
new_answers[current_question["correct_answer_index"]] = "**" + current_question["answers"][current_question["correct_answer_index"]] + "** β
"
|
349 |
return {
|
|
|
37 |
def load_user_data(id):
|
38 |
global user_data
|
39 |
filename = id.replace('@', '_AT_').replace('.', '_DOT_')
|
40 |
+
if file_exists(filename = "users/" + filename + ".json", repo_id = "ebrowne/test-data", repo_type = "dataset", token = os.getenv("HF_TOKEN")):
|
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", repo_type = "dataset")
|
|
|
97 |
"gold_generation": []
|
98 |
}
|
99 |
|
100 |
+
with open("question_data.json", "r") as f:
|
101 |
+
all_questions = json.load(f)
|
102 |
+
|
103 |
+
# Loads the user's current question β this is the first question that the user has not made any progress on.
|
104 |
+
def load_current_question():
|
105 |
+
global current_question
|
106 |
+
q_index = user_data["current"]
|
107 |
+
qid = user_data["order"][q_index]
|
108 |
+
current_question = all_questions[qid]
|
109 |
+
|
110 |
# This method is being used to save each set of individual scores (in case the main files have issues, the data should be saved)
|
111 |
def commit_current_and_reset():
|
112 |
with scheduler.lock:
|
|
|
115 |
f.write("\n")
|
116 |
reset_current_response()
|
117 |
|
|
|
|
|
|
|
|
|
|
|
118 |
# THEMING: colors and styles (Gradio native)
|
119 |
|
120 |
theme = gr.themes.Soft(
|
|
|
349 |
user_id = email
|
350 |
load_user_data(user_id) # calls login, downloads data, initializes session
|
351 |
# After loading user data, update with current question
|
352 |
+
load_current_question()
|
353 |
new_answers = current_question["answers"].copy()
|
354 |
new_answers[current_question["correct_answer_index"]] = "**" + current_question["answers"][current_question["correct_answer_index"]] + "** β
"
|
355 |
return {
|