Download app/main.py from saskarkhadka/classification-backend: direct link, hf CLI and curl.
- Browser
- Download file 1.62 kB
-
https://huggingface.co/spaces/saskarkhadka/classification-backend/resolve/main/app/main.py
- Command line
-
hf download hf://spaces/saskarkhadka/classification-backend/app/main.py
-
curl -L -o main.py https://huggingface.co/spaces/saskarkhadka/classification-backend/resolve/main/app/main.py
1.62 kB
| 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) | |
| def home(): | |
| return {'message': 'pong'} | |
| def err(): | |
| return 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) | |