Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Use permanent storage for database.db
Browse filesFollow-up PR after [#2](https://huggingface.co/spaces/ttseval/TTS-Arena/discussions/2) cc
@mrfakename
@hysts
With this PR, no need to re-download the database if the persistent storage is enabled. This should avoid loosing data because restarts. In case we disable permanent storage in the future (for any reason), the app will still work and default to the local storage as done at the moment.
app.py
CHANGED
@@ -14,7 +14,9 @@ SPACE_ID = os.getenv('HF_ID')
|
|
14 |
|
15 |
DB_DATASET_ID = os.getenv('DATASET_ID')
|
16 |
DB_NAME = "database.db"
|
17 |
-
|
|
|
|
|
18 |
|
19 |
AUDIO_DATASET_ID = "ttseval/tts-arena-new"
|
20 |
|
@@ -79,14 +81,14 @@ def get_leaderboard():
|
|
79 |
####################################
|
80 |
|
81 |
# Download existing DB
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
|
91 |
# Create DB table (if doesn't exist)
|
92 |
create_db_if_missing()
|
|
|
14 |
|
15 |
DB_DATASET_ID = os.getenv('DATASET_ID')
|
16 |
DB_NAME = "database.db"
|
17 |
+
|
18 |
+
# If /data available => means local storage is enabled => let's use it!
|
19 |
+
DB_PATH = f"/data/{DB_NAME}" if os.path.isdir("/data") else DB_NAME
|
20 |
|
21 |
AUDIO_DATASET_ID = "ttseval/tts-arena-new"
|
22 |
|
|
|
81 |
####################################
|
82 |
|
83 |
# Download existing DB
|
84 |
+
if not os.path.isfile(DB_PATH):
|
85 |
+
print("Downloading DB...")
|
86 |
+
try:
|
87 |
+
cache_path = hf_hub_download(repo_id=DB_DATASET_ID, repo_type='dataset', filename=DB_NAME)
|
88 |
+
shutil.copyfile(cache_path, DB_PATH)
|
89 |
+
print("Downloaded DB")
|
90 |
+
except Exception as e:
|
91 |
+
print("Error while downloading DB:", e)
|
92 |
|
93 |
# Create DB table (if doesn't exist)
|
94 |
create_db_if_missing()
|