feat[bert]: FastAPI interface
Browse files- ml-service/app.py +5 -12
ml-service/app.py
CHANGED
@@ -4,30 +4,23 @@ import uvicorn
|
|
4 |
from classifier import Classifier
|
5 |
import nlp
|
6 |
import logging
|
7 |
-
from logging import log
|
8 |
|
9 |
logging.basicConfig(level = logging.INFO)
|
10 |
|
11 |
# Create the FastAPI instance
|
12 |
app = FastAPI()
|
13 |
-
router = APIRouter()
|
14 |
classifier = Classifier()
|
15 |
|
16 |
# Define the required routes
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
|
21 |
-
@
|
22 |
async def data(data: dict):
|
23 |
try:
|
24 |
input_text = data["text"]
|
25 |
res = nlp.sentiment_analysis(classifier, input_text)
|
26 |
return res
|
27 |
except Exception as e:
|
28 |
-
logging.error("Something went wrong")
|
29 |
-
|
30 |
-
app.include_router(router)
|
31 |
-
|
32 |
-
if __name__ == "__main__":
|
33 |
-
uvicorn.run("app:app", reload=True, port=6000, host="0.0.0.0")
|
|
|
4 |
from classifier import Classifier
|
5 |
import nlp
|
6 |
import logging
|
|
|
7 |
|
8 |
logging.basicConfig(level = logging.INFO)
|
9 |
|
10 |
# Create the FastAPI instance
|
11 |
app = FastAPI()
|
|
|
12 |
classifier = Classifier()
|
13 |
|
14 |
# Define the required routes
|
15 |
+
@app.get("/")
|
16 |
+
async def home():
|
17 |
+
return {"message": "Machine Learning service"}
|
18 |
|
19 |
+
@app.post("/sentiment")
|
20 |
async def data(data: dict):
|
21 |
try:
|
22 |
input_text = data["text"]
|
23 |
res = nlp.sentiment_analysis(classifier, input_text)
|
24 |
return res
|
25 |
except Exception as e:
|
26 |
+
logging.error("Something went wrong")
|
|
|
|
|
|
|
|
|
|