Download server.py from s-b3/LifeStack: direct link, hf CLI and curl.
- Browser
- Download file 1.99 kB
-
https://huggingface.co/spaces/s-b3/LifeStack/resolve/main/server.py
- Command line
-
hf download hf://spaces/s-b3/LifeStack/server.py
-
curl -L -o server.py https://huggingface.co/spaces/s-b3/LifeStack/resolve/main/server.py
1.99 kB
| import os | |
| from pathlib import Path | |
| try: | |
| import uvicorn | |
| except ImportError as exc: | |
| root_dir = Path(__file__).resolve().parent | |
| venv_python = root_dir / ".venv" / "bin" / "python" | |
| raise SystemExit( | |
| "uvicorn is not installed for this interpreter.\n" | |
| f"Run the server with: {venv_python} {root_dir / 'server.py'}\n" | |
| "Or activate the virtualenv first: source .venv/bin/activate" | |
| ) from exc | |
| try: | |
| from openenv.core import create_app | |
| except ImportError: | |
| # Alternative path for older/flat openenv structures | |
| try: | |
| from openenv.env import create_app | |
| except ImportError: | |
| def create_app(*a, **k): | |
| print("⚠️ create_app not found in openenv. Using fallback.") | |
| return None | |
| from core.lifestack_env import LifeStackEnv, LifeStackAction, LifeStackObservation | |
| def main(): | |
| """ | |
| LifeStack OpenEnv Server — Standard distribution entry point. | |
| Wraps LifeStackEnv in an HTTP and WebSocket server compatible with EnvClient. | |
| """ | |
| # Use standard environment variables for configuration | |
| host = os.getenv("OPENENV_HOST", "0.0.0.0") | |
| port = int(os.getenv("OPENENV_PORT", "8000")) | |
| max_concurrent = int(os.getenv("OPENENV_MAX_SESSIONS", "4")) | |
| # Create the FastAPI app with the builtin OpenEnv web interface enabled | |
| os.environ["ENABLE_WEB_INTERFACE"] = "true" | |
| app = create_app( | |
| env=LifeStackEnv, | |
| action_cls=LifeStackAction, | |
| observation_cls=LifeStackObservation, | |
| env_name="LifeStack Premium", | |
| max_concurrent_envs=max_concurrent | |
| ) | |
| print(f"\n" + "═"*60) | |
| print(f" 🚀 LifeStack OpenEnv Server is ready!") | |
| print(f" - HTTP Endpoint: http://{host}:{port}") | |
| print(f" - Web Interface: http://{host}:{port}/web") | |
| print(f" - Documentation: http://{host}:{port}/docs") | |
| print("═"*60 + "\n") | |
| uvicorn.run(app, host=host, port=port, log_level="info") | |
| if __name__ == "__main__": | |
| main() | |