2023-09-11 18:04:51 +00:00
# AnkiAI - Automated Anki Deck Creator
2023-09-07 11:26:28 +00:00
2023-09-11 18:04:51 +00:00
AnkiAI is a tool that leverages OCR (Optical Character Recognition) and GPT-3's powerful natural language processing capabilities to automatically generate Anki decks from images containing text.
2023-09-07 11:26:28 +00:00
2023-09-11 18:04:51 +00:00
### Overview
2023-09-07 11:26:28 +00:00
2023-09-11 18:04:51 +00:00
- AnkiAI is designed to streamline the process of creating Anki decks from images.
- The core idea is to use OCR to extract text from images and then use GPT-3 to transform this text into a structured Anki deck format.
- Users can make a POST request to a Flask server endpoint with their images to receive the Anki deck (.apkg file).
2023-09-07 11:26:28 +00:00
2023-09-11 18:04:51 +00:00
### Directory Structure
2023-09-07 11:26:28 +00:00
2023-09-11 18:04:51 +00:00
- `.vscode/` : Contains configuration for VSCode debugger for Flask applications.
- `ankiai.py` : The main script that drives the creation of Anki decks from images.
- `constants.py` : Contains constant variables used across the project.
- `deck_creation.py` : Contains logic for communicating with OpenAI's API and deck creation using genanki.
- `image_processing.py` : Processes images, converting them for OCR and then performing OCR to extract text.
- `logging_config.py` : Logging configuration for the entire project.
- `server.py` : Flask server that provides an API endpoint to upload images and get back an Anki deck.
2023-09-07 11:26:28 +00:00
2023-09-11 18:04:51 +00:00
### Requirements
To run AnkiAI, you'll need to have the following dependencies installed:
```
genanki==0.8.0
Pillow
openai
flask
```
You can install these via `pip` using the `requirements.txt` file:
```bash
pip install -r requirements.txt
```
### How to Run
1. **Environment Variables** : Make sure to set the `OPENAI_API_KEY` environment variable to your OpenAI API key.
2. **Run the Flask server** :
2023-09-07 11:26:28 +00:00
```bash
2023-09-11 18:04:51 +00:00
python server.py
2023-09-07 11:26:28 +00:00
```
2023-09-08 13:29:15 +00:00
2023-09-11 18:04:51 +00:00
This will start the Flask server. You can then make a POST request to `http://localhost:5000/deck-from-images` with your images to get an Anki deck.
2023-09-08 09:32:49 +00:00
2023-09-11 18:04:51 +00:00
3. **Run Directly** :
2023-09-07 11:26:28 +00:00
2023-09-11 18:04:51 +00:00
If you prefer not to use the Flask server, you can also run `ankiai.py` directly:
2023-09-07 11:26:28 +00:00
2023-09-11 18:04:51 +00:00
```bash
python ankiai.py < directory_path_containing_images >
```
2023-09-08 09:24:37 +00:00
2023-09-11 18:04:51 +00:00
### How to Debug (VSCode Users)
2023-09-08 08:30:05 +00:00
2023-09-11 18:04:51 +00:00
- Open the project in VSCode.
- Set up your breakpoints.
- Use the VSCode debugger and select "Python: Flask" to start debugging the Flask server.
2023-09-07 11:26:28 +00:00
2023-09-11 18:04:51 +00:00
### Important Notes
2023-09-07 11:26:28 +00:00
2023-09-11 18:04:51 +00:00
- **API Key**: For the project to work, it is essential to have the `OPENAI_API_KEY` environment variable set.
- **Image Types**: Currently, the image processing module supports PNG, JPG, and JPEG formats.
- **Output**: The output `.apkg` file (Anki package file) will be named `out.apkg` .
2023-09-07 11:26:28 +00:00
2023-09-11 18:04:51 +00:00
### Acknowledgements
2023-09-07 11:26:28 +00:00
2023-09-11 18:04:51 +00:00
This project heavily relies on the `openai` library for processing and the `genanki` library for deck generation.
2023-09-07 11:26:28 +00:00
2023-09-11 18:04:51 +00:00
### Contributions
2023-09-07 11:26:28 +00:00
2023-09-11 18:04:51 +00:00
Contributions are always welcome. Please create a new issue or a pull request for any bug fixes or feature requests.