-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
101 lines (82 loc) · 2.26 KB
/
main.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#Python
from typing import List
from datetime import datetime
#Pydantic
from pydantic import BaseModel, Field, validator
#FastAPI
from fastapi import Body
from fastapi import status
#Auxiliary
from ms import app
from ms.auxiliar import get_model_response
# Input for data validation
class Input(BaseModel):
date_init: datetime = Field(
...,
description="Starting date of the temperature list"
)
temp_back: List[float] = Field(
...,
description="Last 30 previous temperature values"
)
@validator("date_init", pre=True)
def parse_date(cls, value):
return datetime.strptime(
value,
"%Y-%m-%d %H:%M:%S"
)
class Config:
schema_extra = {
"example": {
"date_init": "2021-12-30 20:00:00",
"temp_back": [28.9, 28.7, 28.1, 27.7, 27.6, 27.7, 27.7,
27.5, 27.1, 26.8, 26.9, 26.6, 26.6, 26.6,
26.6, 26.3, 26.1, 27.3, 27.4, 27.4, 28.6,
28.6, 28.2, 28.8, 27.9, 27.5, 27.3, 27.2,
27.1, 27.4]
}
}
class Prediction(BaseModel):
date_pred: datetime = Field(
...,
description="date of the temperature predict"
)
temp_pred: float = Field(...)
@app.get(
path="/",
status_code=status.HTTP_200_OK,
tags=["Home"],
summary="Home from app"
)
async def home():
"""
Home
This is the home from app
No parameters
Returns dictionary with model information, version
"""
return {
"name": "RNN temperature prediction",
"version": "v1.0.0"
}
@app.post(
path='/predict',
response_model=Prediction,
status_code=status.HTTP_200_OK,
tags=["Predict"],
summary="Prediction"
)
async def model_predict(
input: Input = Body(
...
)
):
"""
Predict
This is the path operation for temperature predict using the last 30 temperature values
- Body parameter
- **input** -> This is the class input with date init and last 30 temperature values
Returns temperature prediction with your date information
"""
response = get_model_response(input)
return response