NON_WORKING_matrix_game_2 / run_hf_space.py
Julian Bilcke
up
b8eae92
raw
history blame
961 Bytes
#!/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()