Skip to content

Commit

Permalink
추가: ocr api
Browse files Browse the repository at this point in the history
  • Loading branch information
rrosiee committed Jul 15, 2024
1 parent dc401f0 commit 0b617aa
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ jobs:
docker rm ticats_ai || true
docker image rm public.ecr.aws/h7p2f6d8/ticats_ai:latest || true
docker pull public.ecr.aws/h7p2f6d8/ticats_ai:latest
docker run -d -p 8000:8000 --name ticats_ai -e DATABASE_URL="${{ secrets.DATABASE_URL }}" public.ecr.aws/h7p2f6d8/ticats_ai:latest
docker run -d -p 8000:8000 --name ticats_ai -e DATABASE_URL="${{ secrets.DATABASE_URL }}" -e NAVER_SECRET_KEY="${{ secrets.NAVER_SECRET_KEY }}" -e GEMINAI_SECRET_KEY="${{ secrets.GEMINAI_SECRET_KEY }}" public.ecr.aws/h7p2f6d8/ticats_ai:latest
1 change: 0 additions & 1 deletion app/routers/keyword_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def get_keyword_service():
# Main Section
@router.get("", response_model=KeywordResponse)
async def get_keyword(goods_code: str = None, keyword_service: KeywordService = Depends(get_keyword_service)):

evaluation_text = keyword_service.get_evaluations(goods_code)
topic, sentiment = keyword_service.united_Processor(evaluation_text)

Expand Down
24 changes: 21 additions & 3 deletions app/routers/ocr_router.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import json
from typing import Optional

from fastapi import APIRouter, Depends, UploadFile, File
from pydantic import BaseModel

Expand All @@ -6,8 +9,10 @@

# Response schema definition
class OcrResponseSchema(BaseModel):
result: str
title: str
title: Optional[str]
place: Optional[str]
date: Optional[str]
seat: Optional[str]


# Router
Expand All @@ -21,4 +26,17 @@ class OcrResponseSchema(BaseModel):
async def upload_ocr_photo(image: UploadFile = File(...), ocr_service: OcrService = Depends(OcrService)):
image_content = await image.read()
ocr_result = ocr_service.info_extractor(image_content)
return ocr_result

# OCR 결과가 None일 경우 기본값을 설정
if ocr_result is None:
ocr_result = {}

# OCR 결과에서 필요한 필드를 추출하여 응답 형식에 맞게 변환
response_data = {
"title": ocr_result.get("공연제목") or None,
"place": ocr_result.get("공연장소") or None,
"date": ocr_result.get("공연날짜") or None,
"seat": ocr_result.get("좌석정보") or None
}

return response_data
2 changes: 1 addition & 1 deletion app/services/ocr_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def info_extraction(self, ocr_result):
if infos:
result = ast.literal_eval("{" + infos.group(1) + "}")
else:
result = {'info': 'None'}
result = {}

return result

Expand Down

0 comments on commit 0b617aa

Please sign in to comment.