Skip to content

abdolrezat/anki-ai-swedish

Repository files navigation

Automated Anki Flashcards Generator for 🇸🇪 Swedish Vocabulary

This project automates the creation of Anki cards for Swedish words using freely available tools:


🔧 Setup Instructions

1. Clone the Repository

git clone https://gitlab.com/rezaT/anki-ai-swedish.git
cd anki-ai-swedish

2. Install Python Dependencies

pip install huggingface_hub requests wget

3. Hugging Face Setup

a. Install the Hugging Face CLI

pip install huggingface_hub

b. Login to Hugging Face

huggingface-cli login

This will prompt you to paste your Hugging Face token. You can create one for free here (select "Read" access when creating the token, huggingface-cli command will save the token to ~/.cache/huggingface/token).


4. AnkiConnect Plugin Setup

a. Install Anki

Download and install Anki if you haven't already, from https://apps.ankiweb.net/.

b. Install the AnkiConnect Plugin

  1. Open Anki.
  2. Go to ToolsAdd-onsGet Add-ons.
  3. Paste the following code: 2055492159
  4. Click "OK" and restart Anki.

c. Test the AnkiConnect Server

Ensure Anki is running, then test the connection:

curl localhost:8765

Example output:

{"apiVersion": "AnkiConnect v.6"}

d. Create Custom Card Type

We use a customized card, run the setup script to add it to Anki:

python setup_anki_card_type.py

The custom card has:

  • Fields: Front, Back, Extra (toggles to show sentences, context, etc.), Audio, Video

5. Running the Pipeline

Important: Anki needs to be running for the card to be added.

The workflow is:

  1. Input a Swedish word.
  2. Fetch JSON response from the KTH Lexin API.
  3. Strip/clean relevant content (definitions, examples, grammar).
  4. Use DeepSeek V3 via Hugging Face Inference API to summarize the content into a formatted Anki card.
  5. Send the card to Anki via AnkiConnect.

Run the script:

python main.py <swedish_word>

6. Create a Symlink for Easy Access

To make the script accessible from anywhere, create a symbolic link under /usr/bin:

sudo ln -s <path_to_main.py> /usr/bin/anki-add && sudo chmod +x /usr/bin/anki-add

Running the code:

Now you can run the script using:

anki-add <swedish_word> <extra context>

Extra context is optional, it can be e.g. a sentence to include in the flashcard.

🔍 Example Usage

anki-add programmerare

Output:

<Front>programmer</Front>
<Back>programmerare</Back>
<Extra>
(en programmerare, programmeraren, programmerare, programmerarna)
Person som programmerar
<i>He works as a programmer at a tech company.</i>
Han jobbar som programmerare på ett teknikföretag.
</Extra>

Other Usage Modes

The script supports three modes depending on the input:

  1. Word only: anki-add <word>
    Creates a flashcard from the Lexin dictionary definition.

  2. Word + context: anki-add <word> "<sentence or context>"
    Creates a flashcard from Lexin and includes your provided sentence/context.

  3. Context only: anki-add "" "<sentence or context>"
    Creates a flashcard directly from your sentence without dictionary lookup.


📝 License

This project is licensed under the LGPL 3 License. Please observe the license for the acknowledged sources:


About

Automated Anki Flashcards Generator for 🇸🇪 Swedish Vocabulary

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages