README for docin OCR Tool
Overview
docin is a lightweight document processing toolkit that combines OCR (Optical Character Recognition) and intelligent document analysis. It features two main components:
-
OCR Engine: Powered by the Mistral API, it extracts text and images from PDF and image files, converting them into clean, structured Markdown format.
-
LangQuery: An intelligent document analysis tool that uses LangChain and spaCy to extract structured information through natural language queries and visualize named entities.
Features
OCR Capabilities
- Automatically detects PDF or image input
- Performs OCR using the Mistral API
- Exports results as Markdown (.md)
- Optionally includes extracted images
- Displays real-time progress for multi-page documents
- Prevents accidental overwriting of output files
Document Analysis
- Extract structured information using natural language queries
- Visualize named entities with interactive highlighting
- Customize prompts and examples for specific use cases
- Return results in JSON format for easy processing
Requirements
- Python 3.8+
- A valid Mistral API key
- A LangChain-compatible language model (for document analysis)
- spaCy with 'en_core_web_sm' model (auto-installed)
Installation
pip install docin
The spaCy model 'en_core_web_sm' will be automatically downloaded during installation.
Usage
OCR Processing
from ocr import MistOcr
# Initialize with your Mistral API key
ocr = MistOcr(api_key='your_mistral_api_key')
# Run OCR on a PDF or image file
ocr.doc_to_md(
filename='path/to/document.pdf',
output_filename='output/result.md',
include_image=False, # Include embedded or saved images (optional)
return_response=False # Return OCR response (optional)
)
Document Analysis with LangQuery
from ocr.query import LangQuery
# Initialize with your LangChain model
query = LangQuery(llm=your_llm)
# Load and analyze a document
query.load_document("Your document text here")
# Extract information using natural language
response = query.query_document("Find all company names and locations")
# Visualize results (in Jupyter/IPython)
query.render(response)
You can customize the analysis by setting different examples:
# Set custom examples for specific entity types
query.set_examples("""
{
'companies': ['Example Corp', 'Tech Inc'],
'dates': ['2023-01-01'],
'locations': ['New York']
}
""")
Output
OCR Output
- Saves extracted text in a Markdown (.md) file
- Creates an
images/folder in the same directory for any extracted images - Displays progress during export
- Returns an OCR response object when
return_response=True
LangQuery Output
- Returns structured JSON with extracted entities
- Provides interactive entity highlighting in Jupyter/IPython
- Supports customizable response formats through examples
Supported File Types
- PDF (.pdf)
- Image formats: .jpg, .jpeg, .png, .bmp, .tiff
- LangQuery works with any text content
Error Handling
- Raises
ValueErrorfor unsupported file types - Prompts before overwriting existing files
- Logs warnings for missing or invalid image data
- Validates document loading for LangQuery
- Ensures proper model initialization
Notes
- For OCR: Use high-resolution images (≥300 DPI) for best accuracy
- Supports multi-page PDFs and large documents
- Extracted images are saved with unique IDs in the
images/directory - LangQuery works best with well-structured text content
- Entity visualization requires Jupyter/IPython environment
Example Output
OCR Output
Markdown file:
# Page 1
Extracted text...
# Page 2
More extracted text...
Images folder:
images/
├── image_1.png
├── image_2.jpg
LangQuery Output
JSON Response:
{
"companies": ["Acme Corp", "TechStart Inc"],
"locations": ["New York", "San Francisco"],
"dates": ["2023-01-15"]
}
Visual Output:
- Interactive highlighting of found entities in the document text
- Color-coded entity types for easy identification
Author
Ime Inyang
License
MIT
Version
0.1.2
Metadata
Release files for docin 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| docin-0.1.2.tar.gz | 9.3 kB | Without provenance | Details for docin-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| docin-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for docin-0.1.2-py3-none-any.whl |
Total release size: 19.6 kB
Release files / docin-0.1.2.tar.gz
| Download URL | docin-0.1.2.tar.gz |
|---|---|
| Size | 9.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5dc215701cf304c9dd08c4d3c24b9be595521a61ff21b9e9131b67c72f85f512
|
|
BLAKE2b-256 checksum How to use checksums |
e7854160100218760200bf735512f87e7b759244620d0367b80ae4943d942d17
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.5
|
Release files / docin-0.1.2-py3-none-any.whl
| Download URL | docin-0.1.2-py3-none-any.whl |
|---|---|
| Size | 10.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2982a0502e69a6241cdf579b9c6eca5776dcbba78fc2dd041c8cff92eaa30369
|
|
BLAKE2b-256 checksum How to use checksums |
7f0cae7ff449daad0bd373736d4faabbda2616696a725a3c228718211e9bd797
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.5
|
Security for docin 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.