Skip to main content

A Python package to extract text from images and PDFs using Vision Language Model (VLM).

Project description

Vlense

A Python package to extract text from images and PDFs using Vision Language Models (VLM).

Features

  • Extract text from images and PDFs
  • Supports JSON, HTML, and Markdown formats
  • Easy integration with Vision Language Models
  • Asynchronous processing with batch support
  • Custom JSON schema for structured output

Installation

pip install vlense

Usage

import os
import asyncio
from vlense import Vlense
from pydantic import BaseModel

path = ["./images/image1.jpg", "test.pdf"]
output_dir = "./output"
model = "gemini/gemini-1.5-flash"
temp_dir = "./temp_images"
os.environ["GEMINI_API_KEY"] = "YOUR_API_KEY"


async def main():
    vlense = Vlense()
    responses = await vlense.ocr(
        file_path=path,
        model=model,
        output_dir=output_dir,
        temp_dir=temp_dir,
        batch_size=3,
        clean_temp_files=False,
    )

if __name__ == "__main__":
    asyncio.run(main())

API

Vlense.ocr()

Performs OCR on the provided files.

Parameters:

  • file_path : (Union[str, List[str]]): Path or list of paths to PDF/image files.

  • model : (str, optional): Model name for generating completions. Defaults to "gemini-1.5-flash".

  • output_dir : (Optional[str], optional): Directory to save output. Defaults to None.

  • temp_dir : (Optional[str], optional): Directory for temporary files. Defaults to system temp.

  • batch_size : (int, optional): Number of concurrent processes. Defaults to 3.

  • format : (str, optional): Output format ('markdown', 'html', 'json'). Defaults to 'markdown'.

  • json_schema : (Optional[Type[BaseModel]], optional): Pydantic model for JSON output. Required if format is 'json'.

  • clean_temp_files : (Optional[bool], optional): Cleanup temporary files after processing. Defaults to True.

Returns:

  • Dict[str, VlenseResponse] : Generated content.

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contact

Author: Aditya Miskin
Email: adityamiskin98@gmail.com
Repository: https://github.com/adityamiskin/vlense

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vlense-0.1.1.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vlense-0.1.1-py3-none-any.whl (2.8 kB view details)

Uploaded Python 3

File details

Details for the file vlense-0.1.1.tar.gz.

File metadata

  • Download URL: vlense-0.1.1.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.15

File hashes

Hashes for vlense-0.1.1.tar.gz
Algorithm Hash digest
SHA256 dfbe5e2cf5341e38c792f5fbbe5c04b9ed32e6050344869b43064bf68d0e558c
MD5 13130b000672252dc1510b818b5bc7ea
BLAKE2b-256 b0bc3076cdd8e002e410a592d78deec3538d86bee833ee1bc5665a9a52505fcb

See more details on using hashes here.

File details

Details for the file vlense-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: vlense-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 2.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.15

File hashes

Hashes for vlense-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6d9468f0cbe72c9a55cda90f1ed1063da2de1324ed24fd09b8165bed788059c1
MD5 fd928361868fe6e19dee3cb111eb6256
BLAKE2b-256 a65ef5a842bb2dda85afaa063fc7978e63878387a4d7fd1a6280afa5c331bad7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page