File size: 2,029 Bytes
4ec3855
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
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__)


@asynccontextmanager
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"])


@app.get("/")
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."}


@app.get("/health")
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)