-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
53 lines (33 loc) · 1.12 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
from fastapi import FastAPI
from uvicorn import run as app_run
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import Response
from train import training as start_training
from ner.pipeline.prediction_pipeline import ModelPredictor
from ner.constants import *
app= FastAPI()
origins=["*"]
app.add_middleware(
CORSMiddleware,
allow_origins= origins,
allow_credentials= True,
allow_methods= ["*"],
allow_headers= ["*"],
)
@app.get("/train")
async def training():
try:
start_training()
return Response("Training successful !!")
except Exception as e:
raise Response(f"Error Occurred! {e}")
@app.post("/predict")
async def predict_route(text: str):
try:
prediction_pipeline= ModelPredictor()
sentence, prediction_label= prediction_pipeline.initiate_model_predictor(sentence= text)
return sentence, prediction_label
except Exception as e:
raise Response(f"Error Occurred! {e}")
if __name__ == "__main__":
app_run(app, host= APP_HOST, port= APP_PORT)