Spaces:
Runtime error

dsh-relay / app.py
volhack's picture
Update app.py
987e785 verified
Raw History Blame Contribute Delete
1.55 kB
import os
import sys
import subprocess
import urllib.request
import time
try:
import spaces
@spaces.GPU
def dummy_gpu():
return True
print("[Launcher] Registered @spaces.GPU dummy function")
except Exception as e:
print(f"[Launcher] spaces import error: {e}")
print("[Launcher] Starting DSH Antigravity Relay launcher...")
def get_node():
try:
res = subprocess.run(["node", "-v"], capture_output=True, text=True)
if res.returncode == 0:
print(f"[Launcher] Found system node: {res.stdout.strip()}")
return "node"
except Exception:
pass
node_dir = os.path.abspath("./node_bin")
node_exe = os.path.join(node_dir, "bin", "node")
if os.path.exists(node_exe):
return node_exe
os.makedirs(node_dir, exist_ok=True)
tar_path = "/tmp/node.tar.xz"
url = "https://nodejs.org/dist/v20.18.0/node-v20.18.0-linux-x64.tar.xz"
print(f"[Launcher] Downloading portable Node.js from {url}...")
urllib.request.urlretrieve(url, tar_path)
print("[Launcher] Extracting Node.js...")
subprocess.run(["tar", "-xJf", tar_path, "-C", node_dir, "--strip-components=1"], check=True)
os.chmod(node_exe, 0o755)
print(f"[Launcher] Node.js ready at {node_exe}")
return node_exe
node_bin = get_node()
port = os.environ.get("PORT", "7860")
env = dict(os.environ)
env["PORT"] = str(port)
print(f"[Launcher] Executing node server.mjs on port {port}...")
sys.stdout.flush()
sys.stderr.flush()
subprocess.run([node_bin, "server.mjs"], env=env)