import os import sys import time import subprocess try: import spaces HAS_SPACES = True except Exception: # Plain CPU Spaces (and some runtimes) don't ship the ZeroGPU `spaces` package. # Without this guard, `import spaces` crashes app.py and the whole proxy never starts. spaces = None HAS_SPACES = False print("=======================================================") print("🚀 Initializing Etrog Bypass Proxy on Hugging Face ZeroGPU Space") print("=======================================================") if HAS_SPACES: # Decoration itself can raise on non-ZeroGPU runtimes — guard both import AND decoration. 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).") # Ensure Node.js is installed 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) # Launch Node server on main HF ingress port 7860 os.environ["PORT"] = "7860" print("📡 Launching Node server.js on port 7860...") proc = subprocess.Popen([node_bin, "server.js"], env=os.environ) # Keep process running without launching Gradio HTTP server try: proc.wait() except KeyboardInterrupt: proc.terminate()