Spaces:
Build error
Build error
| """ | |
| Video Dubbing Agent — Deployed Version | |
| Run: python main.py | |
| Access: http://localhost:7860 | |
| """ | |
| import logging | |
| import sys | |
| from contextlib import asynccontextmanager | |
| from fastapi import FastAPI | |
| from fastapi.staticfiles import StaticFiles | |
| from fastapi.responses import FileResponse | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from config import HOST, PORT, DEBUG, STATIC_DIR, TEMPLATES_DIR | |
| from routes.dub import router as dub_router | |
| from routes.info import router as info_router | |
| from utils.file_manager import cleanup_expired_jobs | |
| logging.basicConfig( | |
| level=logging.INFO, | |
| format="%(asctime)s [%(levelname)s] %(name)s: %(message)s", | |
| handlers=[logging.StreamHandler(sys.stdout)], | |
| ) | |
| logger = logging.getLogger(__name__) | |
| async def lifespan(app: FastAPI): | |
| logger.info("Video Dubbing Agent starting...") | |
| cleanup_expired_jobs() | |
| logger.info(f"Ready at http://localhost:{PORT}") | |
| yield | |
| logger.info("Shutting down.") | |
| app = FastAPI( | |
| title="Video Dubbing Agent", | |
| description="AI video dubbing: YouTube → any language. Male voice. Free GPU transcription.", | |
| version="2.0.0", | |
| lifespan=lifespan, | |
| ) | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| STATIC_DIR.mkdir(exist_ok=True) | |
| app.mount("/static", StaticFiles(directory=str(STATIC_DIR)), name="static") | |
| app.include_router(dub_router, prefix="/api", tags=["Dubbing"]) | |
| app.include_router(info_router, prefix="/api", tags=["Info"]) | |
| async def serve_frontend(): | |
| index_path = TEMPLATES_DIR / "index.html" | |
| if index_path.exists(): | |
| return FileResponse(str(index_path)) | |
| return {"message": "Video Dubbing Agent API. Visit /docs for API docs."} | |
| async def health(): | |
| return {"status": "healthy", "service": "video-dubbing-agent", "version": "2.0"} | |
| if __name__ == "__main__": | |
| import uvicorn | |
| uvicorn.run("main:app", host=HOST, port=PORT, reload=False) | |