This commit is contained in:
yihong0618 2023-04-08 17:38:20 +08:00
parent 1b64fe0315
commit bd7fd501e7
3 changed files with 8 additions and 8 deletions

View File

@ -270,10 +270,9 @@ class EPUBBookLoader(BaseBookLoader):
for item in complete_book.get_items():
if item.file_name != fixname:
new_book.add_item(item)
if soup_complete:
complete_item.content = soup_complete.encode()
complete_item.content = soup_complete.encode()
# =================================================
index = self.process_item(
complete_item,
index,
@ -367,7 +366,8 @@ class EPUBBookLoader(BaseBookLoader):
if self.is_test and index >= self.test_num:
break
item.content = soup.encode()
if soup:
item.content = soup.encode()
new_book.add_item(item)
return index
@ -465,7 +465,8 @@ class EPUBBookLoader(BaseBookLoader):
else:
break
# for save temp book
item.content = soup.encode()
if soup:
item.content = soup.encode()
new_temp_book.add_item(item)
name, _ = os.path.splitext(self.epub_name)
epub.write_epub(f"{name}_bilingual_temp.epub", new_temp_book, {})

View File

@ -113,7 +113,7 @@ class TXTBookLoader(BaseBookLoader):
def _save_progress(self):
try:
with open(self.bin_path, "w") as f:
with open(self.bin_path, "w", encoding="utf-8") as f:
f.write("\n".join(self.p_to_save))
except:
raise Exception("can not save resume file")

View File

@ -90,7 +90,7 @@ class ChatGPTAPI(Base):
# work well or exception finish by length limit
choice = completion["choices"][0]
t_text = choice.get("message").get("content").encode("utf8").decode()
t_text = choice.get("message").get("content", "").encode("utf8").decode()
if choice["finish_reason"] == "length":
with open("log/long_text.txt", "a") as f:
@ -212,7 +212,6 @@ The total token is too long and cannot be completely translated\n
print(result_list[i], file=f)
print(file=f)
print("=============================", file=f)
print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
print(
f"bug: {plist_len} paragraphs of text translated into {len(result_list)} paragraphs",