Skip to main content

gpt_pdf_md

gpt_pdf_md is a Python package that leverages GPT-4V and other tools to convert PDF files into Markdown. The current limitation of raw GPT-4V is that it does not support PDF documents in the API. Additionally, when prompted to convert text containing figures to Markdown, the figures are not converted correctly due to missing image URLs in the Markdown. However, gpt_pdf_md is coming close to the OCR quality of Mathpix!

Features

  • Extracts figures from PDF files using the pdffigures2 Scala library.
  • Converts PDF pages to images and uploads them to a Google Cloud Bucket.
  • Utilizes GPT-4V Vision to generate Markdown content from a PDF and then inserts image URLs into the Markdown.

Additional Dependencies

This package requires the pdffigures2 Scala library to extract figures from PDF files. You need to have all necessary dependencies installed for the library. You can find more information here. Please note that this can be quite a hassle because parts of the library are written in Scala, so you need to have the correct versions of Java and Scala installed. We are looking for an alternative, more straightforward way to extract images from a PDF. If you have any ideas, feel free to open an issue.

Installation

Once you have pdffigures2 set up, you can install gpt_pdf_md via pip:

pip install gpt-pdf-md

Configure the required environment variables in your .env file without spaces or unnecessary quotes:

OPENAI_API_KEY=open_ai_key
GOOGLE_ID=google_project_id
GOOGLE_BUCKET=google_bucket_name

NOTE: This project requires a public Google bucket where the images, which are later rendered in the Markdown, are uploaded.

Usage

To process a PDF and generate Markdown content, it's important that the Python file is in the same directory as the pdffigures2 folder. You can use gpt_pdf_md as follows:

from gpt_pdf_md.reader import process_pdf
import os
from dotenv import load_dotenv

load_dotenv()

OPENAI_API_KEY = os.getenv('OPENAI_API_KEY')
GOOGLE_ID = os.getenv('GOOGLE_ID')
GOOGLE_BUCKET = os.getenv('GOOGLE_BUCKET')

absolute_path = os.path.dirname(os.path.abspath(__file__))
# Absolute path to the PDF file
PDF = absolute_path + "/example.pdf"
# Absolute path to pdffigures2
PDFFIGURES2_PATH = absolute_path + "/pdffigures2/"
process_pdf(PDF, PDFFIGURES2_PATH, OPENAI_API_KEY, GOOGLE_ID, GOOGLE_BUCKET)

This will process the specified PDF and output a Markdown file with the extracted information in the same directory. An example is the output.md file, which is the converted result of example.pdf created by running the example.py script.

Next Steps

  • Try Rust vortex for PDF image extraction
  • Use GPT-4 128k for final formatting of Markdown
  • Create a clearer README to make it easier for everyone to use the Python package
  • Improve error handling

Contributing & Support

We welcome contributions! Please open an issue or submit a pull request on our GitHub repository.

License

This project is licensed under the terms of the MIT License.

Metadata

Release files for gpt-pdf-md 0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gpt-pdf-md 0.3
File Size Uploaded Provenance Actions
gpt_pdf_md-0.3.tar.gz 6.1 kB Without provenance Details for gpt_pdf_md-0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gpt-pdf-md 0.3
File Interpreter ABI Platform Actions
gpt_pdf_md-0.3-py3-none-any.whl Python 3 none any Details for gpt_pdf_md-0.3-py3-none-any.whl

Total release size: 12.6 kB

Release files / gpt_pdf_md-0.3.tar.gz

Download URL gpt_pdf_md-0.3.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c6b9a76f523b1b9c7f33ac291ed27f73ea7bcbd535ba09888f47b1632bbe52aa
BLAKE2b-256 checksum
How to use checksums
04346314d83de7d83617d4c637d5d3cd6f5746a1caad35835abf23e8791e9a1d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / gpt_pdf_md-0.3-py3-none-any.whl

Download URL gpt_pdf_md-0.3-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d0d5bb42c341de1215fa94c292884d82c574d828dbcff47fa9bcdbffe19e3445
BLAKE2b-256 checksum
How to use checksums
8154447abdb1c81862a5897e9b14f2c22367951870ca88fc41fbb7ecd0a20054
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Security for gpt-pdf-md 0.3

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.

Release history Release notifications | RSS feed

This release

0.3 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page