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", ], }