Spaces:
Running
Running
Fix the relative vs. absolute path issues
#4
by
antoinetran
- opened
- backend/config.py +9 -5
backend/config.py
CHANGED
@@ -2,6 +2,7 @@
|
|
2 |
# IMPORTANT: When running from docker more setup is required (e.g. on Huggingface)
|
3 |
import os
|
4 |
from collections import defaultdict
|
|
|
5 |
|
6 |
ABS_DATASET_DOMAIN = "https://dl.fbaipublicfiles.com"
|
7 |
|
@@ -139,7 +140,8 @@ DATASET_CONFIGS = {
|
|
139 |
|
140 |
def get_user_dataset():
|
141 |
datasets = defaultdict(list)
|
142 |
-
|
|
|
143 |
if user_data_dir:
|
144 |
for user_data in os.listdir(user_data_dir):
|
145 |
if not os.path.isdir(os.path.join(user_data_dir, user_data)):
|
@@ -171,7 +173,7 @@ def get_datasets():
|
|
171 |
def get_example_config(type, dataset_name):
|
172 |
"""Get example configuration for a specific dataset."""
|
173 |
if not dataset_name:
|
174 |
-
raise ValueError(
|
175 |
|
176 |
# Check if it's a valid dataset for this type
|
177 |
all_datasets = get_datasets()
|
@@ -199,7 +201,7 @@ def get_example_config(type, dataset_name):
|
|
199 |
examples_config = {
|
200 |
"dataset_name": dataset_base_name,
|
201 |
"path": dataset_config["path"],
|
202 |
-
"db_key": _get_db_key_for_dataset(dataset_base_name
|
203 |
}
|
204 |
else:
|
205 |
raise ValueError(f"Dataset {dataset_name} not found in configurations")
|
@@ -207,7 +209,7 @@ def get_example_config(type, dataset_name):
|
|
207 |
return examples_config
|
208 |
|
209 |
|
210 |
-
def _get_db_key_for_dataset(dataset_base_name
|
211 |
"""Helper function to determine the database key for a dataset"""
|
212 |
# Map of dataset names to their db keys
|
213 |
db_key_mapping = {
|
@@ -230,10 +232,12 @@ def get_dataset_config(dataset_name):
|
|
230 |
else:
|
231 |
modality = dataset_name.split("/")[-1]
|
232 |
user_dataset = get_user_dataset()
|
|
|
|
|
233 |
if dataset_name in user_dataset.get(modality, []):
|
234 |
cfg = {
|
235 |
"type": modality,
|
236 |
-
"path":
|
237 |
}
|
238 |
extra_cfg = MODALITY_CONFIG_CONSTANTS.get(cfg["type"], {})
|
239 |
cfg.update(extra_cfg)
|
|
|
2 |
# IMPORTANT: When running from docker more setup is required (e.g. on Huggingface)
|
3 |
import os
|
4 |
from collections import defaultdict
|
5 |
+
from pathlib import Path
|
6 |
|
7 |
ABS_DATASET_DOMAIN = "https://dl.fbaipublicfiles.com"
|
8 |
|
|
|
140 |
|
141 |
def get_user_dataset():
|
142 |
datasets = defaultdict(list)
|
143 |
+
default_local_data_dir = str(Path(__file__).parent.joinpath("data"))
|
144 |
+
user_data_dir = os.getenv("OMNISEAL_LEADERBOARD_DATA", default_local_data_dir)
|
145 |
if user_data_dir:
|
146 |
for user_data in os.listdir(user_data_dir):
|
147 |
if not os.path.isdir(os.path.join(user_data_dir, user_data)):
|
|
|
173 |
def get_example_config(type, dataset_name):
|
174 |
"""Get example configuration for a specific dataset."""
|
175 |
if not dataset_name:
|
176 |
+
raise ValueError("Dataset name is required")
|
177 |
|
178 |
# Check if it's a valid dataset for this type
|
179 |
all_datasets = get_datasets()
|
|
|
201 |
examples_config = {
|
202 |
"dataset_name": dataset_base_name,
|
203 |
"path": dataset_config["path"],
|
204 |
+
"db_key": _get_db_key_for_dataset(dataset_base_name),
|
205 |
}
|
206 |
else:
|
207 |
raise ValueError(f"Dataset {dataset_name} not found in configurations")
|
|
|
209 |
return examples_config
|
210 |
|
211 |
|
212 |
+
def _get_db_key_for_dataset(dataset_base_name):
|
213 |
"""Helper function to determine the database key for a dataset"""
|
214 |
# Map of dataset names to their db keys
|
215 |
db_key_mapping = {
|
|
|
232 |
else:
|
233 |
modality = dataset_name.split("/")[-1]
|
234 |
user_dataset = get_user_dataset()
|
235 |
+
default_local_data_dir = str(Path(__file__).parent.joinpath("data"))
|
236 |
+
user_data_dir = os.getenv("OMNISEAL_LEADERBOARD_DATA", default_local_data_dir)
|
237 |
if dataset_name in user_dataset.get(modality, []):
|
238 |
cfg = {
|
239 |
"type": modality,
|
240 |
+
"path": user_data_dir,
|
241 |
}
|
242 |
extra_cfg = MODALITY_CONFIG_CONSTANTS.get(cfg["type"], {})
|
243 |
cfg.update(extra_cfg)
|