[PR #11240] [CLOSED] PR: fix PDF loader when using default Content Extraction Engine and OCR #22695

Closed
opened 2026-04-20 04:19:31 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/11240
Author: @rgaricano
Created: 3/5/2025
Status: Closed

Base: devHead: dev


📝 Commits (10+)

📊 Changes

4 files changed (+10 additions, -11 deletions)

View changed files

📝 backend/open_webui/retrieval/loaders/main.py (+2 -2)
📝 backend/open_webui/utils/pdf_generator.py (+2 -2)
📝 backend/requirements.txt (+4 -4)
📝 pyproject.toml (+2 -3)

📄 Description

Pull Request

Fix PDF loader when using default Content Extraction Engine and OCR

Checklist

  • [ x] Target branch: Please verify that the pull request targets the dev branch.
  • [ x] Description: Provide a concise description of the changes made in this pull request.
  • Changelog: Ensure a changelog entry following the format of Keep a Changelog is added at the bottom of the PR description.
  • Documentation: Have you updated relevant documentation Open WebUI Docs, or other documentation sources?
  • [x ] Dependencies: Are there any new dependencies? Have you updated the dependency versions in the documentation?
  • [ x] Testing: Have you written and run sufficient tests for validating the changes?
  • [ x] Code review: Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards?
  • Prefix: To cleary categorize this pull request, prefix the pull request title, using one of the following:
  • BREAKING CHANGE: Significant changes that may affect compatibility
  • build: Changes that affect the build system or external dependencies
    • ci: Changes to our continuous integration processes or workflows
    • chore: Refactor, cleanup, or other non-functional code changes
    • docs: Documentation update or addition
    • feat: Introduces a new feature or enhancement to the codebase
    • fix: Bug fix or error correction
    • i18n: Internationalization or localization changes
    • perf: Performance improvement
  • refactor: Code restructuring for better maintainability, readability, or scalability
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc.)
    • test: Adding missing tests or correcting existing tests
  • WIP: Work in progress, a temporary label for incomplete or ongoing work

Changelog Entry

Fix PDF loader when using default CEE and OCR

Description

Fix PDF loader when using default Content Extraction Engine and OCR enabled

Commit to fixing issues due to incorrect dimension calculation when reshaping images using the Langchain class Pypdfloader.

Using the UnsestructuredPDFLoader call instead of the PyPDFLoader call fixes errors encountered when processing PDF files with images.

(before I tried with PyMuPDF, is fast and do the work well, but with AGPL License, it was't approved,
In this case I use unstructured lib, same as is allready been used, with apache license.
unstructured[pdf] is an extra option with that requirements:
Provides-Extra: pdf
Requires-Dist: onnx ; extra == 'pdf'
Requires-Dist: pdf2image ; extra == 'pdf'
Requires-Dist: pdfminer.six ; extra == 'pdf'
Requires-Dist: pikepdf ; extra == 'pdf'
Requires-Dist: pi-heif ; extra == 'pdf'
Requires-Dist: pypdf ; extra == 'pdf'
Requires-Dist: google-cloud-vision ; extra == 'pdf'
Requires-Dist: effdet ; extra == 'pdf'
Requires-Dist: unstructured-inference (>=0.8.7) ; extra == 'pdf'
Requires-Dist: unstructured.pytesseract (>=0.3.12) ; extra == 'pdf'

As I don't know if all unstructured options are going to be installed, i added a specific entry in requirements.txt: unstructured[pdf]

Note: when testing it give this errors:

  • No module named 'unstructured_inference'
    (I run pip install unstructured_inference)
    & after
  • No module named 'pdf2image'
    (I run pip install pdf2image)

Please check that, maybe some of these dependencies may not be desired. ?
unstructured_inference requirements

Requires-Dist: python-multipart
Requires-Dist: huggingface-hub
Requires-Dist: numpy (<2)
Requires-Dist: opencv-python (!=4.7.0.68)
Requires-Dist: onnx
Requires-Dist: onnxruntime (>=1.17.0)
Requires-Dist: matplotlib
Requires-Dist: torch
Requires-Dist: timm
Requires-Dist: transformers (>=4.25.1)
Requires-Dist: rapidfuzz
Requires-Dist: pandas
Requires-Dist: scipy
Requires-Dist: pypdfium2
Requires-Dist: pdfminer-six (==20240706)

With this steps seem it work ok,
In this question you may need to do some testing to make sure all dependencies are installed correctly, if not you may need to explicitly list those libraries.

Licenses that I revised (pdfminer & pdf2image), others than own unstructured, are MIT.

Added

Changed

replace call to langchain-community PyPDFLoader class by langchain-community UnstructuredPDFLoader class

Deprecated

Removed

Fixed

Errors uploading pdf files with default content extraction engine (internal) and OCR feature

Security

Breaking Changes


Additional Information

https://github.com/open-webui/open-webui/discussions/11171
https://github.com/open-webui/open-webui/discussions/4458

Screenshots or Videos

openwebui_pdf_default_unstructured_ocrs_relevant
openwebui_pdf_default_unstructured_ocrs_complete
openwebui_pdf_UED
openwebui_pdf_UFR


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/11240 **Author:** [@rgaricano](https://github.com/rgaricano) **Created:** 3/5/2025 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `dev` --- ### 📝 Commits (10+) - [`9f77c64`](https://github.com/open-webui/open-webui/commit/9f77c64e62d9d8654b877f669822b04bbb09b627) Fix PDF loader when using default CEE and OCR - [`4ec5710`](https://github.com/open-webui/open-webui/commit/4ec57100489b4d19aee699eee9895e314300d305) refac: assets - [`aac5e07`](https://github.com/open-webui/open-webui/commit/aac5e0716a1cd12cdcc4898b214e72e2eec5a44a) Merge branch 'dev' of https://github.com/rgaricano/open-webui into dev - [`7af2a2c`](https://github.com/open-webui/open-webui/commit/7af2a2c0bf3e8caab94587744a1fb23816aacbae) Update main.py - [`197fafa`](https://github.com/open-webui/open-webui/commit/197fafac3b29a0e7c3cb74f1e25d0ee397c0db62) Merge branch 'open-webui:dev' into dev - [`f27451a`](https://github.com/open-webui/open-webui/commit/f27451a86f71d1473fe3e2e1d41f1bd2fcfe5547) Update main.py fix PDF loader when using default Content Extraction Engine and OCR - [`01b6b04`](https://github.com/open-webui/open-webui/commit/01b6b04604ee65b16ff6339d026b6f499b5ac19c) Update requirements.txt for fix PDF default engine+OCR - [`80ebd80`](https://github.com/open-webui/open-webui/commit/80ebd807b82cc26f86e9188299cd2c8ebc196aeb) Update pyproject.toml - [`17f1d49`](https://github.com/open-webui/open-webui/commit/17f1d4909dcb78a4032fa7c983eac055c90c668b) Merge branch 'open-webui:dev' into dev - [`daae293`](https://github.com/open-webui/open-webui/commit/daae293d6f6e29474625b8be255b7e0abfaf7d16) Merge branch 'open-webui:dev' into dev ### 📊 Changes **4 files changed** (+10 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/retrieval/loaders/main.py` (+2 -2) 📝 `backend/open_webui/utils/pdf_generator.py` (+2 -2) 📝 `backend/requirements.txt` (+4 -4) 📝 `pyproject.toml` (+2 -3) </details> ### 📄 Description # Pull Request ## Fix PDF loader when using default Content Extraction Engine and OCR ## Checklist - [ x] **Target branch:** Please verify that the pull request targets the `dev` branch. - [ x] **Description:** Provide a concise description of the changes made in this pull request. - [ ] **Changelog:** Ensure a changelog entry following the format of [Keep a Changelog](https://keepachangelog.com/) is added at the bottom of the PR description. - [ ] **Documentation:** Have you updated relevant documentation [Open WebUI Docs](https://github.com/open-webui/docs), or other documentation sources? - [x ] **Dependencies:** Are there any new dependencies? Have you updated the dependency versions in the documentation? - [ x] **Testing:** Have you written and run sufficient tests for validating the changes? - [ x] **Code review:** Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards? - [ ] **Prefix:** To cleary categorize this pull request, prefix the pull request title, using one of the following: - **BREAKING CHANGE**: Significant changes that may affect compatibility - **build**: Changes that affect the build system or external dependencies - **ci**: Changes to our continuous integration processes or workflows - **chore**: Refactor, cleanup, or other non-functional code changes - **docs**: Documentation update or addition - **feat**: Introduces a new feature or enhancement to the codebase - **fix**: Bug fix or error correction - **i18n**: Internationalization or localization changes - **perf**: Performance improvement - **refactor**: Code restructuring for better maintainability, readability, or scalability - **style**: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc.) - **test**: Adding missing tests or correcting existing tests - **WIP**: Work in progress, a temporary label for incomplete or ongoing work # Changelog Entry Fix PDF loader when using default CEE and OCR ### Description Fix PDF loader when using default Content Extraction Engine and OCR enabled Commit to fixing issues due to incorrect dimension calculation when reshaping images using the Langchain class Pypdfloader. Using the UnsestructuredPDFLoader call instead of the PyPDFLoader call fixes errors encountered when processing PDF files with images. (before I tried with PyMuPDF, is fast and do the work well, but with AGPL License, it was't approved, In this case I use unstructured lib, same as is allready been used, with apache license. unstructured[pdf] is an extra option with that requirements: Provides-Extra: pdf Requires-Dist: onnx ; extra == 'pdf' Requires-Dist: pdf2image ; extra == 'pdf' Requires-Dist: pdfminer.six ; extra == 'pdf' Requires-Dist: pikepdf ; extra == 'pdf' Requires-Dist: pi-heif ; extra == 'pdf' Requires-Dist: pypdf ; extra == 'pdf' Requires-Dist: google-cloud-vision ; extra == 'pdf' Requires-Dist: effdet ; extra == 'pdf' Requires-Dist: unstructured-inference (>=0.8.7) ; extra == 'pdf' Requires-Dist: unstructured.pytesseract (>=0.3.12) ; extra == 'pdf' As I don't know if all unstructured options are going to be installed, i added a specific entry in requirements.txt: unstructured[pdf] Note: when testing it give this errors: - No module named 'unstructured_inference' (I run `pip install unstructured_inference`) & after - No module named 'pdf2image' (I run `pip install pdf2image`) Please check that, maybe some of these dependencies may not be desired. ? unstructured_inference requirements ------------------- Requires-Dist: python-multipart Requires-Dist: huggingface-hub Requires-Dist: numpy (<2) Requires-Dist: opencv-python (!=4.7.0.68) Requires-Dist: onnx Requires-Dist: onnxruntime (>=1.17.0) Requires-Dist: matplotlib Requires-Dist: torch Requires-Dist: timm Requires-Dist: transformers (>=4.25.1) Requires-Dist: rapidfuzz Requires-Dist: pandas Requires-Dist: scipy Requires-Dist: pypdfium2 Requires-Dist: pdfminer-six (==20240706) With this steps seem it work ok, In this question you may need to do some testing to make sure all dependencies are installed correctly, if not you may need to explicitly list those libraries. Licenses that I revised (pdfminer & pdf2image), others than own unstructured, are MIT. ### Added ### Changed replace call to langchain-community PyPDFLoader class by langchain-community UnstructuredPDFLoader class ### Deprecated ### Removed ### Fixed Errors uploading pdf files with default content extraction engine (internal) and OCR feature ### Security ### Breaking Changes --- ### Additional Information https://github.com/open-webui/open-webui/discussions/11171 https://github.com/open-webui/open-webui/discussions/4458 ### Screenshots or Videos ![openwebui_pdf_default_unstructured_ocrs_relevant](https://github.com/user-attachments/assets/a8556afc-c0fd-4053-911f-85f29c934a3b) ![openwebui_pdf_default_unstructured_ocrs_complete](https://github.com/user-attachments/assets/b9d44e32-f6e5-4a21-a955-83cb01fc62f5) ![openwebui_pdf_UED](https://github.com/user-attachments/assets/cc515210-2552-4ac7-a69a-1722a155dbce) ![openwebui_pdf_UFR](https://github.com/user-attachments/assets/961911ac-fc8b-489f-a457-3928201759e5) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-20 04:19:31 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#22695