Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Byaidu committed Dec 29, 2024
2 parents 1503c57 + 30075a8 commit d3b0b4e
Show file tree
Hide file tree
Showing 17 changed files with 725 additions and 279 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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,10 @@ In the following table, we list all advanced options for reference:
| `-f`, `-c` | [Exceptions](https://github.com/Byaidu/PDFMathTranslate/blob/main/docs/ADVANCED.md#exceptions) | `pdf2zh example.pdf -f "(MS.*)"` |
| `-cp` | Compatibility Mode | `pdf2zh example.pdf --compatible` |
| `--share` | Public link | `pdf2zh -i --share` |
| `--authorized` | Authorization | `pdf2zh -i --authorized users.txt [auth.html]` |
| `--authorized` | [Authorization](https://github.com/Byaidu/PDFMathTranslate/blob/main/docs/ADVANCED.md#auth) | `pdf2zh -i --authorized users.txt [auth.html]` |
| `--prompt` | [Custom Prompt](https://github.com/Byaidu/PDFMathTranslate/blob/main/docs/ADVANCED.md#prompt) | `pdf2zh --prompt [prompt.txt]` |
| `--onnx` | [Use Custom DocLayout-YOLO ONNX model] | `pdf2zh --onnx [onnx/model/path]` |
| `--serverport` | [Use Custom WebUI port] | `pdf2zh --serverport 7860` |

For detailed explanations, please refer to our document about [Advanced Usage](./docs/ADVANCED.md) for a full list of each option.

Expand Down
43 changes: 42 additions & 1 deletion docs/ADVANCED.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ 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`| | |See [argos-translate](https://github.com/argosopentech/argos-translate)|

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 @@ -117,7 +120,7 @@ pdf2zh example.pdf -t 1
Use `--prompt` to specify which prompt to use in llm:

```bash
pdf2zh example.pdf -pr prompt.txt
pdf2zh example.pdf --prompt prompt.txt
```

example prompt.txt
Expand Down Expand Up @@ -145,3 +148,41 @@ In custom prompt file, there are three variables can be used.
[⬆️ Back to top](#toc)

---

<h3 id="auth">Authorization</h3>

Use `--authorized` to specify which user to use Web UI and custom the login page:

```bash
pdf2zh example.pdf --authorized users.txt auth.html
```

example users.txt
Each line contains two elements, username, and password, separated by a comma.

```
admin,123456
user1,password1
user2,abc123
guest,guest123
test,test123
```

example auth.html

```html
<!DOCTYPE html>
<html>
<head>
<title>Simple HTML</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>Welcome to my simple HTML page.</p>
</body>
</html>
```

[⬆️ Back to top](#toc)

---
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
42 changes: 26 additions & 16 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 All @@ -175,8 +175,10 @@ Python環境を事前にインストールする必要はありません
| `-o` | 出力ディレクトリ | `pdf2zh example.pdf -o output` |
| `-f`, `-c` | [例外](#exceptions) | `pdf2zh example.pdf -f "(MS.*)"` |
| `--share` | [gradio公開リンクを取得] | `pdf2zh -i --share` |
| `--authorized` | [ウェブ認証とカスタム認証ページの追加] | `pdf2zh -i --authorized users.txt [auth.html]` |
| `--authorized` | [[ウェブ認証とカスタム認証ページの追加](https://github.com/Byaidu/PDFMathTranslate/blob/main/docs/ADVANCED.)] | `pdf2zh -i --authorized users.txt [auth.html]` |
| `--prompt` | [カスタムビッグモデルのプロンプトを使用する] | `pdf2zh --prompt [prompt.txt]` |
| `--onnx` | [カスタムDocLayout-YOLO ONNXモデルの使用] | `pdf2zh --onnx [onnx/model/path]` |
| `--serverport` | [カスタムWebUIポートを使用する] | `pdf2zh --serverport 7860` |

<h3 id="partial">全文または部分的なドキュメント翻訳</h3>

Expand Down Expand Up @@ -221,6 +223,10 @@ 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`| | |See [argos-translate](https://github.com/argosopentech/argos-translate)|
(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 Down Expand Up @@ -257,16 +263,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 @@ -280,12 +288,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
17 changes: 11 additions & 6 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 @@ -58,7 +58,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 @@ -123,9 +123,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 @@ -159,7 +159,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 All @@ -176,8 +176,10 @@ set HF_ENDPOINT=https://hf-mirror.com
| `-o` | 输出目录 | `pdf2zh example.pdf -o output` |
| `-f`, `-c` | [例外规则](#exceptions) | `pdf2zh example.pdf -f "(MS.*)"` |
| `--share` | [获取 gradio 公开链接] | `pdf2zh -i --share` |
| `--authorized` | [添加网页认证和自定义认证页] | `pdf2zh -i --authorized users.txt [auth.html]` |
| `--authorized` | [[添加网页认证和自定义认证页](https://github.com/Byaidu/PDFMathTranslate/blob/main/docs/ADVANCED.)] | `pdf2zh -i --authorized users.txt [auth.html]` |
| `--prompt` | [使用自定义的大模型prompt] | `pdf2zh --prompt [prompt.txt]` |
| `--onnx` | [使用自定义的 DocLayout-YOLO ONNX 模型] | `pdf2zh --onnx [onnx/model/path]` |
| `--serverport` | [使用自定义的 WebUI 端口] | `pdf2zh --serverport 7860` |

<h3 id="partial">全文或部分文档翻译</h3>

Expand Down Expand Up @@ -222,6 +224,9 @@ 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`| | |See [argos-translate](https://github.com/argosopentech/argos-translate)|
对于未在上述表格中的,并且兼容 OpenAI api 的大语言模型,可使用表格中的 OpenAI 的方式进行环境变量的设置。
使用 `-s service` 或 `-s service:model` 指定翻译服务:
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 d3b0b4e

Please sign in to comment.