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.0.tar.gz (7.8 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.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pdfgenius-0.1.0.tar.gz
  • Upload date:
  • Size: 7.8 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.0.tar.gz
Algorithm Hash digest
SHA256 ac56c7dbff710ff205956e04125e72120d24b20e334830a6feba0ccb842e9b29
MD5 e150ae699016d2057bb54eb71ecc47b1
BLAKE2b-256 ddd4ccecfa403ee1b2df271c1df8f01424fd5752c1c4329ea47751e35308cdec

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pdfgenius-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5dd40bd316df19968bd415c2c4851704b694eba6a1899ea0d90ca207f2f7f58d
MD5 254f02e52af08e4a1e705dcb17f8945d
BLAKE2b-256 b09968a019e93e71aae49a259a16619cc8a9ee00f0b49a35d8c45b9524afd4b7

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