Skip to content
This repository was archived by the owner on Dec 23, 2025. It is now read-only.

beforeapril/experimental

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PDF 문서 레이아웃 분석 API

PDF 파일을 분석하여 문서의 레이아웃 정보를 제공하는 REST API 서버입니다.

preview

프로젝트 구조

experimental/
├── model/               # 레이아웃 감지 모델 관련 코드
│   └── layout_detection.py
├── util/                # 유틸리티 함수 
│   └── pdf.py
├── interface/           # 인터페이스 관련 코드
├── server.py            # Flask 서버 메인 파일
├── pyproject.toml       # 프로젝트 의존성 설정
└── poetry.lock          # 의존성 버전 락 파일

기술 스택

  • Python 3.11+
  • Flask 3.1.1+
  • PaddlePaddle 3.0.0+
  • PaddleX 3.0.0+
  • PyPDFium2 4.30.1+
  • OpenCV 4.11.0+
  • PDF2Image 1.17.0+
  • 기타 의존성 라이브러리

설치 방법

Poetry 사용 (권장)

  1. Poetry 설치 (아직 설치하지 않은 경우):

    curl -sSL https://install.python-poetry.org | python3 -
  2. 의존성 설치:

    poetry install
  3. 가상 환경 활성화:

    poetry shell
  4. 서버 실행:

    python server.py

Pip 사용

  1. 가상 환경 생성 및 활성화:

    python -m venv .venv
    source .venv/bin/activate  # Linux/Mac
    # 또는
    .venv\Scripts\activate  # Windows
  2. 의존성 설치:

    pip install -e .
  3. 서버 실행:

    python server.py

API 엔드포인트

상태 확인

  • URL: /health
  • 메소드: GET
  • 응답 예시:
    {
      "status": "ok"
    }

PDF 분석

  • URL: /analyze-pdf
  • 메소드: POST
  • 요청 형식: multipart/form-data
  • 필수 파라미터: file (PDF 파일)
  • 응답 예시:
    {
      "total_pages": 2,
      "results": [
        {
          "page": 1,
          "layout": {
            "boxes": [
              {
                "id": "0",
                "label": "title",
                "score": 0.98,
                "coordinate": [0.1, 0.1, 0.9, 0.2]
              },
              {
                "id": "1",
                "label": "text",
                "score": 0.95,
                "coordinate": [0.1, 0.3, 0.9, 0.8]
              }
            ]
          }
        },
        {
          "page": 2,
          "layout": {
            "boxes": [
              {
                "id": "0",
                "label": "text",
                "score": 0.96,
                "coordinate": [0.1, 0.1, 0.9, 0.9]
              }
            ]
          }
        }
      ]
    }

CORS 지원

API는 CORS(Cross-Origin Resource Sharing)를 지원합니다. 현재 모든 오리진(*)에서 API에 액세스할 수 있습니다. 특정 도메인만 허용하려면 server.py 파일에서 CORS 설정을 수정하세요:

CORS(app, resources={r"/*": {"origins": "허용할도메인.com"}})

사용 예시

Python 클라이언트 예제:

import requests

url = "http://localhost:5000/analyze-pdf"
files = {"file": open("example.pdf", "rb")}

response = requests.post(url, files=files)
print(response.json())

cURL 예제:

curl -X POST -F "file=@example.pdf" http://localhost:5000/analyze-pdf

개발 환경

서버는 기본적으로 개발 모드로 실행되며, 디버그 모드가 활성화되어 있습니다. 프로덕션 환경에서는 적절한 WSGI 서버(예: Gunicorn)를 사용하는 것이 권장됩니다.

About

기술 실험

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors