use docker (#53)

* use docker

* Update Dockerfile

* Update README.md

add example
This commit is contained in:
Zhima-Mochi 2023-03-07 15:37:29 +08:00 committed by GitHub
parent fadc957c87
commit f8edb63486
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 1 deletions

10
.dockerignore Normal file
View File

@ -0,0 +1,10 @@
Dockerfile*
docker-compose*
LICENSE
test_books
README*
.dockerignore
.git
.github
.gitignore
.vscode

13
Dockerfile Normal file
View File

@ -0,0 +1,13 @@
FROM python:3.10-slim
RUN apt-get update
WORKDIR /app
COPY requirements.txt .
RUN pip install -r /app/requirements.txt
COPY . .
ENTRYPOINT ["python3", "make_book.py"]

View File

@ -41,12 +41,43 @@ export OPENAI_API_KEY=${your_api_key}
python3 make_book.py --book_name test_books/animal_farm.epub --model gpt3 --no_limit --language "Simplified Chinese"
```
More understandable example
```
```shell
python3 make_book.py --book_name 'animal_farm.epub' --openai_key sk-XXXXX --api_base 'https://xxxxx/v1'
# or
python make_book.py --book_name 'animal_farm.epub' --openai_key sk-XXXXX --api_base 'https://xxxxx/v1'
```
## Docker
You can use [Docker](https://www.docker.com/) if you don't want to deal with setting up the environment.
```shell
# build image
docker build --tag bilingual_book_maker .
# run container
# "$folder_path" represents the folder where your book file is located. Also, it is where the processed file will be stored.
# Windows PowerShell
$folder_path=your_folder_path # $folder_path="C:\Users\user\mybook\"
$book_name=your_book_name # $book_name="animal_farm.epub"
$openai_key=your_api_key # $openai_key="sk-xxx"
$language=your_language # see utils.py
docker run --rm --name bilingual_book_maker --mount type=bind,source=$folder_path,target='/app/test_books' bilingual_book_maker --book_name "/app/test_books/$book_name" --openai_key $openai_key --no_limit --language $language
# linux
export folder_path=${your_folder_path}
export book_name=${your_book_name}
export openai_key=${your_api_key}
export language=${your_language}
docker container run --rm --name bilingual_book_maker --mount type=bind,source=${folder_path},target='/app/test_books' bilingual_book_maker --book_name "/app/test_books/${book_name}" --openai_key ${openai_key} --no_limit --language "${language}"
```
for example,
```shell
# linux
docker container run --rm --name bilingual_book_maker --mount type=bind,source=/home/user/my_books,target='/app/test_books' bilingual_book_maker --book_name /app/test_books/animal_farm.epub --openai_key sk-XXX --no_limit --test --test_num 1 --language zh-hant
```
## Notes
1. here is a limit. If you want to speed up the process, consider paying for the service or use multiple OpenAI tokens