arrow072 commited on
Commit
df98973
·
verified ·
1 Parent(s): 9c16f41

Update server/app.py

Browse files
Files changed (1) hide show
  1. server/app.py +32 -10
server/app.py CHANGED
@@ -1,14 +1,36 @@
1
- import os
2
- import sys
3
- import uvicorn
4
 
5
- # Add the parent directory to sys.path so 'inference.py' can be imported and env modules
6
- sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
 
 
 
 
 
 
 
 
 
7
 
8
- from inference import app
 
9
 
10
- def main():
11
- uvicorn.run("server.app:app", host="0.0.0.0", port=7860)
 
12
 
13
- if __name__ == "__main__":
14
- main()
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from env import TrafficEnv
 
3
 
4
+ CONFIG = {
5
+ "max_steps": 20,
6
+ "max_queue": 20,
7
+ "arrival_rate": (0, 2),
8
+ "discharge_rate": (3, 5),
9
+ "emergency_prob": 0.02,
10
+ "switch_penalty": 0.2,
11
+ "starvation_threshold": 10,
12
+ "burst_prob": 0.1,
13
+ "burst_multiplier": 1.2,
14
+ }
15
 
16
+ app = FastAPI()
17
+ env = TrafficEnv(CONFIG)
18
 
19
+ @app.get("/")
20
+ def root():
21
+ return {"message": "Traffic Env Running"}
22
 
23
+ @app.post("/reset")
24
+ def reset():
25
+ return env.reset()
26
+
27
+ @app.post("/step")
28
+ def step(action: dict):
29
+ action_value = action.get("action", 0)
30
+ next_state, reward, done, info = env.step(action_value)
31
+ return {
32
+ "next_state": next_state,
33
+ "reward": reward,
34
+ "done": done,
35
+ "info": info,
36
+ }