| from huggingface_hub import hf_hub_download , snapshot_download , HfFileSystem | |
| import importlib | |
| from pathlib import Path | |
| fs = HfFileSystem() | |
| #def setup_cache_directory(): | |
| # """Setup and return cache directory for private space files""" | |
| #cache_dir = Path("private_space_cache") | |
| # cache_dir.mkdir(exist_ok=True) | |
| # return cache_dir | |
| def download_private_assets(cache_dir): | |
| """Download necessary files from private space""" | |
| try: | |
| # Download entire repository snapshot for directory structure | |
| snapshot_download( | |
| repo_id="ghodrat/app", | |
| repo_type="space", | |
| local_dir=cache_dir, | |
| ) | |
| return True | |
| except Exception as e: | |
| st.error(f"Error downloading private assets: {str(e)}") | |
| return False | |
| #setup_cache_directory() | |
| download_private_assets("private_space_cache") | |
| # snapshot_downloading your private space | |
| snapshot_download( | |
| repo_id="ghodrat/app", | |
| repo_type="space", | |
| cache_dir="private_space_cache" | |
| ) | |
| # calling the app code | |
| app = hf_hub_download( | |
| repo_id="ghodrat/app", | |
| filename="src/streamlit_app.py", | |
| repo_type="space" | |
| ) | |
| # executing the app file | |
| spec_app = importlib.util.spec_from_file_location("*",app_path) | |
| app = importlib.util.module_from_spec(spec_app) | |
| spec_app.loader.exec_module(app) |