KloudiHub Docs

Quickstart

Comprehensive guide for using the PaddleOCR API on Kloudihub.

Quickstart

The PaddleOCR API provides powerful multilingual OCR capabilities, allowing you to extract text from images and documents with high precision. This guide provides connection details, API usage, and code examples for various programming languages.

Introduction

PaddleOCR is an ultra-lightweight OCR system based on the PaddlePaddle deep learning framework. It covers a wide range of features including text detection, text recognition, and structure analysis. PaddleOCR is particularly effective for multilingual scenarios, supporting over 80 languages.

Whether you are processing standard scanned documents, street view images, or handwriting, PaddleOCR offers a robust and flexible solution. Key features include:

  • Multilingual Excellence: Superior performance in text recognition for a vast array of languages.
  • Ultra-Lightweight: Optimized for both high-performance servers and edge devices.
  • End-to-End Solution: Integrated text detection, direction classification, and recognition.
  • Highly Accurate: State-of-the-art results on various benchmark datasets.

properties

PropertyValue
Base URLhttps://kloudihub.com
Endpoint/api/v1/paddle-ocr
MethodPOST
Content-Typemultipart/form-data

Authentication

Authentication is handled via a Bearer Token. Ensure you include your API key in the Authorization header.

Authorization: Bearer <YOUR_API_KEY>

Request Parameters

The API accepts a file upload via multipart/form-data.

ParameterTypeRequiredDescription
fileFileYesThe image or document file to be processed (jpg, png, pdf).
langStringNoOptional language code (e.g., en, ch, fr) to improve detection.

Response Format

The API returns a JSON response containing the extracted text and layout information.

{
  "status": "success",
  "data": {
    "text": "Extracted text content...",
    "confidence": 0.95,
    "pages": 1
  }
}

Code Examples

curl -X POST https://kloudihub.com/api/v1/paddle-ocr \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "file=@/path/to/document.png"

Using the axios library:

const axios = require('axios');
const FormData = require('form-data');
const fs = require('fs');

const form = new FormData();
form.append('file', fs.createReadStream('/path/to/document.png'));

axios.post('https://kloudihub.com/api/v1/paddle-ocr', form, {
  headers: {
    ...form.getHeaders(),
    'Authorization': 'Bearer YOUR_API_KEY'
  }
})
.then(response => {
  console.log(response.data);
})
.catch(error => {
  console.error(error);
});

Using the native fetch API:

const fs = require('fs');

async function uploadFile() {
  const formData = new FormData();
  formData.append('file', new Blob([fs.readFileSync('/path/to/document.png')]), 'document.png');

  try {
    const response = await fetch('https://kloudihub.com/api/v1/paddle-ocr', {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer YOUR_API_KEY'
      },
      body: formData
    });
    const data = await response.json();
    console.log(data);
  } catch (error) {
    console.error('Error:', error);
  }
}

uploadFile();

Using axios with TypeScript:

import axios from 'axios';
import FormData from 'form-data';
import fs from 'fs';

interface OCRResponse {
  status: string;
  data: {
    text: string;
    confidence: number;
    pages: number;
  };
}

const uploadFile = async () => {
  const form = new FormData();
  form.append('file', fs.createReadStream('/path/to/document.png'));

  try {
    const { data } = await axios.post<OCRResponse>(
      'https://kloudihub.com/api/v1/paddle-ocr',
      form,
      {
        headers: {
          ...form.getHeaders(),
          'Authorization': 'Bearer YOUR_API_KEY',
        },
      }
    );
    console.log('Extracted Text:', data.data.text);
  } catch (error) {
    console.error('OCR Error:', error);
  }
};

uploadFile();

Using the requests library:

import requests

url = "https://kloudihub.com/api/v1/paddle-ocr"
file_path = "/path/to/document.png"
api_key = "YOUR_API_KEY"

with open(file_path, "rb") as file:
    files = {"file": file}
    headers = {
        "Authorization": f"Bearer {api_key}"
    }
    
    response = requests.post(url, headers=headers, files=files)
    
    if response.status_code == 200:
        print("Response:", response.json())
    else:
        print(f"Error {response.status_code}: {response.text}")

On this page