Spaces:
Running
Running
| """ | |
| Deep-Dive Video Note Taker | |
| ========================== | |
| Main FastAPI Application Entry Point | |
| """ | |
| import os | |
| from contextlib import asynccontextmanager | |
| from fastapi import FastAPI | |
| from fastapi.staticfiles import StaticFiles | |
| from fastapi.templating import Jinja2Templates | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from backend.api.routes import router | |
| from backend.utils.logger import get_logger | |
| from backend.utils.config import settings | |
| logger = get_logger(__name__) | |
| async def lifespan(app: FastAPI): | |
| """Application lifespan manager β runs on startup and shutdown.""" | |
| # ββ STARTUP ββββββββββββββββββββββββββββββββββββββββββββββ | |
| logger.info("π Starting Deep-Dive Video Note Taker...") | |
| # Ensure all data directories exist | |
| dirs = [ | |
| settings.UPLOAD_DIR, | |
| settings.AUDIO_DIR, | |
| settings.TRANSCRIPT_DIR, | |
| settings.SUMMARY_DIR, | |
| "data/embeddings", | |
| "outputs/final_notes", | |
| "outputs/timestamps", | |
| "outputs/action_items", | |
| "outputs/reports", | |
| "frontend/static/uploads", | |
| "models/whisper", | |
| "models/summarization_model", | |
| "models/embedding_model", | |
| ] | |
| for d in dirs: | |
| os.makedirs(d, exist_ok=True) | |
| logger.info("β Directories initialised") | |
| logger.info(f"π Server running at http://{settings.APP_HOST}:{settings.APP_PORT}") | |
| yield | |
| # ββ SHUTDOWN βββββββββββββββββββββββββββββββββββββββββββββ | |
| logger.info("π Shutting down Deep-Dive Video Note Taker...") | |
| # ββ Application βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| app = FastAPI( | |
| title="Deep-Dive Video Note Taker", | |
| description=( | |
| "An AI-powered system that converts long-form videos into " | |
| "structured notes, timestamped highlights, and actionable insights." | |
| ), | |
| version="1.0.0", | |
| lifespan=lifespan, | |
| docs_url="/docs", | |
| redoc_url="/redoc", | |
| ) | |
| # ββ CORS ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| # ββ Static Files & Templates ββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| app.mount("/static", StaticFiles(directory="frontend/static"), name="static") | |
| templates = Jinja2Templates(directory="frontend/templates") | |
| # ββ Routers βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| app.include_router(router, prefix="/api/v1") | |
| # ββ Root redirect βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| from fastapi import Request | |
| from fastapi.responses import HTMLResponse | |
| async def root(request: Request): | |
| return templates.TemplateResponse(request=request, name="index.html") | |
| async def health_check(): | |
| return { | |
| "status": "healthy", | |
| "app": "Deep-Dive Video Note Taker", | |
| "version": "1.0.0", | |
| } | |