Spaces:
Sleeping
Sleeping
Deploy commited on
Commit ·
ffef1c5
1
Parent(s): 4b59833
Deploy proxy
Browse files118 unmodified lines119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153118 unmodified lines
if __name__ == "__main__": import uvicorn import threading import time # 启动时自动注册 def auto_register(): time.sleep(10) # 等待服务启动 try: import httpx # 从 HF 环境变量获取 Space 信息 space_id = os.environ.get("SPACE_ID", "") # pyrq/ws-test-xxx if space_id: space_url = f"https://{space_id.replace('/', '-')}.hf.space" # 注册到 Worker(新格式) with httpx.Client(timeout=10.0) as client: client.post( "https://proxy-worker.busitest135.workers.dev/api/instances", json={ "nodeId": space_id, "url": space_url, "platform": "hf", "tags": ["auto"] } ) log_message(f"[AUTO_REGISTER] Registered {space_id} -> {space_url}") except Exception as e: log_message(f"[AUTO_REGISTER] Failed: {e}") threading.Thread(target=auto_register, daemon=True).start() port = int(os.environ.get("PORT", 7860)) uvicorn.run(app, host="0.0.0.0", port=port)app.py+30