Lint 적용

This commit is contained in:
kyy
2025-11-06 11:57:29 +09:00
parent f9975620cb
commit 2c3b417f3b
3 changed files with 155 additions and 82 deletions

View File

@@ -1,20 +1,25 @@
import logging
from fastapi import APIRouter, File, HTTPException, UploadFile
from services.ocr_engine import process_document
router = APIRouter(prefix="/ocr", tags=["OCR"])
logger = logging.getLogger(__name__)
@router.post("", description="요청된 파일에서 Deepseek OCR을 수행하고 텍스트를 추출합니다.")
async def perform_ocr(document: UploadFile = File(..., description="OCR을 수행할 PDF 또는 이미지 파일")):
@router.post(
"", description="요청된 파일에서 Deepseek OCR을 수행하고 텍스트를 추출합니다."
)
async def perform_ocr(
document: UploadFile = File(..., description="OCR을 수행할 PDF 또는 이미지 파일"),
):
"""
클라이언트로부터 받은 파일을 OCR 엔진에 전달하고, 추출된 텍스트를 반환합니다.
- **document**: `multipart/form-data` 형식으로 전송된 파일.
"""
logger.info(f"'{document.filename}' 파일에 대한 OCR 요청 수신 (Content-Type: {document.content_type})")
logger.info(
f"'{document.filename}' 파일에 대한 OCR 요청 수신 (Content-Type: {document.content_type})"
)
try:
file_content = await document.read()
@@ -36,6 +41,8 @@ async def perform_ocr(document: UploadFile = File(..., description="OCR을 수
except Exception as e:
# 예상치 못한 서버 내부 오류
logger.exception(f"OCR 처리 중 예상치 못한 오류 발생: {e}")
raise HTTPException(status_code=500, detail=f"서버 내부 오류가 발생했습니다: {e}")
raise HTTPException(
status_code=500, detail=f"서버 내부 오류가 발생했습니다: {e}"
)
finally:
await document.close()