mrfakename Wauplin HF staff commited on
Commit
0e3778b
1 Parent(s): e080e91

Use permanent storage for database.db (#4)

Browse files

- Use permanent storage for database.db (baf8348ca0a6ebc8ca738457535b47a5e1dcb3b6)


Co-authored-by: Lucain Pouget <Wauplin@users.noreply.huggingface.co>

Files changed (1) hide show
  1. app.py +11 -9
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
- DB_PATH = "database.db"
 
 
18
 
19
  AUDIO_DATASET_ID = "ttseval/tts-arena-new"
20
 
@@ -79,14 +81,14 @@ def get_leaderboard():
79
  ####################################
80
 
81
  # Download existing DB
82
- print("Downloading DB...")
83
- try:
84
- cache_path = hf_hub_download(repo_id=DB_DATASET_ID, repo_type='dataset', filename=DB_NAME)
85
- shutil.copyfile(cache_path, DB_PATH)
86
- print("Downloaded DB")
87
- except Exception as e:
88
- print("Error while downloading DB:", e)
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()