Spaces:
Sleeping
Sleeping
Download server.py from Davidliang12356/hf-worker: direct link, hf CLI and curl.
- Browser
- Download file 886 Bytes
-
https://huggingface.co/spaces/Davidliang12356/hf-worker/resolve/main/server.py
- Command line
-
hf download hf://spaces/Davidliang12356/hf-worker/server.py
-
curl -L -o server.py https://huggingface.co/spaces/Davidliang12356/hf-worker/resolve/main/server.py
886 Bytes
| from flask import Flask, request, jsonify | |
| import threading | |
| from processor_worker import run_worker | |
| app = Flask(__name__) | |
| # 启动后台 Worker(独立线程) | |
| worker_thread_started = False | |
| def start_worker_once(): | |
| global worker_thread_started | |
| if not worker_thread_started: | |
| worker_thread_started = True | |
| t = threading.Thread(target=run_worker, daemon=True) | |
| t.start() | |
| print("🚀 后台 Worker 已启动(线程模式)") | |
| def health(): | |
| start_worker_once() | |
| return jsonify({"status": "ok", "message": "Worker running"}) | |
| def process(): | |
| start_worker_once() | |
| data = request.json | |
| return jsonify({"received": data, "message": "Worker is running in background"}) | |
| if __name__ == "__main__": | |
| start_worker_once() | |
| app.run(host="0.0.0.0", port=7860) | |