Spaces:
Sleeping
Sleeping
Lisa Dunlap
Add persistent storage support for Hugging Face Spaces - Enhanced app.py with automatic persistent storage detection - Added comprehensive persistent storage utilities - Added documentation and examples - Automatic HF_HOME and cache configuration for /data directory
f850bde
import os | |
from pathlib import Path | |
from lmmvibes.vis_gradio.app import launch_app | |
from lmmvibes.utils.persistent_storage import ( | |
get_hf_home_dir, | |
get_cache_dir, | |
is_persistent_storage_available, | |
get_storage_info | |
) | |
# Launch the app for Hugging Face Spaces | |
if __name__ == "__main__": | |
# Set up persistent storage for Hugging Face Spaces | |
if is_persistent_storage_available(): | |
print("π Persistent storage available - configuring for HF Spaces") | |
# Set Hugging Face cache to persistent storage | |
hf_home = get_hf_home_dir() | |
os.environ.setdefault("HF_HOME", str(hf_home)) | |
# Set cache directory for other libraries | |
cache_dir = get_cache_dir() | |
os.environ.setdefault("TRANSFORMERS_CACHE", str(cache_dir / "transformers")) | |
os.environ.setdefault("HF_DATASETS_CACHE", str(cache_dir / "datasets")) | |
# Print storage info | |
storage_info = get_storage_info() | |
print(f"π Data directory: {storage_info['data_dir']}") | |
print(f"ποΈ Cache directory: {storage_info['cache_dir']}") | |
print(f"π€ HF Home: {storage_info['hf_home']}") | |
if storage_info['storage_paths']: | |
print(f"πΎ Storage: {storage_info['storage_paths']['free_gb']:.1f}GB free / {storage_info['storage_paths']['total_gb']:.1f}GB total") | |
else: | |
print("β οΈ Persistent storage not available - using local storage") | |
# Launch the Gradio app | |
launch_app(share=False, server_name="0.0.0.0", server_port=7860) |