Spaces:
Running
Running
th commited on
Commit ·
1700a97
1
Parent(s): c9b4512
fix: bootstrap node deps for gradio runtime
Browse files
app.py
CHANGED
|
@@ -62,6 +62,29 @@ def verify_api_key(x_api_key: Optional[str] = Header(None)):
|
|
| 62 |
|
| 63 |
MAX_CONCURRENT_ZIWEI = int(os.environ.get("ZIWEI_MAX_CONCURRENT", "2"))
|
| 64 |
_ziwei_subprocess_slots = threading.BoundedSemaphore(MAX_CONCURRENT_ZIWEI)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
|
| 67 |
class ZiweiRequest(BaseModel):
|
|
@@ -80,6 +103,8 @@ def run_ziwei_calculation(request: BaseModel) -> Dict[str, Any]:
|
|
| 80 |
统一处理subprocess调用、returncode检查和JSON解析,
|
| 81 |
失败时直接抛出HTTPException。
|
| 82 |
"""
|
|
|
|
|
|
|
| 83 |
input_data = {
|
| 84 |
"birth_date": request.birth_date,
|
| 85 |
"birth_time": request.birth_time,
|
|
|
|
| 62 |
|
| 63 |
MAX_CONCURRENT_ZIWEI = int(os.environ.get("ZIWEI_MAX_CONCURRENT", "2"))
|
| 64 |
_ziwei_subprocess_slots = threading.BoundedSemaphore(MAX_CONCURRENT_ZIWEI)
|
| 65 |
+
_node_dependency_lock = threading.Lock()
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def ensure_node_dependencies() -> None:
|
| 69 |
+
"""Install Node dependencies on runtimes that do not run Docker build steps."""
|
| 70 |
+
if os.path.isdir("node_modules/iztro"):
|
| 71 |
+
return
|
| 72 |
+
|
| 73 |
+
with _node_dependency_lock:
|
| 74 |
+
if os.path.isdir("node_modules/iztro"):
|
| 75 |
+
return
|
| 76 |
+
|
| 77 |
+
result = subprocess.run(
|
| 78 |
+
["npm", "install", "--production"],
|
| 79 |
+
capture_output=True,
|
| 80 |
+
text=True,
|
| 81 |
+
timeout=180
|
| 82 |
+
)
|
| 83 |
+
if result.returncode != 0:
|
| 84 |
+
raise HTTPException(
|
| 85 |
+
status_code=500,
|
| 86 |
+
detail=f"Node dependency installation failed: {result.stderr or result.stdout}"
|
| 87 |
+
)
|
| 88 |
|
| 89 |
|
| 90 |
class ZiweiRequest(BaseModel):
|
|
|
|
| 103 |
统一处理subprocess调用、returncode检查和JSON解析,
|
| 104 |
失败时直接抛出HTTPException。
|
| 105 |
"""
|
| 106 |
+
ensure_node_dependencies()
|
| 107 |
+
|
| 108 |
input_data = {
|
| 109 |
"birth_date": request.birth_date,
|
| 110 |
"birth_time": request.birth_time,
|