-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathmain.py
62 lines (47 loc) · 1.33 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
# Local imports
import datetime
# Third party imports
from pydantic import BaseModel, Field
from ms import app
from ms.functions import get_model_response
model_name = "Breast Cancer Wisconsin (Diagnostic)"
version = "v1.0.0"
# Input for data validation
class Input(BaseModel):
concavity_mean: float = Field(..., gt=0)
concave_points_mean: float = Field(..., gt=0)
perimeter_se: float = Field(..., gt=0)
area_se: float = Field(..., gt=0)
texture_worst: float = Field(..., gt=0)
area_worst: float = Field(..., gt=0)
class Config:
schema_extra = {
"concavity_mean": 0.3001,
"concave_points_mean": 0.1471,
"perimeter_se": 8.589,
"area_se": 153.4,
"texture_worst": 17.33,
"area_worst": 2019.0,
}
# Ouput for data validation
class Output(BaseModel):
label: str
prediction: int
@app.get('/')
async def model_info():
"""Return model information, version, how to call"""
return {
"name": model_name,
"version": version
}
@app.get('/health')
async def service_health():
"""Return service health"""
return {
"ok"
}
@app.post('/predict', response_model=Output)
async def model_predict(input: Input):
"""Predict with input"""
response = get_model_response(input)
return response