Skip to content

infordoc/PaddleOCRFastAPI

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

106 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Docker Build Python Build

PaddleOCRFastAPI

GitHub

中文

A simple way to deploy PaddleOCR based on FastAPI.

Support Version

PaddleOCR Branch Status
v3.x (v3.4.0) main ✅ Current
v2.7 paddleocr-v2.7 Legacy
v2.5 paddleocr-v2.5 Legacy

Note: The main branch now uses PaddleOCR 3.x with PaddlePaddle 3.0+, featuring improved performance, new model pipelines (PP-OCRv5), and unified inference interfaces.

Features

  • PaddleOCR 3.x with PP-OCRv5 models for enhanced accuracy
  • PaddlePaddle 3.0+ compatibility with optimized performance
  • Local path image recognition
  • Base64 data recognition
  • Upload file recognition
  • URL image recognition
  • PDF table extraction with PPStructureV3
  • Multi-language support (80+ languages)

Deployment Methods

Deploy Directly

  1. Copy the project to the deployment path

    git clone https://github.com/neozhu/PaddleOCRFastAPI.git

    The master branch is the most recent version of PaddleOCR supported by the project. To install a specific version, clone the branch with the corresponding version number.

  2. (Optional) Create new virtual environment to avoid dependency conflicts

  3. Install required dependencies

    pip3 install -r requirements.txt
  4. Run FastAPI

    uvicorn main:app --host 0.0.0.0

Docker Deployment

Test completed in Centos 7, Ubuntu 20.04, Ubuntu 22.04, Windows 10, Windows 11, requires Docker to be installed.

Quick Deploy with Dokploy

For deployment using Dokploy (Docker + GitHub), see:

Manual Docker Build

  1. Copy the project to the deployment path

    git clone https://github.com/neozhu/PaddleOCRFastAPI.git

    The master branch is the most recent version of PaddleOCR supported by the project. To install a specific version, clone the branch with the corresponding version number.

  2. Building a Docker Image

    cd PaddleOCRFastAPI
    # 手工下载模型,避免程序第一次运行时自动下载,实现完全离线,加快启动速度
    cd pp-ocrv4/ && sh download_det_cls_rec.sh
    
    # 返回Dockfile所在目录,开始build
    cd ..
    # 使用宿主机网络
    # 可直接使用宿主机上的代理设置,例如在build时,用宿主机上的代理
    # docker build -t paddleocrfastapi:latest --network host --build-arg HTTP_PROXY=http://127.0.0.1:8888 --build-arg HTTPS_PROXY=http://127.0.0.1:8888 .
    docker build -t paddleocrfastapi:latest --network host .
  3. Edit docker-compose.yml

    version: "3"
    
    services:
    
      paddleocrfastapi:
        container_name: paddleocrfastapi # Custom Container Name
        image: paddleocrfastapi:lastest # Customized Image Name & Label in Step 2
        environment:
          - TZ=Asia/Hong_Kong
          - OCR_LANGUAGE=ch # support 80 languages. refer to https://github.com/Mushroomcat9998/PaddleOCR/blob/main/doc/doc_en/multi_languages_en.md#language_abbreviations
        ports:
         - "8000:8000" # Customize the service exposure port, 8000 is the default FastAPI port, do not modify
        restart: unless-stopped
  4. Create the Docker container and run

    docker compose up -d
  5. Swagger Page at localhost:<port>/docs

deploy and push your local code as blazordevlab/paddleocrapi:latest to Docker Hub

  1. Login to Docker Hub
docker login
  1. Build the Docker Image
docker build -t blazordevlab/paddleocrapi:latest .
  1. Push the Image to Docker Hub
docker push blazordevlab/paddleocrapi:latest

Change language

  1. Clone this repo to localhost.

  2. Edit routers/ocr.py, modify the parameter "lang":

    ocr = PaddleOCR(use_angle_cls=True, lang="ch")

    Before modify, read the supported language list.

  3. Rebuild the docker image, or run the main.py directly.

Screenshots

API Docs: /docs

Swagger

What's New in PaddleOCR 3.x

This project has been upgraded to PaddleOCR 3.x, bringing significant improvements:

Key Upgrades

  1. New Model Pipelines: PP-OCRv5 with improved recognition accuracy for various text types including handwriting
  2. Unified Inference Interface: Simplified predict() API for streamlined usage
  3. PaddlePaddle 3.0 Compatibility: Full support for the latest PaddlePaddle features and optimizations
  4. Enhanced Table Recognition: PPStructureV3 for better document understanding and table extraction

Migration from 2.x

If you're upgrading from PaddleOCR 2.x:

  • The API now uses predict() method instead of ocr() with parameters
  • show_log parameter is replaced by a new logging system
  • use_onnx is replaced by high-performance inference features
  • PPStructure is now PPStructureV3

For more details, see the PaddleOCR 3.x Upgrade Documentation

Documentation

Roadmap

  • Support PaddleOCR v3.x (PP-OCRv5)
  • Image URL recognition
  • PDF table extraction
  • GPU mode optimization
  • Batch processing support
  • Real-time streaming OCR

License

PaddleOCRFastAPI is licensed under the MIT license. Refer to LICENSE for more information.

About

A simple way to deploy PaddleOCR based on FastAPI. (PaddleOCR 的 FastAPI 快速部署方案)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 97.4%
  • Dockerfile 2.2%
  • Shell 0.4%