bilingual_book_maker

repository·main·Indexed 27 days ago

https://github.com/yihong0618/bilingual_book_maker

An AI-powered translation tool that uses LLMs to create multi-language versions of books and files in epub, txt, md, srt, and pdf formats. It supports a wide range of providers including OpenAI, Claude, Gemini, Groq, xAI, DeepL, and local Ollama instances. Key features include parallel processing, custom translation prompts, the ability to resume interrupted translations, and granular control over HTML tag translation for EPUB files.

Tokens
7.9K
Snippets
24
Records
57
Agent score
90%

What's inside bilingual_book_maker

  1. Run bilingual_book_maker using Docker

    main
    If you prefer not to set up the local environment, you can use Docker to build and run the tool. You must mount a local directory containing your book to /app/test_books inside the container. The --book_name argument must then use the container's internal path prefix /app/test_books/.
  2. Tweak the translation prompt using --prompt

    main

    You can customize the translation behavior by using the --prompt parameter. The prompt supports two placeholders that will be dynamically replaced during execution:

    • {text}: The source text to be translated.
    • {language}: The target language.

    There are three ways to provide the prompt:

    1. Simple User Prompt

    If you only need to define the user role content (without a specific system role), provide a string or a path to a .txt file.

    2. JSON Configuration (User + System Roles)

    To define both a system role and a user role, provide a JSON string or a path to a .json file containing system and user keys.

    3. PromptDown Format (.md files)

    For more structured prompts, you can use .md files following the PromptDown format. This allows you to define a System Message (or Developer Message for newer models) and a Conversation table.

    PromptDown Structure Example:

    ## System Message
    You are a professional translator.
    
    ## Conversation
    
    | Role  | Content |
    |-------|---------|
    | User  | Please translate the following text into {language}:\n\n{text} |
  3. Translate markdown files

    main

    Markdown files (.md) can be translated directly using the --book_name flag. For optimal results with Markdown structure, use the --prompt flag to provide a Markdown-specific prompt file (e.g., prompt_md.json).

    python3 make_book.py --book_name your_doc.md --model chatgptapi --openai_key ${openai_key} --prompt prompt_md.json
  4. Run bilingual_book_maker via CLI

    main

    You can use the bbook_maker command directly from your terminal. Provide the path to your book and your OpenAI API key using the --book_name and --openai_key flags.

    bbook_maker --book_name ${path of a book} --openai_key ${openai_key}
    
    # Example
    bbook_maker --book_name test_books/animal_farm.epub --openai_key ${openai_key}
  5. Configure custom API providers

    main

    To use a provider not natively supported (like DeepSeek), use the --provider flag along with --api_key. Providers must be defined in bbm_providers.json.

    python3 make_book.py --book_name test_books/animal_farm.epub --provider deepseek --api_key sk-xxx --language ja
  6. Install and Quick Start bilingual_book_maker

    main

    bilingual_book_maker is an AI translation tool that creates multilingual versions of epub, txt, md, or srt files. It is intended for books in the public domain.

    Prerequisites

    • Python 3.8+
    • ChatGPT or OpenAI token
    • epub/txt/md books
    • Internet access or a proxy

    Installation and Test Run

    You can run the tool directly from the source or install it as a package.

    Option 1: Run from source

    pip install -r requirements.txt
    python3 make_book.py --book_name test_books/animal_farm.epub --openai_key ${openai_key} --test

    Option 2: Install via pip

    pip install -U bbook_maker
    bbook --book_name test_books/animal_farm.epub --openai_key ${openai_key} --test
    pip install -r requirements.txt
    python3 make_book.py --book_name test_books/animal_farm.epub --openai_key ${openai_key} --test