ai-image-filter / app /main.py
nepark's picture
Upload 34 files
0ac5675 verified
"""
AI Image Filter Pipeline - FastAPI Backend
ML ν•™μŠ΅ λ°μ΄ν„°μ…‹μ—μ„œ AI 생성 이미지λ₯Ό ν•„ν„°λ§ν•˜λŠ” νŒŒμ΄ν”„λΌμΈ
"""
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from contextlib import asynccontextmanager
from app.api import routes
@asynccontextmanager
async def lifespan(app: FastAPI):
"""μ•± μ‹œμž‘/μ’…λ£Œ μ‹œ μ‹€ν–‰λ˜λŠ” 둜직"""
# Startup
print("βœ… Service initialized (Stateless)")
yield
# Shutdown
print("πŸ‘‹ Shutting down...")
app = FastAPI(
title="AI Image Filter Pipeline",
description="""
## ML ν•™μŠ΅ 데이터 ν’ˆμ§ˆ 검증 νŒŒμ΄ν”„λΌμΈ
AI 생성 이미지λ₯Ό νƒμ§€ν•˜μ—¬ ν•™μŠ΅ λ°μ΄ν„°μ…‹μ˜ ν’ˆμ§ˆμ„ 보μž₯ν•©λ‹ˆλ‹€.
### 3-Layer 검증 μ‹œμŠ€ν…œ
- **Layer 1**: Hash Check - 이미지 ν•΄μ‹œ 계산 (MD5, SHA256, Perceptual Hash)
- **Layer 2**: Metadata Analysis - C2PA/EXIF 뢄석 및 AI 도ꡬ μ‹œκ·Έλ‹ˆμ²˜ 탐지
- **Layer 3**: AI Detection - ML λͺ¨λΈ 기반 AI 생성 이미지 탐지
*Stateless μ„œλΉ„μŠ€ - λ°μ΄ν„°λ² μ΄μŠ€ λ―Έμ‚¬μš©*
""",
version="1.0.0",
lifespan=lifespan
)
# CORS μ„€μ •
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# λΌμš°ν„° 등둝
app.include_router(routes.router, prefix="/api/v1", tags=["Image Analysis"])
@app.get("/", tags=["Health"])
async def root():
return {
"message": "AI Image Filter Pipeline API",
"docs": "/docs",
"health": "ok"
}
@app.get("/health", tags=["Health"])
async def health_check():
return {"status": "healthy"}