mirror of
https://github.com/yihong0618/bilingual_book_maker.git
synced 2025-06-02 09:30:24 +00:00
fix: lint
Signed-off-by: yihong0618 <zouzou0208@gmail.com>
This commit is contained in:
parent
4e7cbb5e32
commit
f0927404fe
@ -35,7 +35,7 @@ def parse_prompt_arg(prompt_arg):
|
||||
else:
|
||||
raise FileNotFoundError(f"{prompt_arg} not found")
|
||||
|
||||
#if prompt is None or any(c not in prompt["user"] for c in ["{text}", "{language}"]):
|
||||
# if prompt is None or any(c not in prompt["user"] for c in ["{text}", "{language}"]):
|
||||
if prompt is None or any(c not in prompt["user"] for c in ["{text}"]):
|
||||
raise ValueError("prompt must contain `{text}`")
|
||||
|
||||
|
@ -60,21 +60,21 @@ class MarkdownBookLoader(BaseBookLoader):
|
||||
for line in self.origin_book:
|
||||
# 如果是空行且当前段落不为空,保存当前段落
|
||||
if not line.strip() and current_paragraph:
|
||||
self.md_paragraphs.append('\n'.join(current_paragraph))
|
||||
self.md_paragraphs.append("\n".join(current_paragraph))
|
||||
current_paragraph = []
|
||||
# 如果是标题行,单独作为一个段落
|
||||
elif line.strip().startswith('#'):
|
||||
elif line.strip().startswith("#"):
|
||||
if current_paragraph:
|
||||
self.md_paragraphs.append('\n'.join(current_paragraph))
|
||||
self.md_paragraphs.append("\n".join(current_paragraph))
|
||||
current_paragraph = []
|
||||
self.md_paragraphs.append(line)
|
||||
# 其他情况,添加到当前段落
|
||||
else:
|
||||
current_paragraph.append(line)
|
||||
|
||||
|
||||
# 处理最后一个段落
|
||||
if current_paragraph:
|
||||
self.md_paragraphs.append('\n'.join(current_paragraph))
|
||||
self.md_paragraphs.append("\n".join(current_paragraph))
|
||||
|
||||
@staticmethod
|
||||
def _is_special_text(text):
|
||||
@ -93,7 +93,7 @@ class MarkdownBookLoader(BaseBookLoader):
|
||||
for i in range(0, len(self.md_paragraphs), self.batch_size)
|
||||
]
|
||||
for paragraphs in sliced_list:
|
||||
batch_text = '\n\n'.join(paragraphs)
|
||||
batch_text = "\n\n".join(paragraphs)
|
||||
if self._is_special_text(batch_text):
|
||||
continue
|
||||
if not self.resume or index >= p_to_save_len:
|
||||
@ -112,7 +112,7 @@ class MarkdownBookLoader(BaseBookLoader):
|
||||
except Exception as e:
|
||||
print(f"翻译过程中出错: {e}")
|
||||
raise Exception("翻译过程中出现错误") from e
|
||||
|
||||
|
||||
self.p_to_save.append(temp)
|
||||
if not self.single_translate:
|
||||
self.bilingual_result.append(batch_text)
|
||||
|
@ -121,12 +121,18 @@ class Gemini(Base):
|
||||
)
|
||||
t_text = self.convo.last.text.strip()
|
||||
# 检查是否包含特定标签,如果有则只返回标签内的内容
|
||||
tag_pattern = r'<step3_refined_translation>(.*?)</step3_refined_translation>'
|
||||
tag_pattern = (
|
||||
r"<step3_refined_translation>(.*?)</step3_refined_translation>"
|
||||
)
|
||||
tag_match = re.search(tag_pattern, t_text, re.DOTALL)
|
||||
if tag_match:
|
||||
print("[bold green]" + re.sub("\n{3,}", "\n\n", t_text) + "[/bold green]")
|
||||
print(
|
||||
"[bold green]"
|
||||
+ re.sub("\n{3,}", "\n\n", t_text)
|
||||
+ "[/bold green]"
|
||||
)
|
||||
t_text = tag_match.group(1).strip()
|
||||
#print("[bold green]" + re.sub("\n{3,}", "\n\n", t_text) + "[/bold green]")
|
||||
# print("[bold green]" + re.sub("\n{3,}", "\n\n", t_text) + "[/bold green]")
|
||||
break
|
||||
except StopCandidateException as e:
|
||||
print(
|
||||
|
Loading…
x
Reference in New Issue
Block a user