Using PIP Python Package

iApp Technology just released a PIP Python Package on Thai Document OCR.

For easing the python development using iApp AI API service, we have released the iapp_ai python pip package. It is the api client library for iApp AI API service for python.

Installation

$ pip install iapp_ai

Note: It can be either pip or pip3 depend on your environment.

Calling Thai Document OCR API (support pdf, png, gif, jpg, jpeg file)

  • Return as Plain Text

# Document OCR required a file path
api.document_ocr_plaintext("iapp_ai/media/pdf01.pdf").json()
  • Return as JSON Layout

# Document OCR required a file path
api.document_ocr_json_layout("iapp_ai/media/pdf01.pdf").json()
  • Return as DOCX file

# Document OCR required a file path
api.document_ocr_json_layout("iapp_ai/media/pdf01.pdf").json()

Example Usages

import iapp_ai


# You can request API key at https://ai.iapp.co.th
apikey = 'XXXXX_Your_API_Key_XXXXX' 

api = iapp_ai.api(apikey)

# Document OCR required a file path.
# Return PlainText
result_plaintext = api.document_ocr_plaintext("iapp_ai/media/pdf01.pdf").json()
print(result_plaintext)

# '{'text': ['ที่กค๐๔๐๙๒๒๕๖๘ กรมบัญชีกลาง\nถนนพระรามที่5กทม ๑๐๔๐๐\n๒๖\nตุลาคม ๒๕๖๔\nเรื่อง 
# การพัฒนาความรู้ของผู้ปฏิบัติงานด้านการตรวจสอบภายในสำหรับหน่วยงานของรัฐประจำ ปีงบประมาณ\nพศ ๒๕๖๕\nเรียน 
# ปลัดกระทรวง อธิบดี อธิการบดี เลขาธิการ ผู้อำนวยการ 
# ผู้บัญชาการผู้ว่าราชการจังหวัด ผู้ว่าราชการ\nกรุงเทพมหานคร
# ...
# ], 
# 'time': 9.49891972541809
# }'

# Return JSON Layout
result_jsonLayout = api.document_ocr_json_layout("iapp_ai/media/pdf01.pdf").json()
print(result_jsonLayout)

# {'pages': [{'components': [{'bb_bottom': 1616.8448486328125, 'bb_left': 192.82077026367188,
# 'bb_right': 1499.8006591796875, 'bb_top': 1455.723876953125,
# 'text': '๒ หลักสูตรผู้ปฏิบัติงานตรวจสอบภายในที่ได้รับการแต่งตั้งใหม่จำนวน ๑๘ ชั่วโมง\nประกอบด้วย 
# ภาพรวมงานตรวจสอบภายในกระบวนการตรวจสอบภายในและการกำกับดูแล การบริหาร\nจัดการความ
# เสี่ยงและการควบคุมภายใน', 'type': 'Para1'}, ...]
#, 'time': 11.47258472442627
# }'

# Return docx file
result_docx = api.document_ocr_json_layout("iapp_ai/media/pdf01.pdf").json()
print(result_docx)

# https://storage.googleapis.com/iapp-ocr-docx/result_pdf_1674029783.449044.docx?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=ai-ocr%40iapp-ai-357013.iam.gserviceaccount.com%2F20230118%2Fauto%2Fstorage%2F
# goog4_request&X-Goog-Date=20230118T081623Z&X-Goog-Expires=600&X-Goog-SignedHeaders=host&X-Goog-Signature=3ac95575db7e703764c1596e309c3e62f7880aed8ddb4506390a7ca62cd8b8e9d05414bf2b688af8272b035f940bee9526f27b7a55
# 872d43f1f11185b71a346be45266e39c355e3b67cbf57349ee6d2432aec4628e6d225e1eb5f668faa6520a2b3c498d4a7143ec9e67eecab2a59db60795c7671762d38fa4d4cb477586a78a4b20163a0d0c7391f397277242aa2fbb7f8b2fe76228d3b17b66307e8a898
# fc59aacde0170e5b03ef4ec67138c0ee6f3a44e8f5f1dc6b68b256dbd4ee7badf6cb4a196e9e5084c6b18e253c70b3a78309489dedb5ad8f0464233caa8f214dc05ce5254b5234a6cefa4b632b779a52961b4998c45c4220784ac9405f16ca49b6e

Full Example in Google Colaboratory

Last updated