Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into ghrc
Browse files Browse the repository at this point in the history
  • Loading branch information
hellofinch committed Dec 30, 2024
2 parents fcc5bdf + ba7b3f2 commit 87374a6
Show file tree
Hide file tree
Showing 17 changed files with 829 additions and 281 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/python-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ name: Test and Build Python Package

on:
push:
branches:
- main
pull_request:

jobs:
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ PDF scientific paper translation and bilingual comparison.

Feel free to provide feedback in [GitHub Issues](https://github.com/Byaidu/PDFMathTranslate/issues), [Telegram Group](https://t.me/+Z9_SgnxmsmA5NzBl) or [QQ Group](https://qm.qq.com/q/DixZCxQej0).

For details on how to contribute, please consult the [Contribution Guide](https://github.com/Byaidu/PDFMathTranslate/wiki/Contribution-Guide---%E8%B4%A1%E7%8C%AE%E6%8C%87%E5%8D%97).

<h2 id="updates">Updates</h2>

- [Dec. 24 2024] The translator now supports local models on [Xinference](https://github.com/xorbitsai/inference) _(by [@imClumsyPanda](https://github.com/imClumsyPanda))_
- [Dec. 19 2024] Non-PDF/A documents are now supported using `-cp` _(by [@reycn](https://github.com/reycn))_
- [Dec. 13 2024] Additional support for backend by _(by [@YadominJinta](https://github.com/YadominJinta))_
- [Dec. 10 2024] The translator now supports OpenAI models on Azure _(by [@yidasanqian](https://github.com/yidasanqian))_
Expand Down
14 changes: 10 additions & 4 deletions docs/ADVANCED.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ pdf2zh example.pdf -li en -lo ja
We've provided a detailed table on the required [environment variables](https://chatgpt.com/share/6734a83d-9d48-800e-8a46-f57ca6e8bcb4) for each translation service. Make sure to set them before using the respective service.

| **Translator** | **Service** | **Environment Variables** | **Default Values** | **Notes** |
| -------------------- | -------------- | --------------------------------------------------------------------- | -------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|----------------------|----------------|-----------------------------------------------------------------------|----------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **Google (Default)** | `google` | None | N/A | None |
| **Bing** | `bing` | None | N/A | None |
| **DeepL** | `deepl` | `DEEPL_AUTH_KEY` | `[Your Key]` | See [DeepL](https://support.deepl.com/hc/en-us/articles/360020695820-API-Key-for-DeepL-s-API) |
| **DeepLX** | `deeplx` | `DEEPLX_ENDPOINT` | `https://api.deepl.com/translate` | See [DeepLX](https://github.com/OwO-Network/DeepLX) |
| **Ollama** | `ollama` | `OLLAMA_HOST`, `OLLAMA_MODEL` | `http://127.0.0.1:11434`, `gemma2` | See [Ollama](https://github.com/ollama/ollama) |
| **Xinference** | `xinference` | `XINFERENCE_HOST`, `XINFERENCE_MODEL` | `http://127.0.0.1:9997`, `gemma-2-it` | See [Xinference](https://github.com/xorbitsai/inference) |
| **OpenAI** | `openai` | `OPENAI_BASE_URL`, `OPENAI_API_KEY`, `OPENAI_MODEL` | `https://api.openai.com/v1`, `[Your Key]`, `gpt-4o-mini` | See [OpenAI](https://platform.openai.com/docs/overview) |
| **AzureOpenAI** | `azure-openai` | `AZURE_OPENAI_BASE_URL`, `AZURE_OPENAI_API_KEY`, `AZURE_OPENAI_MODEL` | `[Your Endpoint]`, `[Your Key]`, `gpt-4o-mini` | See [Azure OpenAI](https://learn.microsoft.com/zh-cn/azure/ai-services/openai/chatgpt-quickstart?tabs=command-line%2Cjavascript-keyless%2Ctypescript-keyless%2Cpython&pivots=programming-language-python) |
| **Zhipu** | `zhipu` | `ZHIPU_API_KEY`, `ZHIPU_MODEL` | `[Your Key]`, `glm-4-flash` | See [Zhipu](https://open.bigmodel.cn/dev/api/thirdparty-frame/openai-sdk) |
Expand All @@ -64,7 +65,12 @@ We've provided a detailed table on the required [environment variables](https://
| **Tencent** | `tencent` | `TENCENTCLOUD_SECRET_ID`, `TENCENTCLOUD_SECRET_KEY` | `[Your ID]`, `[Your Key]` | See [Tencent](https://www.tencentcloud.com/products/tmt?from_qcintl=122110104) |
| **Dify** | `dify` | `DIFY_API_URL`, `DIFY_API_KEY` | `[Your DIFY URL]`, `[Your Key]` | See [Dify](https://github.com/langgenius/dify),Three variables, lang_out, lang_in, and text, need to be defined in Dify's workflow input. |
| **AnythingLLM** | `anythingllm` | `AnythingLLM_URL`, `AnythingLLM_APIKEY` | `[Your AnythingLLM URL]`, `[Your Key]` | See [anything-llm](https://github.com/Mintplex-Labs/anything-llm) |
|**Argos Translate**|`argos-translate`| | |See [argos-translate](https://github.com/argosopentech/argos-translate)|
|**Argos Translate**|`argos`| | |See [argos-translate](https://github.com/argosopentech/argos-translate)|
|**Grok**|`grok`| `GORK_API_KEY`, `GORK_MODEL` | `[Your GORK_API_KEY]`, `grok-2-1212` |See [Grok](https://docs.x.ai/docs/overview)|
|**DeepSeek**|`deepseek`| `DEEPSEEK_API_KEY`, `DEEPSEEK_MODEL` | `[Your DEEPSEEK_API_KEY]`, `deepseek-chat` |See [DeepSeek](https://www.deepseek.com/)|
|**OpenAI-Liked**|`openai-liked`| `OPENAILIKE_BASE_URL`, `OPENAILIKE_API_KEY`, `OPENAILIKE_MODEL` | `url`, `[Your Key]`, `model name` | None |

For large language models that are compatible with the OpenAI API but not listed in the table above, you can set environment variables using the same method outlined for OpenAI in the table.

Use `-s service` or `-s service:model` to specify service:

Expand Down Expand Up @@ -94,7 +100,7 @@ pdf2zh example.pdf -f "(CM[^RT].*|MS.*|.*Ital)" -c "(\(|\||\)|\+|=|\d|[\u0080-\u
Preserve `Latex`, `Mono`, `Code`, `Italic`, `Symbol` and `Math` fonts by default:

```bash
pdf2zh example.pdf -f "(CM[^R]|(MS|XY|MT|BL|RM|EU|LA|RS)[A-Z]|LINE|LCIRCLE|TeX-|rsfs|txsy|wasy|stmary|.*Mono|.*Code|.*Ital|.*Sym|.*Math)"
pdf2zh example.pdf -f "(CM[^R]|MS.M|XY|MT|BL|RM|EU|LA|RS|LINE|LCIRCLE|TeX-|rsfs|txsy|wasy|stmary|.*Mono|.*Code|.*Ital|.*Sym|.*Math)"
```

[⬆️ Back to top](#toc)
Expand Down Expand Up @@ -168,7 +174,7 @@ test,test123

example auth.html

```
```html
<!DOCTYPE html>
<html>
<head>
Expand Down
2 changes: 1 addition & 1 deletion docs/APIS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[**Documentation**](https://github.com/Byaidu/PDFMathTranslate) > **API Details** _(current)_

<h2 id="toc">Table of Content</h2>
The present project supports two types of APIs;
The present project supports two types of APIs, All methods need the Redis;

- [Functional calls in Python](#api-python)
- [HTTP protocols](#api-http)
Expand Down
44 changes: 27 additions & 17 deletions docs/README_ja-JP.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[English](../README.md) | [简体中文](README_zh-CN.md) | 日本語

<img src="./docs/images/banner.png" width="320px" alt="PDF2ZH"/>
<img src="./images/banner.png" width="320px" alt="PDF2ZH"/>

<h2 id="title">PDFMathTranslate</h2>

Expand Down Expand Up @@ -56,7 +56,7 @@
<h2 id="preview">プレビュー</h2>

<div align="center">
<img src="./docs/images/preview.gif" width="80%"/>
<img src="./images/preview.gif" width="80%"/>
</div>

<h2 id="demo">公共サービス 🌟</h2>
Expand Down Expand Up @@ -122,9 +122,9 @@ Python環境を事前にインストールする必要はありません
http://localhost:7860/
```

<img src="./docs/images/gui.gif" width="500"/>
<img src="./images/gui.gif" width="500"/>

詳細については、[GUIのドキュメント](./docs/README_GUI.md) を参照してください。
詳細については、[GUIのドキュメント](./README_GUI.md) を参照してください。

<h3 id="docker">方法4. Docker</h3>

Expand Down Expand Up @@ -158,7 +158,7 @@ Python環境を事前にインストールする必要はありません

コマンドラインで翻訳コマンドを実行し、現在の作業ディレクトリに翻訳されたドキュメント `example-mono.pdf` とバイリンガルドキュメント `example-dual.pdf` を生成します。デフォルトではGoogle翻訳サービスを使用します。

<img src="./docs/images/cmd.explained.png" width="580px" alt="cmd"/>
<img src="./images/cmd.explained.png" width="580px" alt="cmd"/>

以下の表に、参考のためにすべての高度なオプションをリストしました:

Expand Down Expand Up @@ -223,7 +223,13 @@ pdf2zh example.pdf -li en -lo ja
|**Tencent**|`tencent`|`TENCENTCLOUD_SECRET_ID`, `TENCENTCLOUD_SECRET_KEY`|`[Your ID]`, `[Your Key]`|See [Tencent](https://www.tencentcloud.com/products/tmt?from_qcintl=122110104)|
|**Dify**|`dify`|`DIFY_API_URL`, `DIFY_API_KEY`|`[Your DIFY URL]`, `[Your Key]`|See [Dify](https://github.com/langgenius/dify),Three variables, lang_out, lang_in, and text, need to be defined in Dify's workflow input.|
|**AnythingLLM**|`anythingllm`|`AnythingLLM_URL`, `AnythingLLM_APIKEY`|`[Your AnythingLLM URL]`, `[Your Key]`|See [anything-llm](https://github.com/Mintplex-Labs/anything-llm)|
|**Argos Translate**|`argos-translate`| | |See [argos-translate](https://github.com/argosopentech/argos-translate)|
|**Argos Translate**|`argos`| | |See [argos-translate](https://github.com/argosopentech/argos-translate)|
|**Grok**|`grok`| `GORK_API_KEY`, `GORK_MODEL` | `[Your GORK_API_KEY]`, `grok-2-1212` |See [Grok](https://docs.x.ai/docs/overview)|
|**DeepSeek**|`deepseek`| `DEEPSEEK_API_KEY`, `DEEPSEEK_MODEL` | `[Your DEEPSEEK_API_KEY]`, `deepseek-chat` |See [DeepSeek](https://www.deepseek.com/)|
|**OpenAI-Liked**|`openai-liked`| `OPENAILIKE_BASE_URL`, `OPENAILIKE_API_KEY`, `OPENAILIKE_MODEL` | `url`, `[Your Key]`, `model name` | None |
(need Japenese translation)
For large language models that are compatible with the OpenAI API but not listed in the table above, you can set environment variables using the same method outlined for OpenAI in the table.
`-s service` または `-s service:model` を使用してサービスを指定します:
Expand All @@ -249,7 +255,7 @@ pdf2zh example.pdf -f "(CM[^RT].*|MS.*|.*Ital)" -c "(\(|\||\)|\+|=|\d|[\u0080-\u
デフォルトで `Latex`、`Mono`、`Code`、`Italic`、`Symbol` および `Math` フォントを保持します:
```bash
pdf2zh example.pdf -f "(CM[^R]|(MS|XY|MT|BL|RM|EU|LA|RS)[A-Z]|LINE|LCIRCLE|TeX-|rsfs|txsy|wasy|stmary|.*Mono|.*Code|.*Ital|.*Sym|.*Math)"
pdf2zh example.pdf -f "(CM[^R]|MS.M|XY|MT|BL|RM|EU|LA|RS|LINE|LCIRCLE|TeX-|rsfs|txsy|wasy|stmary|.*Mono|.*Code|.*Ital|.*Sym|.*Math)"
```
<h3 id="threads">スレッド数を指定</h3>
Expand All @@ -260,16 +266,18 @@ pdf2zh example.pdf -f "(CM[^R]|(MS|XY|MT|BL|RM|EU|LA|RS)[A-Z]|LINE|LCIRCLE|TeX-|
pdf2zh example.pdf -t 1
```
<h3 id="prompt">custom prompt</h3>
(need Japenese translation)
Use `--prompt` to specify which prompt to use in llm:
<h3 id="prompt">カスタム プロンプト</h3>
`--prompt`を使用して、LLMで使用するプロンプトを指定します:
```bash
pdf2zh example.pdf -pr prompt.txt
```
example prompt.txt
```
`prompt.txt`の例:
```txt
[
{
"role": "system",
Expand All @@ -283,12 +291,14 @@ example prompt.txt
```
In custom prompt file, there are three variables can be used.
|**variables**|**comment**|
カスタムプロンプトファイルでは、以下の3つの変数が使用できます。
|**変数**|**内容**|
|-|-|
|`lang_in`|input language|
|`lang_out`|output language|
|`text`|text need to be translated|
|`lang_in`|ソース言語|
|`lang_out`|ターゲット言語|
|`text`|翻訳するテキスト|
<h2 id="todo">API</h2>
### Python
Expand Down
22 changes: 15 additions & 7 deletions docs/README_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[English](../README.md) | 简体中文 | [日本語](README_ja-JP.md)

<img src="./docs/images/banner.png" width="320px" alt="PDF2ZH"/>
<img src="./images/banner.png" width="320px" alt="PDF2ZH"/>

<h2 id="title">PDFMathTranslate</h2>

Expand Down Expand Up @@ -41,8 +41,11 @@

欢迎在 [GitHub Issues](https://github.com/Byaidu/PDFMathTranslate/issues)[Telegram 用户群](https://t.me/+Z9_SgnxmsmA5NzBl)[QQ 用户群](https://qm.qq.com/q/DixZCxQej0) 中提供反馈

有关如何贡献的详细信息,请查阅 [贡献指南](https://github.com/Byaidu/PDFMathTranslate/wiki/Contribution-Guide---%E8%B4%A1%E7%8C%AE%E6%8C%87%E5%8D%97)

<h2 id="updates">近期更新</h2>

- [Dec. 24 2024] 翻译功能支持接入 [Xinference](https://github.com/xorbitsai/inference) 运行的本地 LLM _(by [@imClumsyPanda](https://github.com/imClumsyPanda))_
- [Nov. 26 2024] CLI 现在已支持(多个)在线 PDF 文件 *(by [@reycn](https://github.com/reycn))*
- [Nov. 24 2024] 为降低依赖大小,提供 [ONNX](https://github.com/onnx/onnx) 支持 *(by [@Wybxc](https://github.com/Wybxc))*
- [Nov. 23 2024] 🌟 [免费公共服务](#demo) 上线! *(by [@Byaidu](https://github.com/Byaidu))*
Expand All @@ -56,7 +59,7 @@
<h2 id="preview">效果预览</h2>

<div align="center">
<img src="./docs/images/preview.gif" width="80%"/>
<img src="./images/preview.gif" width="80%"/>
</div>

<h2 id="demo">在线演示 🌟</h2>
Expand Down Expand Up @@ -121,9 +124,9 @@ set HF_ENDPOINT=https://hf-mirror.com
http://localhost:7860/
```

<img src="./docs/images/gui.gif" width="500"/>
<img src="./images/gui.gif" width="500"/>

查看 [documentation for GUI](./docs/README_GUI.md) 获取细节说明
查看 [documentation for GUI](/README_GUI.md) 获取细节说明

<h3 id="docker">方法四、容器化部署</h3>

Expand Down Expand Up @@ -157,7 +160,7 @@ set HF_ENDPOINT=https://hf-mirror.com

在命令行中执行翻译命令,在当前工作目录下生成译文文档 `example-mono.pdf` 和双语对照文档 `example-dual.pdf`,默认使用 Google 翻译服务

<img src="./docs/images/cmd.explained.png" width="580px" alt="cmd"/>
<img src="./images/cmd.explained.png" width="580px" alt="cmd"/>

我们在下表中列出了所有高级选项,以供参考:

Expand Down Expand Up @@ -222,7 +225,12 @@ pdf2zh example.pdf -li en -lo ja
|**Tencent**|`tencent`|`TENCENTCLOUD_SECRET_ID`, `TENCENTCLOUD_SECRET_KEY`|`[Your ID]`, `[Your Key]`|See [Tencent](https://www.tencentcloud.com/products/tmt?from_qcintl=122110104)|
|**Dify**|`dify`|`DIFY_API_URL`, `DIFY_API_KEY`|`[Your DIFY URL]`, `[Your Key]`|See [Dify](https://github.com/langgenius/dify),Three variables, lang_out, lang_in, and text, need to be defined in Dify's workflow input.|
|**AnythingLLM**|`anythingllm`|`AnythingLLM_URL`, `AnythingLLM_APIKEY`|`[Your AnythingLLM URL]`, `[Your Key]`|See [anything-llm](https://github.com/Mintplex-Labs/anything-llm)|
|**Argos Translate**|`argos-translate`| | |See [argos-translate](https://github.com/argosopentech/argos-translate)|
|**Argos Translate**|`argos`| | |See [argos-translate](https://github.com/argosopentech/argos-translate)|
|**Grok**|`grok`| `GORK_API_KEY`, `GORK_MODEL` | `[Your GORK_API_KEY]`, `grok-2-1212` |See [Grok](https://docs.x.ai/docs/overview)|
|**DeepSeek**|`deepseek`| `DEEPSEEK_API_KEY`, `DEEPSEEK_MODEL` | `[Your DEEPSEEK_API_KEY]`, `deepseek-chat` |See [DeepSeek](https://www.deepseek.com/)|
|**OpenAI-Liked**|`openai-liked`| `OPENAILIKE_BASE_URL`, `OPENAILIKE_API_KEY`, `OPENAILIKE_MODEL` | `url`, `[Your Key]`, `model name` | None |
对于未在上述表格中的,并且兼容 OpenAI api 的大语言模型,可使用表格中的 OpenAI 的方式进行环境变量的设置。
使用 `-s service` 或 `-s service:model` 指定翻译服务:
Expand All @@ -248,7 +256,7 @@ pdf2zh example.pdf -f "(CM[^RT].*|MS.*|.*Ital)" -c "(\(|\||\)|\+|=|\d|[\u0080-\u
默认保留 `Latex`, `Mono`, `Code`, `Italic`, `Symbol` 以及 `Math` 字体:
```bash
pdf2zh example.pdf -f "(CM[^R]|(MS|XY|MT|BL|RM|EU|LA|RS)[A-Z]|LINE|LCIRCLE|TeX-|rsfs|txsy|wasy|stmary|.*Mono|.*Code|.*Ital|.*Sym|.*Math)"
pdf2zh example.pdf -f "(CM[^R]|MS.M|XY|MT|BL|RM|EU|LA|RS|LINE|LCIRCLE|TeX-|rsfs|txsy|wasy|stmary|.*Mono|.*Code|.*Ital|.*Sym|.*Math)"
```
<h3 id="threads">指定线程数量</h3>
Expand Down
2 changes: 2 additions & 0 deletions pdf2zh/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import tqdm
import json
import io
from pdf2zh.pdf2zh import model

flask_app = Flask("pdf2zh")
flask_app.config.from_mapping(
Expand Down Expand Up @@ -47,6 +48,7 @@ def progress_bar(t: tqdm.tqdm):
doc_mono, doc_dual = translate_stream(
stream,
callback=progress_bar,
model=model,
**args,
)
return doc_mono, doc_dual
Expand Down
Loading

0 comments on commit 87374a6

Please sign in to comment.