File size: 2,241 Bytes
c6df052
9cf5fee
c6df052
b089011
 
59ea016
 
9cf5fee
c6df052
 
 
 
 
 
 
9cf5fee
59ea016
9cf5fee
 
59ea016
 
 
 
9cf5fee
 
 
 
 
b089011
9e707a5
9cf5fee
c6df052
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9cf5fee
 
 
 
c6df052
 
 
 
 
 
 
 
9cf5fee
 
b089011
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from fastapi import FastAPI, HTTPException, Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse, RedirectResponse
import os

# Import the router
from app.api.routes import router as api_router

app = FastAPI(
    title="AI Content Summariser API",
    description="An API for summarizing text content and web pages using NLP models",
    version="1.0.0",
    docs_url="/docs",
    redoc_url="/redoc",
)

# Configure CORS
app.add_middleware(
    CORSMiddleware,
    allow_origins=[
        "https://ai-content-summariser.vercel.app",
        "http://localhost:3000",
    ],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# Include the router
app.include_router(api_router)

@app.get("/", include_in_schema=True)
async def root():
    """
    Root endpoint that provides information about the API and available endpoints.
    """
    return {
        "name": "AI Content Summariser API",
        "version": "1.0.0",
        "description": "API for summarizing text content and web pages using NLP models",
        "endpoints": {
            "documentation": "/docs",
            "alternative_docs": "/redoc",
            "health_check": "/health",
            "api_endpoints": {
                "summarise_text": "/api/summarise",
                "summarise_url": "/api/summarise-url",
                "status": "/api/status"
            }
        },
        "github_repository": "https://github.com/dang-w/ai-content-summariser-api",
        "frontend_application": "https://ai-content-summariser.vercel.app"
    }

@app.get("/docs-redirect")
async def docs_redirect():
    """
    Redirects to the API documentation.
    """
    return RedirectResponse(url="/docs")

@app.get("/health")
async def health_check():
    return {"status": "healthy"}

# Global exception handler for better error responses
@app.exception_handler(Exception)
async def global_exception_handler(request: Request, exc: Exception):
    return JSONResponse(
        status_code=500,
        content={"detail": f"An unexpected error occurred: {str(exc)}"}
    )

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=int(os.environ.get("PORT", 8000)))