File size: 2,702 Bytes
31fda96
 
 
9afba1d
31fda96
 
9afba1d
805e1e5
31fda96
805e1e5
31fda96
 
 
 
9a71624
 
 
31fda96
9a71624
31fda96
f64e40d
5fb4c10
582b4bf
 
 
 
 
 
 
 
 
9a71624
805e1e5
9afba1d
9a71624
 
 
 
 
 
 
 
 
 
 
f64e40d
 
805e1e5
582b4bf
 
 
 
9a71624
130f8de
582b4bf
805e1e5
7b30c7c
88da32f
805e1e5
9a71624
 
 
 
 
 
 
 
 
 
 
88da32f
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
import warnings

import requests
from fastapi import FastAPI, Request
from fastapi.responses import FileResponse, JSONResponse
from fastapi.staticfiles import StaticFiles
from slowapi import Limiter, _rate_limit_exceeded_handler
from slowapi.errors import RateLimitExceeded
from slowapi.middleware import SlowAPIMiddleware
from slowapi.util import get_remote_address

from config import ACCESS_RATE
from features.image_classifier.routes import router as image_classifier_router
from features.image_edit_detector.routes import router as image_edit_detector_router
from features.nepali_text_classifier.routes import (
    router as nepali_text_classifier_router,
)
from features.text_classifier.routes import router as text_classifier_router

warnings.filterwarnings("ignore")
limiter = Limiter(key_func=get_remote_address, default_limits=[ACCESS_RATE])

openapi_tags = [
    {"name": "English Text Classifier", "description": "Endpoints for English AI-vs-human text analysis."},
    {"name": "Nepali Text Classifier", "description": "Endpoints for Nepali AI-vs-human text analysis."},
    {"name": "AI Image Classifier", "description": "Endpoints for AI-vs-human image classification."},
    {"name": "Image Edit Detection", "description": "Endpoints for edited/forged image detection."},
    {"name": "System", "description": "Health and root endpoints."},
]

app = FastAPI(openapi_tags=openapi_tags)
# added the robots.txt
# Set up SlowAPI
app.state.limiter = limiter
app.add_exception_handler(
    RateLimitExceeded,
    lambda request, exc: JSONResponse(
        status_code=429,
        content={
            "status_code": 429,
            "error": "Rate limit exceeded",
            "message": "Too many requests. Chill for a bit and try again",
        },
    ),
)
app.add_middleware(SlowAPIMiddleware)

# Include your routes
app.include_router(text_classifier_router, prefix="/text", tags=["English Text Classifier"])
app.include_router(nepali_text_classifier_router, prefix="/NP", tags=["Nepali Text Classifier"])
app.include_router(image_classifier_router, prefix="/AI-image", tags=["AI Image Classifier"])
app.include_router(image_edit_detector_router, prefix="/detect", tags=["Image Edit Detection"])


@app.get("/", tags=["System"])
@limiter.limit(ACCESS_RATE)
async def root(request: Request):
    return {
        "message": "API is working",
        "endpoints": [
            "/text/analyse",
            "/text/upload",
            "/text/analyse-sentences",
            "/text/analyse-sentance-file",
            "/NP/analyse",
            "/NP/upload",
            "/NP/analyse-sentences",
            "/NP/file-sentences-analyse",
            "/AI-image/analyse",
        ],
    }