qwen-image / scripts /wait_ready.py
Mike0021's picture
Publish tested studio source e7481b8ba082
84cbfcb verified
Raw History Blame Contribute Delete
1.17 kB
#!/usr/bin/env python3
"""Observe a deployed Space to readiness without restarting or retrying inference."""
import argparse
from datetime import datetime, timezone
import json
from pathlib import Path
import time
from huggingface_hub import HfApi
p=argparse.ArgumentParser(description=__doc__)
p.add_argument('space');p.add_argument('--timeout',type=int,default=600)
a=p.parse_args();api=HfApi();started=time.perf_counter();rows=[]
out=Path('artifacts/deployment');out.mkdir(parents=True,exist_ok=True)
stamp=datetime.now(timezone.utc).strftime('%Y%m%dT%H%M%S')
while True:
info=api.space_info(a.space)
row={'at':datetime.now(timezone.utc).isoformat(),'elapsed_seconds':time.perf_counter()-started,
'stage':str(info.runtime.stage),'hub_commit':info.sha,'private':info.private,
'hardware':str(info.runtime.hardware)}
rows.append(row);print(json.dumps(row),flush=True)
(out/f'{stamp}-readiness.json').write_text(json.dumps(rows,indent=2))
if row['stage']=='RUNNING':break
if row['stage'] in {'BUILD_ERROR','RUNTIME_ERROR','CONFIG_ERROR'} or row['elapsed_seconds']>a.timeout:
raise SystemExit('Inspect logs before any further mutation')
time.sleep(10)