Skip to content

Commit

Permalink
Hot-Fix: 수정 AI 필기 분석
Browse files Browse the repository at this point in the history
수정: uuid는 자를 수 없음
이동: 디렉토리 생성 명령어는 도커파일 CMD에서
수정: 모델 없을 경우에만 다운로드
추가: 모델로드 기본 1회 실행
  • Loading branch information
semnisem committed Nov 16, 2024
1 parent bc19920 commit afe22d9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ RUN apt-get update && apt-get install -y git \

# 작업 디렉토리 설정
WORKDIR /test
RUN mkdir models

# 의존성 파일 복사 및 설치
COPY ./requirements.txt /test/requirements.txt
Expand All @@ -27,4 +26,4 @@ COPY ./app /test/app/
WORKDIR /test/app

# 컨테이너 실행 시 실행할 명령어
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
CMD ["bash", "-c", "mkdir -p /test/models && uvicorn main:app --host 0.0.0.0 --port 8000"]
23 changes: 18 additions & 5 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@


def create_file_path(obj_path, extension):
file_id = uuid4()[:4] # 각 클라이언트마다 고유한 파일 ID 생성
file_id = uuid4() # 각 클라이언트마다 고유한 파일 ID 생성
dir_path = obj_path.rsplit('/', 1)[0]
paths = {"input_path": f"{dir_path}/{file_id}.input.{extension}",
"mask_path": f"{dir_path}/{file_id}.mask.{extension}",
Expand Down Expand Up @@ -69,10 +69,21 @@ def upload_image_to_s3(file_bytes, file_path):
def download_model_from_s3(yolo_path: str = 'models/yolo11_best.pt', sam_path: str = 'models/sam_vit_h_4b8939.pth'):
dest_dir = f'../' # 모델을 저장할 컨테이너 내 경로
try:
s3_client.download_file(BUCKET_NAME, yolo_path, dest_dir+yolo_path)
s3_client.download_file(BUCKET_NAME, sam_path, dest_dir+sam_path)
logger.info(f'YOLOv11 & SAM models downloaded successfully to {dest_dir}')
logger.info(f"files in 'models' Dir: {os.listdir(dest_dir)}")
yolo_full_path = dest_dir+yolo_path
sam_full_path = dest_dir+sam_path
if not os.path.exists(yolo_full_path):
s3_client.download_file(BUCKET_NAME, yolo_path, yolo_full_path)
logger.info(f'YOLOv11 & SAM models downloaded successfully to {dest_dir}')
else:
logger.info(f'YOLOv11 already exists at {yolo_full_path}')
if not os.path.exists(sam_full_path):
s3_client.download_file(BUCKET_NAME, sam_path, sam_full_path)
logger.info(f'SAM models downloaded successfully to {dest_dir}')
else:
logger.info(f'SAM models already exists at {dest_dir}')


logger.info(f"Files in 'models' Dir: {os.listdir(dest_dir)}")
except Exception as e:
print(f'Failed to download model: {e}')

Expand All @@ -90,6 +101,8 @@ async def get_models():
logger.error("Error with Download & Saving AIs: %s", e)
raise HTTPException(status_code=500, detail="Error with Download & Saving AIs")

get_models()

@app.post("/process-shape")
async def processShape(request: Request):
""" AI handwriting detection & Telea Algorithm-based inpainting """
Expand Down

0 comments on commit afe22d9

Please sign in to comment.