#!/bin/bash # Start script for Hugging Face Space (Dual Process: Node.js + Python Browser Agent) # 0. IServ filter (127.0.0.1:7862, only reachable from this container) as its own unix user. sudo resets the # environment, so it sees only what is passed here: the token, not ISERV_PASSWORD. Restarted if it ever dies, so a # crash cannot take the other apps down with it. (while true; do sudo -u iserv_runner env FILTER_ONLY=1 HF_HUB_OFFLINE=1 PYTHONDONTWRITEBYTECODE=1 API_BEARER_TOKEN="$API_BEARER_TOKEN" /opt/filter-venv/bin/python -m uvicorn app:app --app-dir /app/iserv-filter --host 127.0.0.1 --port 7862 --log-level warning sleep 5 done) & # 1. Start Node.js App (Port 7860) in the background echo "Starting Node.js server..." node server.js & NODE_PID=$! # 2. Setup and Start Browser Agent (Port 8765) echo "Starting Python Browser Agent as agent_runner..." # Run the python agent as agent_runner using sudo echo "Debug: OPENROUTER_API_KEY length is ${#OPENROUTER_API_KEY}" sudo -u agent_runner env PLAYWRIGHT_BROWSERS_PATH="/app/Browser_Agent/pw-browsers" OPENROUTER_API_KEY="$OPENROUTER_API_KEY" bash -c "cd /app/Browser_Agent && . .venv/bin/activate && python main.py" & PYTHON_PID=$! # Wait for any process to exit wait -n # Exit with status of process that exited first exit $?