File size: 1,619 Bytes
19cc583
9766e10
 
 
 
 
 
 
 
 
 
554a609
9766e10
 
 
 
 
 
 
 
 
19cc583
 
 
9766e10
 
 
 
 
 
19cc583
 
 
 
 
9766e10
 
 
 
19cc583
 
9766e10
 
 
 
 
19cc583
9766e10
19cc583
 
9766e10
19cc583
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, HTTPException
import uvicorn
from app.middleware.auth import auth_middleware
from app.middleware.request_tag import request_id_middleware
from starlette.exceptions import HTTPException
from fastapi.exceptions import RequestValidationError
from app.core.exception import (
    http_exception_handler,
    request_validation_error_handler,
    global_exception_handler
)
from app.models.models import ClassificationRequest, ClassificationResponse
from app.inference.inference import inference_service
from app.core.config import settings
from app.core.logging import setup_logging
from app.router.router import api_router
import nltk

nltk.download('stopwords')

setup_logging()

app = FastAPI()

app.add_exception_handler(HTTPException, http_exception_handler)
app.add_exception_handler(RequestValidationError, request_validation_error_handler)
app.add_exception_handler(Exception, global_exception_handler)

# app.middleware("http")(auth_middleware)
app.middleware("http")(request_id_middleware)

@app.get('/')
def home():
    return {'message': 'pong'}

@app.get('/err')
def err():
    return ClassificationResponse()

@app.post('/classify/nepali-news', status_code=200, response_model=ClassificationResponse)
def classify_nepali_news(body: ClassificationRequest) -> ClassificationResponse:
    result: ClassificationResponse = inference_service.run_inference(
        model=body.model,
        text=body.text,
    )
    return result

app.include_router(api_router, prefix='/api')

if __name__ == "__main__":
    port = int(settings.PORT) 
    uvicorn.run(app, host="0.0.0.0", port=port)