Spaces:
Sleeping
Sleeping
Update env.py
Browse files
env.py
CHANGED
|
@@ -1,7 +1,8 @@
|
|
| 1 |
import asyncio
|
| 2 |
-
from typing import Optional
|
| 3 |
from types import SimpleNamespace
|
| 4 |
-
from
|
|
|
|
| 5 |
from models import MyEnvV4Observation, MyEnvV4Action
|
| 6 |
|
| 7 |
class MyEnvV4Env(Environment):
|
|
@@ -82,9 +83,22 @@ class MyEnvV4Env(Environment):
|
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
-
#
|
| 86 |
my_env = MyEnvV4Env()
|
| 87 |
|
| 88 |
-
#
|
| 89 |
-
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import asyncio
|
| 2 |
+
from typing import Optional, List
|
| 3 |
from types import SimpleNamespace
|
| 4 |
+
from fastapi import FastAPI
|
| 5 |
+
from openenv.core.env_server import Environment
|
| 6 |
from models import MyEnvV4Observation, MyEnvV4Action
|
| 7 |
|
| 8 |
class MyEnvV4Env(Environment):
|
|
|
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
+
# Create the environment instance
|
| 87 |
my_env = MyEnvV4Env()
|
| 88 |
|
| 89 |
+
# defining the FastAPI app and routes
|
| 90 |
+
app = FastAPI()
|
| 91 |
+
|
| 92 |
+
@app.get("/reset")
|
| 93 |
+
async def reset():
|
| 94 |
+
result = await my_env.reset()
|
| 95 |
+
return {"observation": result.observation, "reward": result.reward, "done": result.done}
|
| 96 |
+
|
| 97 |
+
@app.post("/step")
|
| 98 |
+
async def step(action: MyEnvV4Action):
|
| 99 |
+
result = await my_env.step(action)
|
| 100 |
+
return {"observation": result.observation, "reward": result.reward, "done": result.done}
|
| 101 |
+
|
| 102 |
+
@app.get("/state")
|
| 103 |
+
async def state():
|
| 104 |
+
return await my_env.state()
|