VoiceGuard Bot
Deploy optimized VoiceGuard with Abhishtagatya model
1c5dd00
Raw
History Blame Contribute Delete
3.66 kB
"""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
)