| import os |
| import sys |
| import time |
| import subprocess |
|
|
| try: |
| import spaces |
| HAS_SPACES = True |
| except Exception: |
| |
| |
| spaces = None |
| HAS_SPACES = False |
|
|
| print("=======================================================") |
| print("🚀 Initializing Etrog Bypass Proxy on Hugging Face ZeroGPU Space") |
| print("=======================================================") |
|
|
| if HAS_SPACES: |
| |
| try: |
| @spaces.GPU |
| def zero_gpu_dummy(): |
| return "ZeroGPU Ready" |
|
|
| zero_gpu_dummy() |
| except Exception as e: |
| print(f"ZeroGPU init note: {e}") |
| else: |
| print("ℹ️ `spaces` package not available — running without ZeroGPU (fine on CPU Spaces).") |
|
|
| |
| NODE_VERSION = "v20.18.0" |
| NODE_DIR = f"node-{NODE_VERSION}-linux-x64" |
| NODE_TAR = f"{NODE_DIR}.tar.xz" |
| NODE_URL = f"https://nodejs.org/dist/{NODE_VERSION}/{NODE_TAR}" |
|
|
| if not os.path.exists(NODE_DIR): |
| print(f"📦 Downloading standalone Node.js {NODE_VERSION}...") |
| subprocess.run(f"curl -fsSL {NODE_URL} | tar -xJ", shell=True, check=True) |
|
|
| node_bin = os.path.abspath(f"{NODE_DIR}/bin/node") |
| npm_bin = os.path.abspath(f"{NODE_DIR}/bin/npm") |
|
|
| os.environ["PATH"] = os.path.abspath(f"{NODE_DIR}/bin") + os.path.pathsep + os.environ.get("PATH", "") |
|
|
| print("📥 Installing Node.js dependencies...") |
| subprocess.run([npm_bin, "install", "--omit=dev"], check=True) |
|
|
| |
| os.environ["PORT"] = "7860" |
| print("📡 Launching Node server.js on port 7860...") |
| proc = subprocess.Popen([node_bin, "server.js"], env=os.environ) |
|
|
| |
| try: |
| proc.wait() |
| except KeyboardInterrupt: |
| proc.terminate() |
|
|