From 26e9006ede9073c753a4483e7a5807a6fcd4feb1 Mon Sep 17 00:00:00 2001 From: Yuankui Li Date: Mon, 6 Mar 2023 13:25:43 +0800 Subject: [PATCH] keep translation only --- make_book.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/make_book.py b/make_book.py index 486861fc..3bd04d22 100644 --- a/make_book.py +++ b/make_book.py @@ -193,6 +193,8 @@ def make_bilingual_book(self): new_p.string = self.translate_model.translate(p.text) self.p_to_save.append(new_p.text) p.insert_after(new_p) + if TRANSLATION_ONLY: + p.extract() index += 1 if IS_TEST and index > TEST_NUM: break @@ -275,6 +277,12 @@ def save_progress(self): default="zh-hans", help="language to translate to", ) + parser.add_argument( + "--translation-only", + dest="translation_only", + action="store_false", + help="remove original paragraphs, and keep translation only", + ) parser.add_argument( "--resume", dest="resume", @@ -308,6 +316,7 @@ def save_progress(self): OPENAI_API_KEY = options.openai_key or env.get("OPENAI_API_KEY") RESUME = options.resume + TRANSLATION_ONLY = options.translation_only if not OPENAI_API_KEY: raise Exception("Need openai API key, please google how to") if not options.book_name.endswith(".epub"):