一键翻译各类图片内文字
English | 更新日志
欢迎加入我们的 Discord https://discord.gg/Ak8APNy4vb
针对群内、各个图站上大量不太可能会有人去翻译的图片设计,让我这种日语小白能够勉强看懂图片
主要支持日语,汉语、英文和韩语
支持图片修补和嵌字
该项目是求闻转译志的 v2 版本
只是初步版本,我们需要您的帮助完善
这个项目目前只完成了简单的 demo,依旧存在大量不完善的地方,我们需要您的帮助完善这个项目!
请支持我们使用 GPU 服务器,谢谢!
官方演示站 (由 zyddnys 维护): https://cotrans.touhou.ai/
镜像站 (由 Eidenz 维护): https://manga.eidenz.com/
浏览器脚本 (由 QiroNT 维护): https://greasyfork.org/scripts/437569
# 首先,确信你的机器安装了 Python 3.8 及以上版本,和相应的编译工具
$ python --version
Python 3.8.13
# 拉取仓库
$ git clone https://github.com/zyddnys/manga-image-translator.git
# 安装依赖
$ pip install -r requirements.txt
注意:pydensecrf 和其他pip包可能需要操作系统的相应编译工具(如Debian的build-essential)。
[使用谷歌翻译时可选]
申请有道翻译或者 DeepL 的 API,把你的 APP_KEY 和 APP_SECRET 或 AUTH_KEY 写入 translators/key.py 中。
| 名称 | 是否需要 API Key | 是否离线可用 | 其他说明 |
|---|---|---|---|
| youdao | ✔️ | 需要 YOUDAO_APP_KEY 和 YOUDAO_SECRET_KEY | |
| baidu | ✔️ | 需要 BAIDU_APP_ID 和 BAIDU_SECRET_KEY | |
| deepl | ✔️ | 需要 DEEPL_AUTH_KEY | |
| caiyun | ✔️ | 需要 CAIYUN_TOKEN | |
| gpt3 | ✔️ | Implements text-davinci-003. Requires OPENAI_API_KEY | |
| gpt3.5 | ✔️ | Implements gpt-3.5-turbo. Requires OPENAI_API_KEY | |
| gpt4 | ✔️ | Implements gpt-4. Requires OPENAI_API_KEY | |
| deepseek | ✔️ | 需要 DEEPSEEK_API_KEY | |
| papago | |||
| sakura | 需要SAKURA_API_BASE | ||
| ollama | 需要 OLLAMA_API_BASE OLLAMA_MODEL | ||
| offline | ✔️ | 自动选择可用的离线模型,只是选择器 | |
| sugoi | ✔️ | 只能翻译英文 | |
| m2m100 | ✔️ | 可以翻译所有语言 | |
| m2m100_big | ✔️ | 带big的是完整尺寸,不带是精简版 | |
| none | ✔️ | 翻译成空白文本 | |
| mbart50 | ✔️ | ||
| original | ✔️ | 翻译成源文本 |
可以填入 --target-lang 参数
CHS: Chinese (Simplified)
CHT: Chinese (Traditional)
CSY: Czech
NLD: Dutch
ENG: English
FRA: French
DEU: German
HUN: Hungarian
ITA: Italian
JPN: Japanese
KOR: Korean
PLK: Polish
PTB: Portuguese (Brazil)
ROM: Romanian
RUS: Russian
ESP: Spanish
TRK: Turkish
VIN: Vietnames
ARA: Arabic
SRP: Serbian
HRV: Croatian
THA: Thai
IND: Indonesian
FIL: Filipino (Tagalog)
-h, --help show this help message and exit -v, --verbose Print debug info and save intermediate images in result folder --attempts ATTEMPTS Retry attempts on encountered error. -1 means infinite times. --ignore-errors Skip image on encountered error. --model-dir MODEL_DIR Model directory (by default ./models in project root) --use-gpu Turn on/off gpu (auto switch between mps and cuda) --use-gpu-limited Turn on/off gpu (excluding offline translator) --font-path FONT_PATH Path to font file --pre-dict PRE_DICT Path to the pre-translation dictionary file --post-dict POST_DICT Path to the post-translation dictionary file --kernel-size KERNEL_SIZE Set the convolution kernel size of the text erasure area to completely clean up text residues --config-file CONFIG_FILE path to the config file
# 如果机器有支持 CUDA 的 NVIDIA GPU,可以添加 `--use-gpu` 参数
# 使用 `--use-gpu-limited` 将需要使用大量显存的翻译交由CPU执行,这样可以减少显存占用
# 使用 `--translator=<翻译器名称>` 来指定翻译器
# 使用 `--target-lang=<语言代码>` 来指定目标语言
# 将 <图片文件路径> 替换为图片的路径
# 如果你要翻译的图片比较小或者模糊,可以使用upscaler提升图像大小与质量,从而提升检测翻译效果
$ python -m manga_translator --verbose --use-gpu --translator=google --target-lang=CHS -i <path_to_image_file>
# 结果会存放到 result 文件夹里
# 其它参数如上
# 使用 `--mode batch` 开启批量翻译模式
# 将 <图片文件夹路径> 替换为图片文件夹的路径
$ python -m manga_translator --verbose --mode batch --use-gpu --translator=google --target-lang=CHS -i <图片文件夹路径>
# 结果会存放到 `<图片文件夹路径>-translated` 文件夹里
# 其它参数如上
# 使用 `--mode web` 开启 Web 服务器模式
$ python -m manga_translator --verbose --mode web --use-gpu
# 程序服务会开启在 http://127.0.0.1:5003
程序提供两个请求模式:同步模式和异步模式。
同步模式下你的 HTTP POST 请求会一直等待直到翻译完成。
异步模式下你的 HTTP POST 会立刻返回一个 task_id,你可以使用这个 task_id 去定期轮询得到翻译的状态。
task_id 去 result 文件夹里取结果,例如通过 Nginx 暴露 result 下的内容task_idtask_id 你可以定期发送 POST 轮询请求 JSON {"taskid": <task_id>} 到 http://127.0.0.1:5003/task-statefinished、error 或 error-lang 时代表翻译完成人工翻译允许代替机翻手动填入翻译后文本
POST 提交一个带图片,名字是 file 的 form 到 http://127.0.0.1:5003/manual-translate,并等待返回
你会得到一个 JSON 数组,例如:
{
"task_id": "12c779c9431f954971cae720eb104499",
"status": "pending",
"trans_result": [
{
"s": "☆上司来ちゃった……",
"t": ""
}
]
}
将翻译后内容填入 t 字符串:
{
"task_id": "12c779c9431f954971cae720eb104499",
"status": "pending",
"trans_result": [
{
"s": "☆上司来ちゃった……",
"t": "☆上司来了..."
}
]
}
将该 JSON 发送到 http://127.0.0.1:5003/post-manual-result,并等待返回
之后就可以从得到的 task_id 去 result 文件夹里取结果,例如通过 Nginx 暴露 result 下的内容
列一下以后完善这个项目需要做的事,欢迎贡献!
以下样例可能并未经常更新,可能不能代表当前主分支版本的效果。
| 原始图片 | 翻译后图片 |
|---|---|
(Source @09ra_19ra) |
(Mask) |
(Source @VERTIGRIS_ART) |
--detector ctd
(Mask)
|
(Source @hiduki_yayoi) |
--translator none
(Mask)
|
(Source @rikak) |
(Mask) |