File size: 2,113 Bytes
51e559a e92d5c0 51e559a 3ca3e6a 51e559a 3ca3e6a 51e559a 3ca3e6a 9df7818 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
import os
# Is server running in a Hugging Face Space?
IS_SPACE = os.getenv("SYSTEM") == "spaces"
# Database path
DATABASE_PATH = os.getenv("DATABASE_DIR", "tmp_data")
os.makedirs(DATABASE_PATH, exist_ok=True)
DATABASE_FILE = os.path.join(DATABASE_PATH, "database.db")
DATABASE_URL = f"sqlite:///{DATABASE_FILE}"
# Is frontend served by the server?
# In practice: is it running in a production environment?
FRONTEND_PATH = os.getenv("FRONTEND_PATH")
SERVE_FRONTEND = os.getenv("FRONTEND_PATH") is not None
FRONTEND_ASSETS_PATH = (
os.path.join(FRONTEND_PATH, "assets") if FRONTEND_PATH is not None else None
)
FRONTEND_INDEX_PATH = (
os.path.join(FRONTEND_PATH, "index.html") if FRONTEND_PATH is not None else None
)
if SERVE_FRONTEND and (
not os.path.exists(FRONTEND_PATH)
or not os.path.exists(FRONTEND_ASSETS_PATH)
or not os.path.exists(FRONTEND_INDEX_PATH)
):
raise FileNotFoundError(
f"FRONTEND_PATH {FRONTEND_PATH} has not been built correctly. Please build the frontend first by running `pnpm build` from the 'frontend/' directory."
" If you want to run the server in development mode, run `make dev` from the 'backend/' directory and `pnpm dev` from the 'frontend/' directory."
)
# Back-up Hub dataset (optional)
BACKUP_DATASET_ID = os.getenv("BACKUP_DATASET_ID")
HF_TOKEN = os.getenv("HF_TOKEN")
BACKUP_DB = BACKUP_DATASET_ID is not None and HF_TOKEN is not None
if BACKUP_DATASET_ID is not None:
if HF_TOKEN is None:
print(
f"Backup dataset ID {BACKUP_DATASET_ID} is set, but HF_TOKEN is not set."
"\nPlease set HF_TOKEN as environment variable to enable backup."
)
else:
print(f"Backup enabled to dataset: {BACKUP_DATASET_ID}")
else:
if HF_TOKEN is not None:
print(
"HF_TOKEN is set, but BACKUP_DATASET_ID is not set."
"\nPlease set BACKUP_DATASET_ID as environment variable to enable backup."
)
else:
print(
"Backup disabled. You must set BACKUP_DATASET_ID and HF_TOKEN as environment variables to enable backup."
)
|