Download app/main.py from saskarkhadka/summarization-backend: direct link, hf CLI and curl.
- Browser
- Download file 1.62 kB
-
https://huggingface.co/spaces/saskarkhadka/summarization-backend/resolve/main/app/main.py
- Command line
-
hf download hf://spaces/saskarkhadka/summarization-backend/app/main.py
-
curl -L -o main.py https://huggingface.co/spaces/saskarkhadka/summarization-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 SummarizationRequest, SummarizationResponse | |
| 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 | |
| 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 summarize_nepali_news(body: SummarizationRequest) -> SummarizationResponse: | |
| result: SummarizationResponse = inference_service.run_inference( | |
| model=body.model, | |
| text=body.text, | |
| num_beams=body.num_beams, | |
| temperature=body.temperature, | |
| top_k=body.top_k, | |
| ) | |
| 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) |