Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files
AIGN.py
CHANGED
@@ -165,19 +165,30 @@ class AIGN:
|
|
165 |
temperature=0.66,
|
166 |
)
|
167 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
168 |
def update_chapter_list(self):
|
169 |
-
self.chapter_list =
|
170 |
-
chapter_content = ""
|
171 |
-
for line in self.novel_content.split('\n'):
|
172 |
-
if line.startswith('## 第'):
|
173 |
-
if chapter_content:
|
174 |
-
self.chapter_list.append((chapter_title, chapter_content.strip()))
|
175 |
-
chapter_title = line.strip()
|
176 |
-
chapter_content = ""
|
177 |
-
else:
|
178 |
-
chapter_content += line + "\n"
|
179 |
-
if chapter_content:
|
180 |
-
self.chapter_list.append((chapter_title, chapter_content.strip()))
|
181 |
|
182 |
|
183 |
def updateNovelContent(self):
|
|
|
165 |
temperature=0.66,
|
166 |
)
|
167 |
|
168 |
+
def split_chapters(self, novel_content):
|
169 |
+
# 使用正则表达式匹配章节标题
|
170 |
+
chapter_pattern = re.compile(r'(?:##?|)?\s*第([一二三四五六七八九十百千万亿\d]+)章[::]?\s*(.+)')
|
171 |
+
|
172 |
+
# 将小说正文按章节标题分割
|
173 |
+
chapters = chapter_pattern.split(novel_content)
|
174 |
+
|
175 |
+
# 移除第一个空字符串(如果存在)
|
176 |
+
if chapters[0] == '':
|
177 |
+
chapters = chapters[1:]
|
178 |
+
|
179 |
+
# 将章节标题和内容组合成元组
|
180 |
+
chapter_tuples = []
|
181 |
+
for i in range(0, len(chapters), 3):
|
182 |
+
if i + 2 < len(chapters):
|
183 |
+
chapter_num = chapters[i]
|
184 |
+
chapter_title = chapters[i + 1]
|
185 |
+
chapter_content = chapters[i + 2]
|
186 |
+
chapter_tuples.append((f"第{chapter_num}章 {chapter_title}", chapter_content))
|
187 |
+
|
188 |
+
return chapter_tuples
|
189 |
+
|
190 |
def update_chapter_list(self):
|
191 |
+
self.chapter_list = self.split_chapters(self.novel_content)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
192 |
|
193 |
|
194 |
def updateNovelContent(self):
|
app.py
CHANGED
@@ -41,7 +41,7 @@ def set_api_model(model):
|
|
41 |
# 修改获取章节名的函数
|
42 |
def get_chapter_name(content):
|
43 |
# 查找最后一个章节标题,支持数字和汉字表示的章节
|
44 |
-
matches = re.findall(r'
|
45 |
if matches:
|
46 |
chapter_num, chapter_title = matches[-1]
|
47 |
# 如果章节号是数字,直接使用;如果是汉字,转换为数字
|
|
|
41 |
# 修改获取章节名的函数
|
42 |
def get_chapter_name(content):
|
43 |
# 查找最后一个章节标题,支持数字和汉字表示的章节
|
44 |
+
matches = re.findall(r'(?:##?|)?\s*第([一二三四五六七八九十百千万亿\d]+)章[::]?\s*(.+)', content)
|
45 |
if matches:
|
46 |
chapter_num, chapter_title = matches[-1]
|
47 |
# 如果章节号是数字,直接使用;如果是汉字,转换为数字
|