File size: 743 Bytes
e548193
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# app.py
from fastapi import FastAPI, APIRouter
import uvicorn
from classifier import Classifier
from nlp import NLP
import logging

logging.basicConfig(level = logging.INFO)

# Create the FastAPI instance
app = FastAPI()
nlp = NLP()
router = APIRouter()
classifier = Classifier()

# Define the required routes
@router.get("/")
async def home():
  return {"message": "Machine Learning service"}

@router.post("/sentiment")
async def data(data: dict):
  try:
    input_text = data["text"]
    res = nlp.sentiment_analysis(classifier, input_text)
    return res
  except Exception as e:
    log.error("Something went wrong")

app.include_router(router)

if __name__ == "__main__":
  uvicorn.run("app:app", reload=True, port=6000, host="0.0.0.0")