
Features: - JWT authentication with user registration and login - Video upload to Amazon S3 with file validation (200MB limit) - Audio transcription using OpenAI Whisper API - Text translation using GPT-4 API - Voice cloning and audio synthesis using ElevenLabs API - Video processing with ffmpeg for audio replacement - Complete SQLite database with proper models and migrations - Background task processing for long-running operations - Health endpoint and comprehensive API documentation Tech stack: - FastAPI with SQLAlchemy ORM - SQLite database with Alembic migrations - Amazon S3 for file storage - OpenAI APIs for transcription and translation - ElevenLabs API for voice cloning - ffmpeg for video processing - JWT authentication with bcrypt password hashing
64 lines
1.8 KiB
Python
64 lines
1.8 KiB
Python
from pathlib import Path
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from contextlib import asynccontextmanager
|
|
|
|
from app.db.session import engine
|
|
from app.db.base import Base
|
|
from app.routes import auth, videos, transcription, translation, voice_cloning, video_processing
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
# Create database tables
|
|
storage_dir = Path("/app/storage/db")
|
|
storage_dir.mkdir(parents=True, exist_ok=True)
|
|
Base.metadata.create_all(bind=engine)
|
|
yield
|
|
|
|
|
|
app = FastAPI(
|
|
title="AI Video Dubbing API",
|
|
description="Backend API for AI-powered video dubbing with voice cloning and translation",
|
|
version="1.0.0",
|
|
lifespan=lifespan
|
|
)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# Include routers
|
|
app.include_router(auth.router, prefix="/auth", tags=["Authentication"])
|
|
app.include_router(videos.router, prefix="/videos", tags=["Videos"])
|
|
app.include_router(transcription.router, prefix="/transcription", tags=["Transcription"])
|
|
app.include_router(translation.router, prefix="/translation", tags=["Translation"])
|
|
app.include_router(voice_cloning.router, prefix="/voice", tags=["Voice Cloning"])
|
|
app.include_router(video_processing.router, prefix="/process", tags=["Video Processing"])
|
|
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
return {
|
|
"title": "AI Video Dubbing API",
|
|
"documentation": "/docs",
|
|
"health": "/health"
|
|
}
|
|
|
|
|
|
@app.get("/health")
|
|
async def health_check():
|
|
return {
|
|
"status": "healthy",
|
|
"service": "AI Video Dubbing API",
|
|
"database": "connected"
|
|
}
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
uvicorn.run(app, host="0.0.0.0", port=8000) |