Spaces:
Runtime error

File size: 1,553 Bytes
987e785
dc6828e
 
 
 
 
987e785
 
 
 
 
 
 
 
 
dc6828e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
987e785
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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)