Spaces:
Sleeping
Sleeping
| """VoiceGuard API - Main Application Entry Point. | |
| AI-Generated Voice Detection API for Indian Languages. | |
| Supports: Tamil, English, Hindi, Malayalam, Telugu | |
| """ | |
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from fastapi.staticfiles import StaticFiles | |
| import os | |
| from app.api.routes import router | |
| from app.config import settings | |
| from app.core.detector import detector | |
| # Create FastAPI app | |
| app = FastAPI( | |
| title="VoiceGuard API", | |
| description=""" | |
| ## AI-Generated Voice Detection for Indian Languages | |
| VoiceGuard detects whether an audio sample is AI-generated (deepfake) or genuine human speech. | |
| ### Features | |
| ### Features | |
| - π― **Multi-Language Support**: Tamil, English, Hindi, Malayalam, Telugu | |
| - π **Explanations**: Human-readable reasoning for each detection | |
| ### How It Works | |
| 1. Upload Base64-encoded MP3/WAV audio | |
| 2. AI analyzes the audio for synthetic patterns | |
| 3. Get classification, confidence, and visual explanation | |
| --- | |
| **India AI Impact Summit Buildathon 2026** | |
| """, | |
| version="1.0.0", | |
| docs_url="/docs", | |
| redoc_url="/redoc" | |
| ) | |
| # Add CORS middleware (allow frontend to connect) | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], # Allow all origins for demo | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| # Mount frontend files | |
| frontend_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), "frontend") | |
| if os.path.exists(frontend_dir): | |
| app.mount("/frontend", StaticFiles(directory=frontend_dir, html=True), name="frontend") | |
| # Include API routes (endpoint: /api/voice-detection) | |
| app.include_router(router, prefix="/api", tags=["Detection"]) | |
| # ============== ROOT ENDPOINT ============== | |
| async def root(): | |
| """Root endpoint with API information.""" | |
| return { | |
| "name": "VoiceGuard API", | |
| "description": "AI-Generated Voice Detection for Indian Languages", | |
| "version": "1.0.0", | |
| "docs": "/docs", | |
| "frontend": "/frontend/", | |
| "health": "/api/health", | |
| "languages": ["tamil", "english", "hindi", "malayalam", "telugu"], | |
| "status": "online" | |
| } | |
| async def favicon(): | |
| """Return empty response for favicon (browser default request).""" | |
| from fastapi.responses import Response | |
| return Response(content="", media_type="image/x-icon") | |
| # ============== STARTUP EVENT ============== | |
| async def startup_event(): | |
| """Initialize resources on startup.""" | |
| print("=" * 50) | |
| print("π‘οΈ VoiceGuard API Starting...") | |
| print("=" * 50) | |
| # Single multilingual model for all languages | |
| print("π Single-model architecture:") | |
| print(" Model: abhishtagatya/hubert-base-960h-itw-deepfake") | |
| print(" Accuracy: Human=99.83%, AI=99.79%") | |
| print(" Languages: Tamil, English, Hindi, Malayalam, Telugu") | |
| print("=" * 50) | |
| print(f"π API ready at http://{settings.HOST}:{settings.PORT}") | |
| print(f"π Docs: http://{settings.HOST}:{settings.PORT}/docs") | |
| print(f"π¨ Frontend: http://{settings.HOST}:{settings.PORT}/frontend/") | |
| print("=" * 50) | |
| # ============== SHUTDOWN EVENT ============== | |
| async def shutdown_event(): | |
| """Cleanup on shutdown.""" | |
| print("VoiceGuard API shutting down...") | |
| # ============== MAIN ============== | |
| if __name__ == "__main__": | |
| import uvicorn | |
| uvicorn.run( | |
| "app.main:app", | |
| host=settings.HOST, | |
| port=settings.PORT, | |
| reload=settings.DEBUG | |
| ) | |