Spire.OCR for Python 2.1.0 supports integration with cloud-based AI models

Spire.OCR for Python 2.1.0 supports integration with cloud-based AI models

2026-04-23 09:53:43

We’re pleased to announce the release of Spire.OCR for Python 2.1.0. This version enables seamless integration of cloud-based AI models—including Doubao, Qwen, and DeepSeek—into Spire.OCR for Python. These models help improve accuracy and enhance text recognition in images.

Here is a list of changes made in this release

Category ID Description
New Feature - Added support for integration of AI models into Spire.OCR. (Note: Users need to obtain an API Key from the AI platform on their own.)
def _run_ai_test(self):
    filename = "1.png"
    output_file = "scan.txt"
    file_path = r"F:\3.3.0AI\AI\ocr.xml"
    model = "AIModel"
    api_key = "ApiKey"
    api_url = "ApiUrl"
    self._update_ocr_config(file_path, model, api_key, api_url)
    self._scan_img(filename, output_file)


def _scan_img(self, filename, output_file):
    scanner = OcrScanner()
    configure_options = ConfigureOptions()
    configure_options.ModelPath = r"F:\3.3.0AI\AI"
    configure_options.Language = "Japanese"
    scanner.ConfigureDependencies(configure_options)
    scanner.Scan(filename)

    text = scanner.Text.ToString()
    with open(output_file, "w", encoding="utf-8") as f:
        f.write(text)


def _update_ocr_config(self, file_path, model, api_key, api_url):
    tree = ET.parse(file_path)
    root = tree.getroot()

    model_node = root.find('./configs/model')
    api_key_node = root.find('./configs/apiKey')
    api_url_node = root.find('./configs/apiUrl')

    if model_node is not None:
        model_node.text = model
    if api_key_node is not None:
        api_key_node.text = api_key
    if api_url_node is not None:
        api_url_node.text = api_url

    tree.write(file_path, encoding='utf-8', xml_declaration=True)
    print("XML updated successfully!")
Click the link to download Spire.OCR for Python 2.1.0: