revised README.md

This commit is contained in:
B.J. Dweck 2023-09-11 21:04:51 +03:00
parent 28e6c8d611
commit e96f23ddc8
2 changed files with 60 additions and 51 deletions

View File

@ -1,67 +1,76 @@
# AnkiAI # AnkiAI - Automated Anki Deck Creator
AnkiAI is a robust system that converts images containing text into structured Anki cards using Optical Character Recognition (OCR) and OpenAI's GPT-4 language model. Users can quickly generate decks of flashcards from their images for effective study. 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.
## Features ### Overview
- Converts image content to textual content using OCR.
- Uses OpenAI's GPT-4 model to structure the content into Anki decks and cards.
- Outputs the structured content as an Anki package.
## Dependencies - AnkiAI is designed to streamline the process of creating Anki decks from images.
- genanki: Used for creating Anki decks and cards. - 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.
- Pillow: Image processing library. - Users can make a POST request to a Flask server endpoint with their images to receive the Anki deck (.apkg file).
- openai: API library for OpenAI's GPT-4 model.
- flask: Web server to host the service.
## Setup and Installation ### Directory Structure
1. Clone this repository: - `.vscode/`: Contains configuration for VSCode debugger for Flask applications.
```bash - `ankiai.py`: The main script that drives the creation of Anki decks from images.
git clone https://git.rudefox.io/bj/anki-json2ankicards.git - `constants.py`: Contains constant variables used across the project.
cd json2ankicards - `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.
2. Set up a virtual environment and activate it: ### Requirements
```bash
python3 -m venv venv
source venv/bin/activate
```
3. Install the required packages: To run AnkiAI, you'll need to have the following dependencies installed:
```bash
pip install -r requirements.txt
```
4. Set up the OpenAI API key: ```
```bash genanki==0.8.0
export OPENAI_API_KEY=your_openai_api_key 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**:
5. Run the server:
```bash ```bash
python server.py python server.py
``` ```
## Usage 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.
1. Start the server as mentioned above. 3. **Run Directly**:
2. Use a tool like [Postman](https://www.postman.com/) or `curl` to send images to `http://localhost:5000/deck-from-images` as a multi-part POST request. If you prefer not to use the Flask server, you can also run `ankiai.py` directly:
3. The server will respond with a downloadable Anki package. Import this into your Anki app and start studying! ```bash
python ankiai.py <directory_path_containing_images>
```
## Modules ### How to Debug (VSCode Users)
1. **ankiai.py**: The main module that orchestrates the flow. - Open the project in VSCode.
2. **images2text.py**: Converts image content into text using OCR. - Set up your breakpoints.
3. **json2deck.py**: Converts structured JSON data into an Anki package. - Use the VSCode debugger and select "Python: Flask" to start debugging the Flask server.
4. **prompt4cards.py**: Uses OpenAI to structure the content into Anki decks and cards.
5. **server.py**: Flask server to host the service.
## Contributing ### Important Notes
Contributions are welcome! Please submit a pull request or open an issue to discuss changes or fixes. - **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`.
## License ### Acknowledgements
[MIT License](LICENSE) This project heavily relies on the `openai` library for processing and the `genanki` library for deck generation.
### Contributions
Contributions are always welcome. Please create a new issue or a pull request for any bug fixes or feature requests.

View File

@ -3,16 +3,16 @@ import tempfile
import shutil import shutil
import logging import logging
from logging_config import setup_logging
from flask import Flask, request, send_from_directory, jsonify from flask import Flask, request, send_from_directory, jsonify
from werkzeug.utils import secure_filename from werkzeug.utils import secure_filename
from ankiai import images_to_package from ankiai import images_to_package
from constants import IMAGE_KEY, APKG_FILE, NO_IMAGE_PART_ERROR, NO_SELECTED_FILE_ERROR, INVALID_FILENAME_ERROR from constants import IMAGE_KEY, APKG_FILE, NO_IMAGE_PART_ERROR, NO_SELECTED_FILE_ERROR, INVALID_FILENAME_ERROR
from logging_config import setup_logging
setup_logging() setup_logging()
from logging_config import setup_logging
app = Flask(__name__) app = Flask(__name__)
def save_uploaded_images(images, directory): def save_uploaded_images(images, directory):