Spaces:
Paused
Paused
Delete check_space.py with huggingface_hub
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970import os, requests, json
HF_TOKEN = os.environ["HF_TOKEN"]REPO_ID = "mansui52001/grok2api"ADMIN_KEY = os.environ.get("MANAGEMENT_PASSWORD", "xiaobai640438859@qq.com")headers = {"Authorization": f"Bearer {HF_TOKEN}"}
# Check runtime status and secretsprint("=== Space Runtime Status ===")stage = "unknown"try: r = requests.get(f"https://huggingface.co/api/spaces/{REPO_ID}", headers=headers, timeout=30) if r.status_code == 200: data = r.json() runtime = data.get('runtime', {}) stage = runtime.get('stage', 'unknown') print(f"Stage: {stage}") secrets_list = runtime.get('secrets', []) print(f"Secrets: {secrets_list}") else: print(f"Space API: {r.status_code} {r.text[:200]}")except Exception as e: print(f"Space check error: {e}")
# If APP_STARTING, wait and retryif stage == "APP_STARTING": import time for i in range(6): print(f"Waiting 30s for app to start (attempt {i+1}/6)...") time.sleep(30) try: r = requests.get(f"https://huggingface.co/api/spaces/{REPO_ID}/runtime", headers=headers, timeout=30) if r.status_code == 200: data = r.json() stage = data.get('stage', 'unknown') print(f" Stage: {stage}") if stage in ("RUNNING", "RUNTIME_ERROR", "CONFIG_ERROR", "STOPPED", "PAUSED"): break except: pass
# Check auth files via management APIprint("\n=== Auth Files ===")try: r = requests.get(f"https://mansui52001-grok2api.hf.space/v0/management/auth-files", headers={"Authorization": f"Bearer {ADMIN_KEY}"}, timeout=30) if r.status_code == 200: data = r.json() auths = data if isinstance(data, list) else data.get('auths', data.get('files', [])) active = [a for a in auths if a.get('status') == 'active'] disabled = [a for a in auths if a.get('status') == 'disabled'] print(f"Total: {len(auths)}, Active: {len(active)}, Disabled: {len(disabled)}") for a in auths: print(f" {a.get('email', a.get('label', a.get('id','?'))):40s} | {a.get('status','?'):10s} | source: {a.get('source','?')} | path: {a.get('path','?')}") else: print(f"Auth API: {r.status_code} {r.text[:200]}")except Exception as e: print(f"Auth check error: {e}")
# Check configprint("\n=== Config ===")try: r = requests.get(f"https://mansui52001-grok2api.hf.space/v0/management/config.yaml", headers={"Authorization": f"Bearer {ADMIN_KEY}"}, timeout=30) if r.status_code == 200: print(r.text) else: print(f"Config API: {r.status_code}")except Exception as e: print(f"Config check error: {e}")check_space.pyDeleted-70