Skip to content

05chrs/Webtoon-Translator

Repository files navigation

Webtoon Translator

A Python-based tool for automatically translating Korean webtoons to English. This tool uses OCR to detect text in speech bubbles, translates the text using OpenAI's GPT-3.5-turbo (the cheapest model), and renders it back onto the image while preserving the original artwork.

Features

  • Automatic text detection in speech bubbles using EasyOCR
  • Korean to English translation using OpenAI GPT-3.5-turbo (much better quality than MarianMT)
  • Intelligent sound effect translation (e.g., "어허회" → "sob", "퍽" → "whack")
  • Context-aware translations that maintain plot coherence
  • Text removal and inpainting to preserve artwork
  • Support for both single panels and long webtoon strips
  • Automatic panel splitting for long webtoon images
  • Translation caching to reduce API costs

Installation

  1. Clone the repository:
git clone https://github.com/cphanhth/Webtoon-Translator.git
cd Webtoon-Translator
  1. Create a virtual environment and install dependencies:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -r requirements.txt
  1. Set up OpenAI API key (required for translation):
python setup_openai.py

Or manually create a .env file with:

OPENAI_API_KEY=your_openai_api_key_here
OPENAI_MODEL=gpt-3.5-turbo
OPENAI_MAX_TOKENS=1000
OPENAI_TEMPERATURE=0.3

Usage

Command Line Interface

Single Panel Translation

python src/main.py input_panel.png output_panel.png

Long Webtoon Translation

python src/main.py long_webtoon.png translated_webtoon.png --mode webtoon

With Custom Font

python src/main.py input.png output.png --font path/to/font.ttf

With OpenAI API Key (if not in .env)

python src/main.py input.png output.png --openai-key YOUR_API_KEY

Python API

from src.main import WebtoonTranslator

# Initialize translator
translator = WebtoonTranslator()

# Translate single panel
translator.translate_panel("input_panel.png", "output_panel.png")

# Translate long webtoon
translator.translate_webtoon("long_webtoon.png", "translated_webtoon.png")

Testing

Test the OpenAI integration:

python test_openai.py

Cost Estimation

Using GPT-3.5-turbo (the cheapest model):

  • Input tokens: $0.0015 per 1K tokens
  • Output tokens: $0.002 per 1K tokens
  • Typical cost per panel: ~$0.0001 - $0.0005
  • 1000 panels: ~$0.10 - $0.50

The system includes caching to avoid re-translating identical text.

Configuration

You can customize the OpenAI settings in your .env file:

  • OPENAI_MODEL: Model to use (default: gpt-3.5-turbo)
  • OPENAI_MAX_TOKENS: Maximum response length (default: 1000)
  • OPENAI_TEMPERATURE: Response creativity 0.0-1.0 (default: 0.3)

Requirements

  • Python 3.7+
  • OpenCV
  • NumPy
  • Pillow
  • EasyOCR
  • OpenAI (for translation)
  • python-dotenv (for configuration)

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published