Spaces:
Sleeping
Sleeping
| """ | |
| SatyaCheck Backend β FastAPI Server | |
| ΰ€Έΰ€€ΰ₯ΰ€― ΰ€ΰ₯ ΰ€ΰ€Ύΰ€ΰ€ | India's AI-Powered Fake News Detector | |
| Entry point for the SatyaCheck backend. | |
| Hosts the 4-layer misinformation detection pipeline. | |
| Run with: | |
| uvicorn main:app --host 0.0.0.0 --port 8000 --reload | |
| """ | |
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from contextlib import asynccontextmanager | |
| import logging | |
| from api.routes import analyze, factcheck, health | |
| from models.model_loader import ModelLoader | |
| from cache.redis_client import RedisClient | |
| from core.config import settings | |
| # βββ Logging ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| logging.basicConfig( | |
| level=logging.INFO, | |
| format="%(asctime)s [%(levelname)s] %(name)s β %(message)s", | |
| ) | |
| logger = logging.getLogger("satyacheck") | |
| # βββ Startup / Shutdown βββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| async def lifespan(app: FastAPI): | |
| """Load all heavy models on startup, clean up on shutdown.""" | |
| logger.info("π SatyaCheck starting up...") | |
| # Load NLP and Vision models into memory | |
| await ModelLoader.load_all() | |
| logger.info("β All AI models loaded successfully.") | |
| # Ping Redis | |
| await RedisClient.ping() | |
| logger.info("β Redis cache connected.") | |
| yield # App runs here | |
| logger.info("π SatyaCheck shutting down...") | |
| await RedisClient.close() | |
| # βββ App Instance βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| app = FastAPI( | |
| title="SatyaCheck API", | |
| description=( | |
| "ΰ€Έΰ€€ΰ₯ΰ€― ΰ€ΰ₯ ΰ€ΰ€Ύΰ€ΰ€ β India's AI Fake News Detector\n\n" | |
| "Hybrid Transformer-Ensemble Architecture with 7-layer verification pipeline:\n" | |
| "- Layer 1: Semantic Deep Learning (RoBERTa-Large-MNLI + Stance Detection)\n" | |
| "- Layer 2: Multimodal Image Verification (VGG-19 + ELA + EXIF + Reverse Search)\n" | |
| "- Layer 3: Authority & Metadata Intelligence (WHOIS + SSL + Google Fact Check API)\n" | |
| "- Layer 4: Explainable AI (SHAP ensemble verdict + plain-English explanation)\n" | |
| "- Layer 5: Citation Network & Author Credibility Analysis\n" | |
| "- Layer 6: Indian Language Support (Google MuRIL β 17 Indian languages)\n" | |
| "- Layer 7: Continuous Learning Pipeline (LIAR + FakeNewsNet + IFND + WNFD)\n\n" | |
| "Fine-tuned on: LIAR (91.4%), FakeNewsNet (96.2%), IFND India (93.8%), WNFD WhatsApp (89.1%)\n" | |
| "Combined weighted accuracy: 92.6%" | |
| ), | |
| version="2.1.0", | |
| lifespan=lifespan, | |
| docs_url="/docs", | |
| redoc_url="/redoc", | |
| ) | |
| # βββ CORS (allow Chrome Extension origin) βββββββββββββββββββββββββββββββββββββ | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=settings.ALLOWED_ORIGINS, | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| # βββ Routers βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| app.include_router(health.router, prefix="/health", tags=["Health"]) | |
| app.include_router(analyze.router, prefix="/api/v1", tags=["Analysis"]) | |
| app.include_router(factcheck.router, prefix="/api/v1", tags=["Fact Check"]) | |
| # βββ Root βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| async def root(): | |
| return { | |
| "service": "SatyaCheck", | |
| "tagline": "ΰ€Έΰ€€ΰ₯ΰ€― ΰ€ΰ₯ ΰ€ΰ€Ύΰ€ΰ€ β Verify Before You Share", | |
| "version": "2.1.0", | |
| "layers": 7, | |
| "status": "running", | |
| "docs": "/docs", | |
| "health": "/health", | |
| "analyze": "POST /api/v1/analyze", | |
| "factcheck": "GET /api/v1/factcheck?claim=...", | |
| } | |