File size: 2,255 Bytes
1cff1e5
0eda9c2
1cff1e5
 
 
 
e39cad1
1cff1e5
03faf26
 
1cff1e5
 
0eda9c2
 
1cff1e5
5094515
1cff1e5
 
 
 
 
 
 
 
 
0eda9c2
 
 
 
 
 
 
 
 
 
 
1cff1e5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5094515
1cff1e5
 
 
 
 
e39cad1
 
 
 
 
 
 
 
 
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
from contextlib import asynccontextmanager
import asyncio
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
import os
import uvicorn



from config import get_settings
from database import connect_db, close_db
from services.tts_service import warmup_xtts_model
from services.stt_service import warmup_whisper_model

from routers import auth, resume, profile, interview, reports, admin, speech

settings = get_settings()


@asynccontextmanager
async def lifespan(app: FastAPI):
    # Startup
    await connect_db()
    os.makedirs(settings.UPLOAD_DIR, exist_ok=True)
    try:
        await asyncio.wait_for(warmup_xtts_model(), timeout=45)
        print("XTTS warmup: ready")
    except Exception as exc:
        print(f"XTTS warmup skipped: {exc}")

    try:
        await asyncio.wait_for(warmup_whisper_model(), timeout=45)
        print("Whisper warmup: ready")
    except Exception as exc:
        print(f"Whisper warmup skipped: {exc}")
    print(f"🚀 Interview Bot API running in {settings.APP_ENV} mode")
    yield
    # Shutdown
    await close_db()


app = FastAPI(
    title="AI Mock Interview Trainer",
    description="Production-ready AI-powered mock interview platform",
    version="1.0.0",
    lifespan=lifespan,
)

# CORS
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# Routers
app.include_router(auth.router, prefix="/auth", tags=["Authentication"])
app.include_router(resume.router, prefix="/resume", tags=["Resume"])
app.include_router(profile.router, prefix="/profile", tags=["Profile"])
app.include_router(interview.router, prefix="/interview", tags=["Interview"])
app.include_router(reports.router, prefix="/reports", tags=["Reports"])
app.include_router(admin.router, prefix="/admin", tags=["Admin"])
app.include_router(speech.router, prefix="/speech", tags=["Speech"])


@app.get("/health")
async def health_check():
    return {"status": "healthy", "version": "1.0.0"}


if __name__ == "__main__":
    uvicorn.run(
        "main:app",
        host=settings.APP_HOST,
        port=settings.APP_PORT,
        reload=settings.APP_ENV != "production",
    )