Adds server-side image safety check to ensure users upload pet photos instead of human images. Uses NudeNet with 0.5 confidence threshold and fail-open behavior. Frontend shows loading state during analysis and error UI when humans are detected. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
69 lines
1.8 KiB
Python
69 lines
1.8 KiB
Python
"""FastAPI application entry point."""
|
|
|
|
import logging
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.config import settings
|
|
from app.routers import health, image_safety, profanity, results, submissions, webhook
|
|
|
|
# Configure logging
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
|
)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
# Create FastAPI app
|
|
app = FastAPI(
|
|
title="PAH Backend API",
|
|
description="Valentine's Day Pet Love Song Generator Backend",
|
|
version="1.0.0",
|
|
)
|
|
|
|
# CORS configuration
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=settings.CORS_ORIGINS,
|
|
allow_credentials=True,
|
|
allow_methods=["GET", "POST"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# Include routers
|
|
app.include_router(submissions.router)
|
|
app.include_router(webhook.router)
|
|
app.include_router(results.router)
|
|
app.include_router(health.router)
|
|
app.include_router(profanity.router)
|
|
app.include_router(image_safety.router)
|
|
|
|
|
|
@app.on_event("startup")
|
|
async def startup_event() -> None:
|
|
"""Run on application startup."""
|
|
logger.info("PAH Backend API starting up...")
|
|
|
|
# Ensure storage directories exist
|
|
settings.IMG_STORAGE.mkdir(parents=True, exist_ok=True)
|
|
settings.AUDIO_STORAGE.mkdir(parents=True, exist_ok=True)
|
|
settings.VIDEO_STORAGE.mkdir(parents=True, exist_ok=True)
|
|
settings.COMPOSITE_STORAGE.mkdir(parents=True, exist_ok=True)
|
|
logger.info("Storage directories verified")
|
|
|
|
|
|
@app.on_event("shutdown")
|
|
async def shutdown_event() -> None:
|
|
"""Run on application shutdown."""
|
|
logger.info("PAH Backend API shutting down...")
|
|
|
|
|
|
@app.get("/")
|
|
async def root() -> dict:
|
|
"""Root endpoint returning API info."""
|
|
return {
|
|
"name": "PAH Backend API",
|
|
"version": "1.0.0",
|
|
"status": "running",
|
|
}
|