-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathapp.py
44 lines (33 loc) · 753 Bytes
/
app.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
import datetime as dt
from fastapi import FastAPI
from bikesmodel import train_and_persist, predict
app = FastAPI()
@app.get("/")
async def home():
return {"message": "Hello, world!"}
# Beware! Exposing train_and_persist
# allows anyone to run the training
@app.post("/train_and_persist")
async def do_train_and_persist():
train_and_persist()
return {"success": True}
@app.get("/predict")
async def do_predict(
dteday: dt.date,
hr: int,
weathersit: str,
temp: float,
atemp: float,
hum: float,
windspeed: float,
):
result = predict(
dteday.isoformat(),
hr,
weathersit,
temp,
atemp,
hum,
windspeed,
)
return {"number_cyclists": result}