Spaces:
Running on T4
Running on T4
Download tools/start_api.py from modventures/baseball-engine: direct link, hf CLI and curl.
- Browser
- Download file 1.12 kB
-
https://huggingface.co/spaces/modventures/baseball-engine/resolve/main/tools/start_api.py
- Command line
-
hf download hf://spaces/modventures/baseball-engine/tools/start_api.py
-
curl -L -o start_api.py https://huggingface.co/spaces/modventures/baseball-engine/resolve/main/tools/start_api.py
1.12 kB
| """Prepare SAM once at startup, then run the existing API even if setup is unavailable.""" | |
| import os | |
| from pathlib import Path | |
| import subprocess | |
| import sys | |
| import json | |
| def main(): | |
| worker=Path('/opt/sam-runtime/bin/python') | |
| if worker.is_file() and os.environ.get('BASEBALL_SAM_SKIP_SETUP')!='1': | |
| try: | |
| subprocess.run([str(worker),'-m','tools.prepare_sam_assets'],timeout=600,check=False) | |
| except subprocess.TimeoutExpired: | |
| path=Path(os.environ.get('BASEBALL_DATA_ROOT','/data'))/'sam-setup-status.json' | |
| path.write_text(json.dumps({'status':'unavailable','reason_code':'sam_asset_setup_timeout'})) | |
| from tools.setup_gvhmr_api_worker import launch_optional_setup | |
| try:launch_optional_setup() | |
| except OSError: | |
| print('GVHMR optional setup could not start; continuing API startup',flush=True) | |
| os.execv(sys.executable,[sys.executable,'-m','uvicorn','baseball_batting.api:create_app','--factory', | |
| '--host','0.0.0.0','--port','8000','--workers','1','--timeout-graceful-shutdown','20','--no-access-log']) | |
| if __name__=='__main__':main() | |