Spaces:
Sleeping
Sleeping
File size: 3,660 Bytes
f68a33a 1c5dd00 f68a33a | 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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | """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 ==============
@app.get("/", tags=["Info"])
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"
}
@app.get("/favicon.ico", include_in_schema=False)
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 ==============
@app.on_event("startup")
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 ==============
@app.on_event("shutdown")
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
)
|