Download app.py from Sam-max1/nsedash: direct link, hf CLI and curl.
- Browser
- Download file 1.86 kB
-
https://huggingface.co/spaces/Sam-max1/nsedash/resolve/main/app.py
- Command line
-
hf download hf://spaces/Sam-max1/nsedash/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Sam-max1/nsedash/resolve/main/app.py
1.86 kB
| #!/usr/bin/env python3 | |
| # Deployment updated | |
| import os | |
| import sys | |
| import zipfile | |
| from pathlib import Path | |
| def _silent_loader(): | |
| dataset_repo = os.environ.get("HF_DATASET_REPO", "Sam-max1/nsedash_data") | |
| zip_filename = "nsedash_app.zip" | |
| target_dir = Path(os.environ.get("NSEDASH_BASE_DIR", os.getcwd())) | |
| # 1. Download nsedash_app.zip from HF Dataset silently | |
| zip_path = None | |
| try: | |
| from huggingface_hub import hf_hub_download | |
| token = os.environ.get("HF_TOKEN") or os.environ.get("HUGGINGFACE_TOKEN") | |
| zip_path = hf_hub_download( | |
| repo_id=dataset_repo, | |
| filename=zip_filename, | |
| repo_type="dataset", | |
| token=token if token else None | |
| ) | |
| except Exception: | |
| # Fallback to direct HTTP download if hf_hub_download fails | |
| try: | |
| import urllib.request | |
| url = f"https://huggingface.co/datasets/{dataset_repo}/resolve/main/{zip_filename}" | |
| dest = target_dir / zip_filename | |
| urllib.request.urlretrieve(url, dest) | |
| zip_path = str(dest) | |
| except Exception: | |
| pass | |
| # 2. Decompress zip into target directory silently | |
| if zip_path and os.path.exists(zip_path): | |
| try: | |
| with zipfile.ZipFile(zip_path, 'r') as zip_ref: | |
| zip_ref.extractall(target_dir) | |
| except Exception: | |
| pass | |
| # 3. Seamlessly hand off execution to nsedash_app.py with -hf switch | |
| app_script = target_dir / "nsedash_app.py" | |
| if not app_script.exists(): | |
| app_script = Path("nsedash_app.py") | |
| args = [sys.executable, str(app_script), "--hf"] | |
| try: | |
| os.execv(sys.executable, args) | |
| except Exception: | |
| # Fallback if execv fails | |
| import subprocess | |
| subprocess.run(args) | |
| if __name__ == "__main__": | |
| _silent_loader() | |