Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -116,9 +116,29 @@ QUESTION_SET = [
|
|
116 |
def load_or_initialize_count_json(audio_paths):
|
117 |
# Add filelock to /workspace/count.json
|
118 |
lock_path = COUNT_JSON_PATH + ".lock"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
# Read of count.json will wait for 10 seconds until another thread involving releases it, and then add a lock to it
|
120 |
with FileLock(lock_path, timeout=10):
|
121 |
# If count.json exists: load into count_data
|
|
|
|
|
122 |
# Else initialize count_data with orderedDict
|
123 |
if os.path.exists(COUNT_JSON_PATH):
|
124 |
with open(COUNT_JSON_PATH, "r", encoding="utf-8") as f:
|
|
|
116 |
def load_or_initialize_count_json(audio_paths):
|
117 |
# Add filelock to /workspace/count.json
|
118 |
lock_path = COUNT_JSON_PATH + ".lock"
|
119 |
+
|
120 |
+
try:
|
121 |
+
api = HfApi()
|
122 |
+
repo_id = "intersteller2887/Turing-test-dataset"
|
123 |
+
hf_token = os.getenv("HF_TOKEN")
|
124 |
+
count_json = None
|
125 |
+
|
126 |
+
try:
|
127 |
+
count_json = api.get_file(
|
128 |
+
path_in_repo=COUNT_JSON_REPO_PATH,
|
129 |
+
repo_id=repo_id,
|
130 |
+
repo_type="dataset",
|
131 |
+
token=hf_token
|
132 |
+
)
|
133 |
+
|
134 |
+
except Exception as e:
|
135 |
+
print(f"Could not download count.json from dataset {e}")
|
136 |
+
|
137 |
# Read of count.json will wait for 10 seconds until another thread involving releases it, and then add a lock to it
|
138 |
with FileLock(lock_path, timeout=10):
|
139 |
# If count.json exists: load into count_data
|
140 |
+
with open(COUNT_JSON_PATH, "wb") as f:
|
141 |
+
f.write(count_json)
|
142 |
# Else initialize count_data with orderedDict
|
143 |
if os.path.exists(COUNT_JSON_PATH):
|
144 |
with open(COUNT_JSON_PATH, "r", encoding="utf-8") as f:
|