Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Use permanent storage for database.db (#4)
Browse files- Use permanent storage for database.db (baf8348ca0a6ebc8ca738457535b47a5e1dcb3b6)
Co-authored-by: Lucain Pouget <[email protected]>
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()
|