Skip to content

Commit

Permalink
doc: api
Browse files Browse the repository at this point in the history
  • Loading branch information
Byaidu committed Dec 18, 2024
1 parent a353e68 commit 55b16c0
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions docs/APIS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ params = {
'lang_out': 'zh',
'service': 'google',
'thread': 4,
}
}
```
Translate with files:
```python
(file_mono, file_dual) = translate(files=['example.pdf'], **params)[0]

```
Translate with stream:
```python
with open('example.pdf', 'rb') as f:
(stream_mono, stream_dual) = translate_stream(stream=f.read(),
**params)

(stream_mono, stream_dual) = translate_stream(stream=f.read(), **params)
```

[⬆️ Back to top](#toc)
Expand All @@ -39,7 +42,7 @@ with open('example.pdf', 'rb') as f:

In a more flexible way, you can communicate with the program using HTTP protocols, if:

1. You have the backend installed & running
1. Install and run backend

```bash
pip install pdf2zh[backend]
Expand All @@ -49,7 +52,7 @@ In a more flexible way, you can communicate with the program using HTTP protocol

2. Using HTTP protocols as follows:

- Translate
- Submit translate task

```bash
curl http://localhost:11008/v1/translate -F "file=@example.pdf" -F "data={\"lang_in\":\"en\",\"lang_out\":\"zh\",\"service\":\"google\",\"thread\":4}"
Expand All @@ -70,19 +73,19 @@ In a more flexible way, you can communicate with the program using HTTP protocol
{"state":"SUCCESS"}
```

- Specifying output
- Save monolingual file

```bash
curl http://localhost:11008/v1/translate/d9894125-2f4e-45ea-9d93-1a9068d2045a/mono --output example-mono.pdf
```

- Specifying the output as a bilingual file
- Save bilingual file

```bash
curl http://localhost:11008/v1/translate/d9894125-2f4e-45ea-9d93-1a9068d2045a/dual --output example-dual.pdf
```

- Or delete it after the whole process
- Interrupt if running and delete the task
```bash
curl http://localhost:11008/v1/translate/d9894125-2f4e-45ea-9d93-1a9068d2045a -X DELETE
```
Expand Down

0 comments on commit 55b16c0

Please sign in to comment.