From 91350f3ca35b2f9a7d18fabdac6f470946547c9e Mon Sep 17 00:00:00 2001 From: Benjamin Dweck Date: Fri, 8 Sep 2023 12:37:24 +0300 Subject: [PATCH] Created a pipeline --- README.md | 10 ++++++++++ pipeline.py | 27 +++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 pipeline.py diff --git a/README.md b/README.md index 2499704..66652ae 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,16 @@ Remember to replace `your_openai_api_key_here` with your actual OpenAI API key. ## Usage +### Pipeline Usage + +To convert a directory of images directly to an Anki deck package: + +```bash +python pipeline.py /path/to/your/image_directory/ +``` + +This will process the images, extract text, convert text to a set of questions and answers in CSV format, and then produce an `output.apkg` file ready for import into Anki. + ### Image to Text Conversion To convert images from a directory to a single text file using OCR: diff --git a/pipeline.py b/pipeline.py new file mode 100644 index 0000000..79139f2 --- /dev/null +++ b/pipeline.py @@ -0,0 +1,27 @@ +import sys +import os + +from images2text import main as images_to_text +from text2csvdeck import create_csv_deck + +CSV_DECK_NAME = "output_deck.csv" +APKG_NAME = "output.apkg" + + +def pipeline(directory_path): + # 1. Convert images in the directory to a text file + text_file_name = images_to_text(directory_path) + + # 2. Convert the text file to a CSV deck using ChatGPT + create_csv_deck(text_file_name) + + # 3. Convert the CSV deck to an Anki package + os.system(f"python csv2ankicards.py {CSV_DECK_NAME} {APKG_NAME}") + + +if __name__ == "__main__": + if len(sys.argv) != 2: + print("Usage: python pipeline.py ") + sys.exit(1) + + pipeline(sys.argv[1])