Spaces:
Running
Running
File size: 1,599 Bytes
5efbc82 1b567fa 703fff1 1b567fa 703fff1 1b567fa 5efbc82 1b567fa 5efbc82 703fff1 1b567fa 5efbc82 |
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 |
"""
Configuration for Kokoro TTS API, especially for Hugging Face Spaces deployment.
"""
import os
import tempfile
import logging
# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def setup_hf_cache():
"""Setup cache environment variables for Hugging Face Spaces"""
# Use user's home directory for cache
home_dir = os.path.expanduser("~")
cache_dir = os.path.join(home_dir, ".cache")
cache_settings = {
'HF_HOME': cache_dir,
'TRANSFORMERS_CACHE': cache_dir,
'HF_HUB_CACHE': cache_dir,
'TORCH_HOME': cache_dir,
'NUMBA_CACHE_DIR': os.path.join(cache_dir, 'numba'),
'NUMBA_DISABLE_JIT': '1',
'HF_HUB_DISABLE_TELEMETRY': '1'
}
# Set environment variables
for key, value in cache_settings.items():
os.environ[key] = value
logger.info(f"Set {key} to {value}")
# Create cache directories
cache_dirs = [cache_dir, os.path.join(cache_dir, 'numba')]
for cache_path in cache_dirs:
try:
os.makedirs(cache_path, exist_ok=True)
logger.info(f"Created cache directory: {cache_path}")
except Exception as e:
logger.warning(f"Could not create {cache_path}: {e}")
logger.info("Cache environment setup completed")
def get_temp_dir():
"""Get a writable temporary directory"""
return tempfile.gettempdir()
def is_hf_spaces():
"""Check if running on Hugging Face Spaces"""
return os.environ.get('SPACE_ID') is not None
# Initialize cache setup
setup_hf_cache() |