Skip to content

bentoml/BentoOCR

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Turning OCR Models into APIs with BentoML

This is a BentoML example project that demonstrates how to serve an OCR model. It accepts images as input and returns the text contained within. While the example uses EasyOCR, you can choose any other OCR model.

See here for a full list of BentoML example projects.

Install dependencies

  1. Make sure to install uv.

  2. Clone the repo and install dependencies.

    git clone https://github.com/bentoml/BentoOCR.git && cd BentoOCR
    
    # Recommend Python 3.11
    pip install -r requirements.txt

Save the model

Import the model into the BentoML Model Store.

python import_model.py

Run the BentoML Service

We have defined a BentoML Service in service.py to serve the model. To start it, run:

bentoml serve

The server is now active at http://localhost:3000. It exposes two API endpoints:

  • detect: Takes an image as input and returns a list of detected text regions. Each detection includes the extracted text and the bounding box coordinates of where the text was found in the image.
  • classify: Takes an image as input and returns a list with the extracted text and the confidence score for each text detection.

You can call these endpoints using the Swagger UI or in other different ways.

cURL

curl -X 'POST' \
  'http://localhost:3000/detect' \
  -H 'accept: application/json' \
  -H 'Content-Type: multipart/form-data' \
  -F 'image=@sample-image.png;type=image/png'

Python client

import bentoml
from pathlib import Path

with bentoml.SyncHTTPClient("http://localhost:3000/") as client:
    result = client.detect(
        image=Path("image.jpg"),
    )

Deploy to BentoCloud

After the Service is ready, you can deploy the application to BentoCloud for better management and scalability. Sign up if you haven't got a BentoCloud account.

Make sure you have logged in to BentoCloud.

bentoml cloud login

Deploy it to BentoCloud:

bentoml deploy

Once the application is up and running on BentoCloud, you can access it via the exposed URL.

Community

BentoML has a thriving open source community where thousands of ML/AI practitioners are contributing to the project, helping other users and discussing the future of AI. πŸ‘‰ Pop into our Slack community!

About

Turn any OCR models into online inference API endpoint πŸš€ πŸŒ–

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors 4

  •  
  •  
  •  
  •  

Languages