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." )