-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbit.py
49 lines (29 loc) · 840 Bytes
/
bit.py
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
import asyncio
from fastapi import FastAPI
from contextlib import asynccontextmanager
ml_models = {}
@asynccontextmanager
async def lifespan(app: FastAPI):
ml_models["answer_to_everything"] = 42
print("set", app)
yield
print("model clearing")
ml_models.clear()
app = FastAPI(lifespan=lifespan)
@app.get("/")
async def run_something():
return {"resp": "ok"}
def fake_answer_to_everything_ml_model(x: float):
return x * 42
@app.get("/download")
async def run_something():
return open("./dotest/canada.json", 'rb').read()
@app.get("/state")
async def run_something():
return {"resp": ml_models.get("answer_to_everything", "actual nothing")}
async def send(a):
pass
async def receive(**a):
pass
if __name__ == "__main__":
asyncio.run(app({"type": "lifespan"}, receive, send))