Spaces:
Sleeping
Sleeping
| """ | |
| API Routes - ์ด๋ฏธ์ง ๋ถ์ ์๋ํฌ์ธํธ | |
| """ | |
| from fastapi import APIRouter, UploadFile, File, HTTPException, BackgroundTasks | |
| from fastapi.responses import JSONResponse | |
| from typing import List, Optional | |
| import uuid | |
| from datetime import datetime | |
| from app.services.hash_service import HashService | |
| from app.services.metadata_service import MetadataService | |
| from app.services.detection_service import DetectionService | |
| from app.services.pipeline_service import PipelineService | |
| from app.models.schemas import ( | |
| AnalysisResult, | |
| BatchAnalysisResult, | |
| ) | |
| router = APIRouter() | |
| # ์๋น์ค ์ธ์คํด์ค | |
| hash_service = HashService() | |
| metadata_service = MetadataService() | |
| detection_service = DetectionService() | |
| pipeline_service = PipelineService() | |
| async def analyze_single_image( | |
| file: UploadFile = File(...) | |
| ): | |
| """ | |
| ๋จ์ผ ์ด๋ฏธ์ง ๋ถ์ | |
| 3๊ฐ Layer๋ฅผ ์์ฐจ์ ์ผ๋ก ์คํํ์ฌ ์ข ํฉ ํ์ ๊ฒฐ๊ณผ๋ฅผ ๋ฐํํฉ๋๋ค. | |
| """ | |
| if not file.content_type or not file.content_type.startswith("image/"): | |
| raise HTTPException(status_code=400, detail="์ด๋ฏธ์ง ํ์ผ๋ง ์ ๋ก๋ ๊ฐ๋ฅํฉ๋๋ค.") | |
| try: | |
| contents = await file.read() | |
| result = await pipeline_service.analyze_image( | |
| image_bytes=contents, | |
| filename=file.filename | |
| ) | |
| return result | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=str(e)) | |
| async def analyze_batch_images( | |
| files: List[UploadFile] = File(...), | |
| ): | |
| """ | |
| ๋ฐฐ์น ์ด๋ฏธ์ง ๋ถ์ (์ต๋ 50๊ฐ) | |
| """ | |
| if len(files) > 50: | |
| raise HTTPException(status_code=400, detail="์ต๋ 50๊ฐ ํ์ผ๊น์ง ์ ๋ก๋ ๊ฐ๋ฅํฉ๋๋ค.") | |
| results = [] | |
| for file in files: | |
| if file.content_type and file.content_type.startswith("image/"): | |
| try: | |
| contents = await file.read() | |
| result = await pipeline_service.analyze_image( | |
| image_bytes=contents, | |
| filename=file.filename | |
| ) | |
| results.append(result) | |
| except Exception as e: | |
| results.append({ | |
| "filename": file.filename, | |
| "error": str(e), | |
| "status": "failed" | |
| }) | |
| # ํต๊ณ ๊ณ์ฐ | |
| total = len(results) | |
| ai_detected = sum(1 for r in results if isinstance(r, dict) and r.get("final_verdict") == "ai_generated") | |
| real_detected = sum(1 for r in results if isinstance(r, dict) and r.get("final_verdict") == "likely_real") | |
| return BatchAnalysisResult( | |
| total_processed=total, | |
| ai_generated_count=ai_detected, | |
| likely_real_count=real_detected, | |
| uncertain_count=total - ai_detected - real_detected, | |
| results=results | |
| ) | |