Skip to main content

No project description provided

Project description

PDF GENIUS

PDF GENUIS is a powerful Python package that converts PDF documents into text using AI-powered optical character recognition (OCR). It currently supports both Google's Gemini and OpenAI's GPT-4 Vision models for text extraction, with an extensible architecture that makes it easy to add support for additional AI models.

Features

  • Extract text from PDF documents using state-of-the-art AI models
  • Support for multiple AI providers (Gemini and OpenAI)
  • Secure local storage of API keys
  • Command-line interface (CLI) for easy use
  • Extensible architecture for adding new AI models
  • Automatic handling of multi-page PDFs
  • Clean temporary file management

Installation

You can install the package using pip:

pip install pdfgenius

The package requires Python 3.7 or later.

System Dependencies

This package requires Poppler for PDF processing. Install it based on your operating system:

  • Linux (Ubuntu/Debian):

    sudo apt-get install poppler-utils
    
  • macOS:

    brew install poppler
    
  • Windows: Download and install poppler from poppler releases, then add the bin directory to your system PATH.

Quick Start

Extract text from a PDF using the default Gemini model:

# Store your API key (one-time setup)
pdfgenius keys add gemini "your-gemini-api-key"

# Extract text from PDF
pdfgenius extract document.pdf

API Key Management

The package provides secure local storage for your API keys. You can manage them using these commands:

# Add an API key
pdfgenius keys add gemini "your-gemini-api-key"
pdfgenius keys add openai "your-openai-api-key"

# List stored keys (shows partial keys for security)
pdfgenius keys list

# Delete a stored key
pdfgenius keys delete gemini

Command Line Usage

Basic Usage

# Extract using default settings (Gemini model)
pdfgenius extract document.pdf

# Specify output file
pdfgenius extract document.pdf -o output.txt

# Use OpenAI model
pdfgenius extract document.pdf -m openai

# Provide API key directly (without storing)
pdfgenius extract document.pdf -m openai --api-key "your-api-key"

Full Command Reference

# Show help
pdfgenius --help

# Show help for extract command
pdfgenius extract --help

# Show help for key management
pdfgenius keys --help

Python API

You can also use the package programmatically in your Python code:

from pdf_extractor import GeminiExtractor, OpenAIExtractor
from pdf_extractor.utils import process_pdf

# Using Gemini
extractor = GeminiExtractor(api_key="your-api-key")
extractor.initialize_client()
text = process_pdf("document.pdf", extractor)

# Using OpenAI
extractor = OpenAIExtractor(api_key="your-api-key")
extractor.initialize_client()
text = process_pdf("document.pdf", extractor)

Adding Support for New AI Models

The package is designed to be easily extensible. To add support for a new AI model:

  1. Create a new extractor class that inherits from BaseExtractor
  2. Implement the required methods
  3. Register the new extractor in the CLI

Example:

from pdf_extractor.extractors.base import BaseExtractor

class NewModelExtractor(BaseExtractor):
    def initialize_client(self):
        # Initialize your AI client
        pass

    def extract_text_from_image(self, image_path: Path) -> str:
        # Implement text extraction logic
        pass

Security

  • API keys are stored encrypted in the user's home directory
  • The encryption key is stored separately
  • Only partial keys are displayed when listing stored keys
  • Keys can be easily deleted when no longer needed

Environment Variables

The package also supports providing API keys through environment variables:

export GEMINI_API_KEY="your-gemini-api-key"
export OPENAI_API_KEY="your-openai-api-key"

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

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

Acknowledgments

This package uses several open-source libraries:

  • pdf2image for PDF processing
  • google-generativeai for Gemini API
  • openai for OpenAI API
  • click for CLI interface
  • cryptography for secure key storage

Support

If you encounter any issues or have questions, please file an issue on the GitHub repository.

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

pdfgenius-0.1.2.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

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

pdfgenius-0.1.2-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file pdfgenius-0.1.2.tar.gz.

File metadata

  • Download URL: pdfgenius-0.1.2.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for pdfgenius-0.1.2.tar.gz
Algorithm Hash digest
SHA256 34281a874c8fcf41a6e612647c04dde34bda4b3182cd50a6d41ab871e28d9caa
MD5 2e05ed68a8325a0e779fd1ad3708bb42
BLAKE2b-256 367e51ee9d441837f18b44c9b1562ba9b11a71bd7ecefd3beed9052f572991d6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pdfgenius-0.1.2.tar.gz:

Publisher: python-publish.yml on TooSalty0000/pdfgenius

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pdfgenius-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: pdfgenius-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for pdfgenius-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fa3316599f7570d672b311c4156a546d200e2c33921ae6037bff2ff1551db238
MD5 c11fc6472576f34bd5e258e964ccb0f7
BLAKE2b-256 fde082aa479b28d761e535dac9d175a2fcd1744c457751b1860c48902cdcc7f4

See more details on using hashes here.

Provenance

The following attestation bundles were made for pdfgenius-0.1.2-py3-none-any.whl:

Publisher: python-publish.yml on TooSalty0000/pdfgenius

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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