Compare commits

..
4 Commits
Author SHA1 Message Date
bj 9d33c2ee10 Pinned python package versions 2023-09-21 15:21:17 +03:00
bj aa17dcc48a Updated README.md to include ImageMagick 2023-09-21 15:14:38 +03:00
bj 6c1ece44ab Updated README.md with curl command and tesseract dependency 2023-09-21 15:02:06 +03:00
bj 3f3cc276f2 revised prompt to generate more cards 2023-09-21 14:52:06 +03:00
3 changed files with 58 additions and 20 deletions
+46 -8
View File
@@ -20,16 +20,27 @@ AnkiAI is a tool that leverages OCR (Optical Character Recognition) and GPT-3's
### Requirements
To run AnkiAI, you'll need to have the following dependencies installed:
#### ImageMagick
```
genanki==0.8.0
Pillow
openai
flask
ImageMagick is a software suite that allows you to create, edit, and compose bitmap images. It can read, convert, and write images in a variety of formats (over 100) including DPX, EXR, GIF, JPEG, JPEG-2000, PDF, PhotoCD, PNG, Postscript, SVG, and TIFF. In the AnkiAI project, it is used for preprocessing images to improve the performance of OCR.
```bash
sudo apt-get update
sudo apt-get install imagemagick
```
You can install these via `pip` using the `requirements.txt` file:
#### Tesseract
You need Tesseract for the OCR functionality:
```bash
sudo apt-get install tesseract-ocr
```
### Python Dependencies
To ensure consistent functionality, it's crucial to use the provided `requirements.txt` file which pins dependencies to known compatible versions.
You can install the Python dependencies via `pip` using the `requirements.txt` file:
```bash
pip install -r requirements.txt
@@ -38,7 +49,11 @@ 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.
```bash
export OPENAI_API_KEY=sk-myapikey
```
2. **Run the Flask server**:
```bash
@@ -55,6 +70,29 @@ pip install -r requirements.txt
python ankiai.py <directory_path_containing_images>
```
### Example curl commands to interact with the service:
You can make POST requests to the server using curl. Here are some examples from the command line history:
```bash
curl -X POST -o deck.apkg \
-F "image=@/home/ubuntu/Pictures/image1.png" \
-F "image=@/home/ubuntu/Pictures/image2.png" \
-F "image=@/home/ubuntu/Pictures/image3.png" \
http://localhost:5000/deck-from-images
```
Batch processing of images:
```bash
for file in /home/ubuntu/Pictures/*; do
if [[ -f "$file" ]]; then
basefile=$(basename "$file");
curl -X POST -o "deck-${basefile}.apkg" -F "image=@${file}" http://localhost:5000/deck-from-images;
fi;
done
```
### How to Debug (VSCode Users)
- Open the project in VSCode.
+9 -9
View File
@@ -16,17 +16,17 @@ if not API_KEY:
openai.api_key = API_KEY
PROMPT_TEMPLATE = """
Please craft a title for the deck along with a set of index cards that succinctly capture the main ideas and themes of the provided text. Ensure the following:
Please craft a title for the deck and generate a comprehensive set of index cards based on the provided text. Follow these guidelines:
1. Every card should have a title, a question on the front, and an answer on the back.
2. Each answer must contain at least one concrete fact not evident from its question.
3. Include any numbers, data, or details that may be challenging to remember.
4. The aim is for a person who learns this set to effectively convey the text's main themes and specifics to another individual.
5. You should craft at least one index card for every 3-5 sentences of content, depending on how much information is packed in the content.
6. Each index card should focus on answering a single question
7. Each index card answer shall be no longer than 3 sentences.
2. Each answer must contain at least one concrete fact that is not evident from its corresponding question.
3. Ensure inclusion of numbers, data, or intricate details that would be challenging for individuals to remember.
4. The goal is to enable someone who learns this set to competently convey both the overarching themes and intricate details of the text to another person.
5. Create one index card for every 2-4 sentences of the content. The exact number depends on the density of the information. Aim for completeness over brevity.
6. Each index card should home in on answering a distinct question.
7. Limit each index card answer to no more than three sentences for brevity and clarity.
Structure your response as:
Structure your output as:
```
Deck Title: [Title of the Deck]
Cards:
@@ -36,7 +36,7 @@ Cards:
- Title: [Card Title 2]
Front: [Question 2]
Back: [Answer 2]
... and so on
... continue in this pattern
```
Content for reference:
+3 -3
View File
@@ -1,4 +1,4 @@
genanki==0.8.0
Pillow
openai
flask
Pillow==10.0.1
openai==0.28.0
Flask==2.3.3