Turn your Japanese study sheets into Anki decks β no retyping required.
KanGen converts images of kanji study material into structured, import-ready Anki flashcards. Upload a worksheet, textbook page, or handwritten study table, and KanGen extracts the kanji, validates the readings, and generates a .apkg deck automatically.
Built with multimodal AI, dictionary-backed validation, and a production-ready API, KanGen eliminates the tedious process of manually creating flashcards from study resources.
- πΈ Extract kanji directly from study sheets and textbook pages
- ποΈ Multimodal page understanding using Gemini 2.5 Flash
- π‘οΈ Reading validation with SudachiPy to reduce hallucinations
- π Automatic Anki deck generation (
.apkg) - β‘ Command-line interface for local use
- π FastAPI backend for web integrations
- βοΈ AWS S3 integration with presigned download URLs
- π Built-in retry and backoff handling for API rate limits
- π§Ή Automatic cleanup of temporary files
You already have the study material.
The difficult part is turning it into flashcards.
Before KanGen
πΈ Study Sheet
β
π© Manually type dozens of entries
β
π Flashcards
After KanGen
πΈ Study Sheet
β
β‘ One Command
β
π Flashcards
Instead of spending time copying kanji, readings, and meanings into Anki, KanGen performs the entire workflow automatically.
πΈ Study Image
β
π² Image Preprocessing
β
ποΈ Gemini 2.5 Flash
β
π Structured JSON Extraction
β
π‘οΈ SudachiPy Validation
β
π genanki Deck Generation
β
π¦ .apkg Output
β
βοΈ S3 Upload (API Mode)
Input images are normalized before extraction.
Supported formats include:
- JPG
- PNG
- HEIC
Images are converted when necessary and prepared for visual analysis.
KanGen uses Gemini 2.5 Flash to understand the structure of Japanese study material.
Unlike traditional OCR systems, the model can distinguish between:
- Actual study content
- Stroke-order diagrams
- Practice boxes
- Decorative annotations
- Layout elements
The output is structured JSON rather than raw text.
Multimodal models are powerful but not infallible.
To reduce incorrect readings, KanGen validates extracted readings against SudachiPy.
This creates a hybrid workflow:
AI Extraction
+
Dictionary Validation
=
Reliable Flashcards
Validated entries are converted into Anki flashcards using genanki.
Generated decks are compatible with:
- Anki Desktop
- AnkiDroid
- AnkiMobile
- AnkiWeb
| Layer | Technology |
|---|---|
| Vision Engine | Gemini 2.5 Flash |
| Validation | SudachiPy |
| CLI | Click |
| REST API | FastAPI + Uvicorn |
| Cloud Storage | AWS S3 (Boto3) |
| Flashcard Generation | genanki |
| Data Models | Pydantic |
- Python 3.10+
- Google Gemini API Key
git clone https://github.com/your-username/KanGen.git
cd KanGenpython -m venv .venv
# Linux / macOS
source .venv/bin/activate
# Windows
.venv\Scripts\activatepip install -r requirements.txtCreate a .env file:
GEMINI_API_KEY=your_api_key
# Required only for API mode
S3_BUCKET=your_bucket_name
AWS_ACCESS_KEY_ID=your_access_key
AWS_SECRET_ACCESS_KEY=your_secret_keyGenerate a deck directly from one or more images.
python src/main.py study_sheet.jpgSpecify an output path:
python src/main.py study_sheet.jpg \
--output my_kanji_deck.apkgUsage: main.py [OPTIONS] [INPUT_PATHS]...
Options:
-o, --output TEXT
Output deck path
--api-key TEXT
Gemini API key
--help
Show help message
Start the FastAPI server:
uvicorn src.api:app --reloadInteractive API documentation:
http://localhost:8000/docs
POST /v1/processUpload an image and receive a job identifier.
Response:
{
"job_id": "abc123"
}GET /v1/jobs/{job_id}Response:
{
"status": "completed",
"download_url": "..."
}A presigned S3 URL is returned when deck generation completes.
| Field | Value |
|---|---|
| Kanji | δ½ |
| Meaning | To live; reside |
| On-yomi | γΈγ₯γ¦ |
| Kun-yomi | γ(γ) |
| Example Sentence | γγγ«δ½γγ§γγΎγγ |
- Kanji study tables
- Textbook pages
- Worksheets
- Vocabulary sheets
- Annotated study notes
- Newspapers
- Novels
- Manga
- Long-form running text
- General document OCR
KanGen is optimized specifically for educational study material.
Handles temporary failures such as:
- HTTP 429 (Rate Limits)
- HTTP 503 (Service Unavailable)
with exponential backoff.
Long-running generation tasks execute in worker threads, keeping the API responsive.
Temporary images and generated decks are automatically removed after processing.
KanGen generates standard .apkg files.
| Platform | Application |
|---|---|
| Windows | Anki Desktop |
| macOS | Anki Desktop |
| Linux | Anki Desktop |
| Android | AnkiDroid |
| iOS | AnkiMobile |
| Browser | AnkiWeb |
Import through:
File β Import β Select .apkg
- Gemini 2.5 Flash extraction
- Structured JSON output
- On-yomi / Kun-yomi separation
- SudachiPy validation
- genanki integration
- FastAPI backend
- AWS S3 delivery
- Retry handling
- Automatic cleanup
- Next.js web interface
- Redis job queue
- Persistent image caching
- Multiple example sentences
- Batch deck generation
- User authentication
- Deck customization options
Each request is independent and self-contained.
All outputs are validated through typed models before deck generation.
Temporary resources are cleaned aggressively and external API failures are handled gracefully.
KanGen works because it understands not only what to extract, but also what to ignore.