117 lines
4.7 KiB
Python
117 lines
4.7 KiB
Python
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
import logging
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
# Add parent directory to path for imports
|
|
sys.path.insert(0, str(Path(__file__).parent.parent))
|
|
sys.path.insert(0, str(Path(__file__).parent)) # Add backend directory too
|
|
|
|
from backend.api.validation import router as validation_router
|
|
from backend.api.transcripts import router as transcripts_router
|
|
from backend.api.transcripts_stub import youtube_auth_router # Keep stub for YouTube auth
|
|
from backend.api.summarization import router as summarization_router
|
|
from backend.api.pipeline import router as pipeline_router
|
|
from backend.api.cache import router as cache_router
|
|
from backend.api.videos import router as videos_router
|
|
from backend.api.models import router as models_router
|
|
from backend.api.export import router as export_router
|
|
from backend.api.templates import router as templates_router
|
|
from backend.api.auth import router as auth_router
|
|
from backend.api.summaries import router as summaries_unified_router
|
|
from backend.api.batch import router as batch_router
|
|
from backend.api.history import router as history_router
|
|
from backend.api.multi_agent import router as multi_agent_router
|
|
from backend.api.summaries_fs import router as summaries_fs_router
|
|
from backend.api.analysis_templates import router as analysis_templates_router
|
|
from backend.api.chat import router as chat_router
|
|
from backend.api.websocket_chat import router as websocket_chat_router
|
|
from backend.api.websocket_processing import router as websocket_processing_router
|
|
from core.database import engine, Base
|
|
from core.config import settings
|
|
|
|
# YouTube authentication is handled by the backend API auth router
|
|
|
|
# Configure logging
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
|
)
|
|
|
|
app = FastAPI(
|
|
title="YouTube Summarizer API",
|
|
description="AI-powered YouTube video summarization service with user authentication",
|
|
version="3.1.0"
|
|
)
|
|
|
|
# Create database tables on startup
|
|
@app.on_event("startup")
|
|
async def startup_event():
|
|
"""Initialize database and create tables."""
|
|
# Import all models to ensure they are registered
|
|
from backend.models import (
|
|
User, RefreshToken, APIKey, EmailVerificationToken, PasswordResetToken,
|
|
Summary, ExportHistory, BatchJob, BatchJobItem,
|
|
Playlist, PlaylistVideo, MultiVideoAnalysis,
|
|
PromptTemplate, AgentSummary,
|
|
EnhancedExport, ExportSection, ExportMetadata, SummarySection,
|
|
RAGChunk, VectorEmbedding, SemanticSearchResult,
|
|
ChatSession, ChatMessage, VideoChunk
|
|
)
|
|
from backend.core.database_registry import registry
|
|
|
|
# Create all tables using the registry (checkfirst=True to skip existing)
|
|
try:
|
|
registry.create_all_tables(engine)
|
|
logging.info("Database tables created/verified using registry")
|
|
except Exception as e:
|
|
logging.warning(f"Table creation warning (likely tables already exist): {e}")
|
|
# This is usually fine - tables may already exist from migrations
|
|
|
|
# Configure CORS
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["http://localhost:3000", "http://localhost:3001", "http://localhost:3002", "http://localhost:3003"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# Include routers
|
|
app.include_router(auth_router) # Authentication routes first
|
|
# YouTube auth is handled by the backend auth router above
|
|
app.include_router(validation_router)
|
|
app.include_router(transcripts_router)
|
|
app.include_router(youtube_auth_router) # YouTube auth stub endpoints
|
|
app.include_router(summarization_router)
|
|
app.include_router(pipeline_router)
|
|
app.include_router(cache_router)
|
|
app.include_router(videos_router)
|
|
app.include_router(models_router)
|
|
app.include_router(export_router)
|
|
app.include_router(templates_router)
|
|
app.include_router(summaries_unified_router) # Unified summary management (database)
|
|
app.include_router(batch_router) # Batch processing
|
|
app.include_router(history_router) # Job history from persistent storage
|
|
app.include_router(multi_agent_router) # Multi-agent analysis system
|
|
app.include_router(summaries_fs_router) # File-based summary management
|
|
app.include_router(analysis_templates_router) # Template-based unified analysis system
|
|
app.include_router(chat_router) # RAG-powered video chat
|
|
app.include_router(websocket_chat_router) # WebSocket endpoints for real-time chat
|
|
app.include_router(websocket_processing_router) # WebSocket endpoints for processing updates
|
|
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
return {"message": "YouTube Summarizer API", "version": "1.0.0"}
|
|
|
|
|
|
@app.get("/health")
|
|
async def health_check():
|
|
return {"status": "healthy"}
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
uvicorn.run(app, host="0.0.0.0", port=8000) |