-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.py
More file actions
51 lines (34 loc) · 1.02 KB
/
Server.py
File metadata and controls
51 lines (34 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from typing import List, Optional
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
import Room_mapping
app = FastAPI()
RM = Room_mapping.RoomMapper()
class NetworkInfo(BaseModel):
ssid: str
rssi: int
bssid: str
class NetworksInfo(BaseModel):
scan_results: Optional[List[NetworkInfo]] = None
class ChangeModeBody(BaseModel):
mode: bool
@app.post("/location/mode")
def change_mode(body: ChangeModeBody):
print("MODE: ", body.mode, flush=True)
if not RM.trained() and body.mode:
RM.train()
return {"trained": True}
@app.post("/location")
def get_room_prediction(networks_info: NetworksInfo):
if not RM.trained():
raise HTTPException(status_code=503, detail="Model is not trained yet")
room = RM.get_device_location(networks_info)
return {"id": room}
@app.post("/retrain")
def retrain_model():
RM.retrain()
return {"retrained": True}
if __name__ == '__main__':
import uvicorn
RM.train()
uvicorn.run(app, host='0.0.0.0', port=8083)