Skip to main content

A Python package to create Anki cards from PDFs using OpenAI.

Project description

pdf2anki

pdf2anki is a Python application that enables you to generate Anki flashcards questions from PDF files utilizing the power of OpenAI ChatGPT.

Prerequisites

  • Python 3.6 or higher
  • Access to OpenAI API (ensure to set your API key as an environment variable named 'OPENAI_API_KEY')

Installation

You can install pdf2anki from PyPI:

pip install pdf2anki

Usage

Once installed, you can use the pdf2anki command to generate Anki cards from a directory of PDFs. The following arguments are needed:

pdf2anki --source-dir SOURCE_DIR --output-dir OUTPUT_DIR --model MODEL --temperature TEMPERATURE --max-tokens MAX_TOKENS

For example:

pdf2anki --source-dir ./pdfs --output-dir ./anki-cards --model gpt-4 --temperature 0.5 --max-tokens 1000

For Developers

Developers can also use pdf2anki in their Python scripts as follows:

import os
from pdf2anki.main import read_pdf, create_anki_cards

#### Define the source PDF folder and the output folder for the Anki cards
source_dir = "path/to/pdf_folder"
output_dir = "path/to/output_folder"

#### Define the parameters for the OpenAI model
model = "gpt-4"
temperature = 0.5
max_tokens = 1000

#### Iterate over the PDF files in the source directory
for file_name in os.listdir(source_dir):
    if file_name.endswith(".pdf"):
        # Get the full path to the source PDF
        source_pdf = os.path.join(source_dir, file_name)

        # Read the PDF text
        pdf_text = read_pdf(source_pdf)

        # Create output file path
        output_file = os.path.join(output_dir, file_name.rsplit(".", 1)[0] + ".txt")

        # Create Anki cards from the PDF text
        create_anki_cards(pdf_text, output_file, model, temperature, max_tokens)

License

This project is licensed under the terms of the MIT license. For more details, see the LICENSE file.

References

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

pdf2anki-0.1.2.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

pdf2anki-0.1.2-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pdf2anki-0.1.2.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for pdf2anki-0.1.2.tar.gz
Algorithm Hash digest
SHA256 0f80fc3724c66a94e8e93a4026f5b3f54fb67420624fad6716a1a6d086bb0c1f
MD5 5c924b0e3b22c8f0e920ff32c73378da
BLAKE2b-256 8c1d34eb3f8fa3512a716c22e13faafaeebbb4a30845262c1c1d82142698c355

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pdf2anki-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for pdf2anki-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f1133d01ae1cb93c558308d39daf2740aa58be3bf8c734878fd3826c55af5197
MD5 b8f76f0ee36dfb9546f2b7ccad66d028
BLAKE2b-256 4e65a8d1d7980725cedec11be1f1d603fb01a17f30fcf7462223fa116c78a005

See more details on using hashes here.

Supported by

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