diff --git a/app.py b/app.py index db0c30d..1046f3f 100644 --- a/app.py +++ b/app.py @@ -5,6 +5,7 @@ from PIL import Image import json import os import uuid +import numpy as np # 페이지 설정 st.set_page_config(page_title="PaddleOCR 이미지 분석", layout="wide") @@ -56,16 +57,9 @@ if uploaded_file is not None: # 분석 시작 버튼 if st.button("분석 시작하기", use_container_width=True): with st.spinner("이미지를 분석하고 있습니다..."): - # PIL 이미지를 바이트로 변환하여 예측 - # PPStructureV3는 파일 경로 또는 numpy 배열을 입력으로 받습니다. - # 업로드된 파일을 임시 저장하여 경로를 전달합니다. - temp_image_path = output_dir / f"temp_{unique_id}_{uploaded_file.name}" - - # 변환된 이미지를 임시 파일로 저장 - image.save(temp_image_path) - - # PPStructureV3로 예측 수행 - output = structure.predict(input=str(temp_image_path)) + # PIL 이미지를 numpy 배열로 변환하여 예측 + img_array = np.array(image) + output = structure.predict(input=img_array) if not output: st.warning("이미지에서 구조를 감지하지 못했습니다.") @@ -165,9 +159,9 @@ if uploaded_file is not None: with st.expander(f"`{json_path.name}` 전체 내용 보기"): st.json(json_data) - # 임시 파일 삭제 - if temp_image_path.exists(): - os.remove(temp_image_path) + # 임시 파일 삭제 (이제 필요 없음) + # if temp_image_path.exists(): + # os.remove(temp_image_path) except Exception as e: st.error(f"이미지 처리 중 예상치 못한 오류가 발생했습니다: {e}")