-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapp.py
87 lines (70 loc) · 2.2 KB
/
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
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
"""
Controller
"""
from contextlib import asynccontextmanager
import uvicorn
from fastapi import FastAPI
from src.utils.logging_util import Logger
from src.configurations.app_configs import AppConfigs
from src.services.classifier import Classifier
from src.domain.constants import SOCKET_HOST, PORT
from src.domain.request_response_schemas import BuildResponse
from src.routers import v1
tags_metadata = [
{"name": "Build", "description": "Use this API to check project build number."},
{
"name": "Prediction Service",
"description": "Prediction Service APIs",
"externalDocs": {
"description": "External Document",
"url": "https://link.to.external.document.com/",
},
},
]
@asynccontextmanager
async def lifespan(app: FastAPI):
"""
This function covers the lifespan of app.
Reference - https://fastapi.tiangolo.com/advanced/events/
:param app: FastAPI app
"""
app_configs = AppConfigs()
logger = Logger()
classifier = Classifier()
yield
del app_configs
del logger
del classifier
app = FastAPI(
debug=True,
title="ML Prediction Web Service",
description="This project is a production ready ML Prediction Web Service template. "
"<br /><br />"
"Author - [***Pranay Chandekar***](https://www.linkedin.com/in/pranaychandekar/)",
version="3.0.0",
openapi_tags=tags_metadata,
docs_url="/swagger/",
lifespan=lifespan,
)
@app.get("/", tags=["Build"], response_model=BuildResponse)
async def build():
"""
Hit this API to get build details.
:return: The build details
"""
Logger().get_instance().info("Checking the service setup.\n")
return {
"service": "ml-prediction-web-service",
"version": "3.0",
"author": "Pranay Chandekar",
"linkedIn": "https://www.linkedin.com/in/pranaychandekar/",
"message": "The web service is up and running!",
}
app.include_router(v1.router, prefix="/v1")
if __name__ == "__main__":
Logger().get_instance().info("Starting the web service.")
uvicorn.run(
app,
host=AppConfigs().get_instance().get(SOCKET_HOST),
port=AppConfigs().get_instance().get(PORT),
)