File size: 961 Bytes
b8eae92 |
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 |
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Hugging Face Space launcher for MatrixGame WebSocket Server
This script launches the server with the appropriate configuration for Hugging Face Spaces.
"""
import os
import sys
import subprocess
def main():
# Get the port from environment variable in Hugging Face Space
port = int(os.environ.get("PORT", 7860))
# Determine if this is running in a Hugging Face Space
is_hf_space = os.environ.get("SPACE_ID") is not None
# Pass the appropriate path if in a space
path_arg = ""
if is_hf_space:
# In a space, we're usually behind a proxy, so we need to handle base path
path_arg = f"--path /{os.environ.get('SPACE_ID', '')}"
# Construct and run the command
cmd = f"{sys.executable} server.py --host 0.0.0.0 --port {port} {path_arg}"
print(f"Running command: {cmd}")
subprocess.run(cmd, shell=True)
if __name__ == "__main__":
main() |