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)
extract-pdf keys add gemini "your-gemini-api-key"

# Extract text from PDF
extract-pdf 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
extract-pdf keys add gemini "your-gemini-api-key"
extract-pdf keys add openai "your-openai-api-key"

# List stored keys (shows partial keys for security)
extract-pdf keys list

# Delete a stored key
extract-pdf keys delete gemini

Command Line Usage

Basic Usage

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

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

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

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

Full Command Reference

# Show help
extract-pdf --help

# Show help for extract command
extract-pdf extract --help

# Show help for key management
extract-pdf 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.1.tar.gz (7.7 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.1-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pdfgenius-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2613e06de3f07d34220d3907a93248ceb5bcd07079f1f8122a5c1bd7eedeeef8
MD5 d555d8094e3d25486967219e52690268
BLAKE2b-256 32a2523f20d01fb766776862a1e740d0a1bab147b01e5f1f2f1f2a1644a75a36

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pdfgenius-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d4e42fdf30bf6e098e776cc3916f223567c6543e71e8d1f8b5efa1787f72bcc5
MD5 55660f3ad5cb008e6eb14ddc4b6a36ba
BLAKE2b-256 a487b11184b1b511736330fdf67e65c8ca26790809d6c4da5839c2206d45912e

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