PyMuPDF Utilities for LLM/RAG with Visual Analyzer
Project description
Image Analyzer (New!)
PyMuPDF4LLM now includes a powerful Image Analyzer feature designed to bridge the gap between visual content and structured text. This feature uses Vision Language Models (VLMs) to extract detailed information from images—such as logos, complex tables, and charts—and convert them into clean, LLM-ready Markdown.
How it Works
The Image Analyzer is designed to handle the nuance of visual data that standard OCR often misses:
- Hierarchical Table Parsing: Specifically optimized to detect and reconstruct complex, multi-level X-axis structures (e.g., grouping data by "Model" then "Configuration").
- Brand & Logo Recognition: Identifies and transcribes visible text from logos and brand marks.
- Chart & Graph Interpretation: Converts bar charts, line graphs, and pie charts into structured Markdown tables, capturing data points and trend notes.
- Smart OCR: Uses a hybrid approach to only apply OCR where necessary (e.g., on scanned regions or illegible text), preserving the quality of native digital text.
Key Features
- Model Agnostic: Compatible with multiple inference backends, including Hugging Face, Groq, OpenAI, and llama-cpp-python.
- Layout-Aware: Maintains the natural reading order and structural context of the document.
- Markdown Optimized: Outputs are formatted specifically for RAG pipelines, ensuring that visual data is indexed as meaningfully as the surrounding text.
Usage
You can use the Image Analyzer by calling the analyze_image method from the ImageAnalyzer classes.
import pymupdf4llm
from pymupdf4llm.helpers.image_analyzer import HuggingFaceImageAnalyzer
# Initialize the analyzer with your preferred model
analyzer = HuggingFaceImageAnalyzer(model_name="Qwen/Qwen3.5-0.8B")
# Analyze an image and get the structured Markdown
markdown_output = analyzer.analyze_image("path/to/chart.png")
print(markdown_output)
Technical Details
- Prompt Engineering: Uses a sophisticated system prompt (
visual_descriptor.md) that enforces strict structural rules to prevent "hallucinated" layout collapses. - Performance: Optimized to be significantly faster and cheaper than standard vision-based LLM extraction by using targeted OCR and efficient inference.
- Customizable: Easily configure
max_output_tokens,temperature, andocr_dpito suit your specific data requirements.
Note: Ensure you have the required dependencies installed for your chosen backend (e.g., pip install transformers torch for Hugging Face).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pymupdf4llm_tsr-0.2.0.tar.gz.
File metadata
- Download URL: pymupdf4llm_tsr-0.2.0.tar.gz
- Upload date:
- Size: 3.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3978a061676b583321941342b4b04e2e055fd2de5d47feb5cc63cc245a16c85a
|
|
| MD5 |
7ba2c43a192520bf7c79bc99b54f8784
|
|
| BLAKE2b-256 |
25750f241f7809bfe0ad21e0eab6ca39c6da5597ac0de8a6a038cf3761326967
|
File details
Details for the file pymupdf4llm_tsr-0.2.0-py3-none-any.whl.
File metadata
- Download URL: pymupdf4llm_tsr-0.2.0-py3-none-any.whl
- Upload date:
- Size: 77.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71cf17223fded29c03c28f82f8cf51e38788b0555f0e8078300797131cee5284
|
|
| MD5 |
4aa385e727eb6b341d0356d0e52780e8
|
|
| BLAKE2b-256 |
531e780f01b811780621fb86be3bbf8d22e9552cb9ad2e1a36e570a9e2b4dd94
|