Spaces:
Sleeping
Sleeping
add server/app.py at root
Browse files- server/app.py +46 -0
server/app.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""FastAPI application for the RedVeil Environment."""
|
| 2 |
+
|
| 3 |
+
try:
|
| 4 |
+
from openenv.core.env_server.http_server import create_app
|
| 5 |
+
except Exception as e:
|
| 6 |
+
raise ImportError(
|
| 7 |
+
"openenv is required. Install with: pip install openenv-core[core]"
|
| 8 |
+
) from e
|
| 9 |
+
|
| 10 |
+
try:
|
| 11 |
+
from ..models import RedVeilAction, RedVeilObservation
|
| 12 |
+
from .redveil_environment import RedVeilEnvironment
|
| 13 |
+
except (ModuleNotFoundError, ImportError):
|
| 14 |
+
from models import RedVeilAction, RedVeilObservation
|
| 15 |
+
from server.redveil_environment import RedVeilEnvironment
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
# Singleton: OpenEnv calls the factory on every request, so we return
|
| 19 |
+
# the same instance to preserve state across reset() -> step() calls.
|
| 20 |
+
_singleton_env = RedVeilEnvironment()
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def _env_factory() -> RedVeilEnvironment:
|
| 24 |
+
return _singleton_env
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
app = create_app(
|
| 28 |
+
_env_factory,
|
| 29 |
+
RedVeilAction,
|
| 30 |
+
RedVeilObservation,
|
| 31 |
+
env_name="redveil",
|
| 32 |
+
max_concurrent_envs=4,
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def main(host: str = "0.0.0.0", port: int = 8000):
|
| 37 |
+
import uvicorn
|
| 38 |
+
uvicorn.run(app, host=host, port=port)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
if __name__ == "__main__":
|
| 42 |
+
import argparse
|
| 43 |
+
parser = argparse.ArgumentParser()
|
| 44 |
+
parser.add_argument("--port", type=int, default=8000)
|
| 45 |
+
args = parser.parse_args()
|
| 46 |
+
main(port=args.port)
|