Spaces:
Building
Building
from fastapi import FastAPI | |
from fastapi.middleware.cors import CORSMiddleware | |
import logging | |
import os | |
from dotenv import load_dotenv | |
# Load environment variables | |
load_dotenv() | |
from app.database import init_db # Import init_db | |
from app.auth import router as auth_router | |
from app.upload import router as upload_router | |
from app.dashboard import router as dashboard_router | |
from app.agent.custom_chatbot import router as custom_chatbot_router | |
from app.feeds import router as feeds_router | |
# from app.routes import pdf_ingestions | |
# Initialize logger | |
logging.basicConfig(level=logging.INFO) | |
logger = logging.getLogger(__name__) | |
app = FastAPI( | |
title="Dubsway Video AI", | |
description="Production-ready API for auth, video upload, and analysis with Groq LLM integration", | |
version="1.0.0", | |
docs_url="/docs", # Optional: secure this in prod | |
redoc_url=None, | |
) | |
# Allow frontend (adjust in prod!) | |
app.add_middleware( | |
CORSMiddleware, | |
allow_origins=["*"], # REPLACE with frontend URL in production! | |
allow_credentials=True, | |
allow_methods=["*"], | |
allow_headers=["*"], | |
) | |
# Include API routes | |
app.include_router(auth_router, prefix="/api", tags=["Auth"]) | |
app.include_router(upload_router, prefix="/api", tags=["Upload"]) | |
app.include_router(dashboard_router, prefix="/api", tags=["Dashboard"]) | |
app.include_router(custom_chatbot_router, prefix="/api", tags=["Custom Chatbot"]) | |
app.include_router(feeds_router, prefix="/api", tags=["Feeds"]) | |
# app.include_router(pdf_ingestion.router, prefix="/api", tags=["PDF Ingestion"]) | |
async def root(): | |
"""Root endpoint for Hugging Face Spaces""" | |
return { | |
"message": "π₯ Dubsway Video AI API", | |
"version": "1.0.0", | |
"docs": "/docs", | |
"status": "running" | |
} | |
async def startup_event(): | |
logger.info("β FastAPI app started") | |
logger.info(f"Environment: {os.getenv('ENVIRONMENT', 'development')}") | |
logger.info(f"Database URL configured: {'DATABASE_URL' in os.environ}") | |
await init_db() | |
async def shutdown_event(): | |
logger.info("π FastAPI app shutdown") | |