Spaces:
Running
Running
Mahiruoshi
commited on
Commit
•
eb8ecd4
1
Parent(s):
397defe
Update app.py
Browse files
app.py
CHANGED
@@ -273,7 +273,7 @@ def extract_text_from_pdf(file_path):
|
|
273 |
content = [page.extract_text() for page in reader.pages]
|
274 |
return '\n'.join(content)
|
275 |
|
276 |
-
def
|
277 |
current_content = []
|
278 |
|
279 |
def _extract(data, current_data=None):
|
@@ -283,26 +283,17 @@ def extract_text_from_game(data):
|
|
283 |
current_data = {}
|
284 |
|
285 |
if isinstance(data, dict):
|
286 |
-
if '
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
if 'voiceId' in data:
|
291 |
-
current_data['voiceId'] = data['voiceId']
|
292 |
|
293 |
-
|
294 |
-
|
295 |
-
valid_body = bool(re.sub(r'[^\w]', '', current_data.get('body', "")))
|
296 |
-
|
297 |
-
if valid_data and valid_displayname and valid_body:
|
298 |
-
current_content.append(f"{current_data['windowDisplayName']}|{current_data['body']}")
|
299 |
-
|
300 |
-
for key in data:
|
301 |
-
_extract(data[key], dict(current_data))
|
302 |
|
303 |
elif isinstance(data, list):
|
304 |
for item in data:
|
305 |
-
_extract(item, dict(current_data))
|
306 |
|
307 |
_extract(data)
|
308 |
return '\n'.join(current_content)
|
@@ -320,7 +311,7 @@ def extract_text_from_file(inputFile):
|
|
320 |
elif file_extension == ".asset":
|
321 |
with open(inputFile, 'r', encoding='utf-8') as f:
|
322 |
content = json.load(f)
|
323 |
-
return extract_text_from_game(content)
|
324 |
else:
|
325 |
raise ValueError(f"Unsupported file format: {file_extension}")
|
326 |
|
@@ -396,7 +387,7 @@ if __name__ == "__main__":
|
|
396 |
]
|
397 |
with gr.Blocks() as app:
|
398 |
gr.Markdown(
|
399 |
-
'# Bang Dream全员TTS,使用本模型请严格遵守法律法规!\n发布二创作品请标注本项目作者及链接、作品使用Bert-VITS2 AI
|
400 |
)
|
401 |
for band in BandList:
|
402 |
with gr.TabItem(band):
|
@@ -453,7 +444,7 @@ if __name__ == "__main__":
|
|
453 |
with gr.Row():
|
454 |
with gr.Column():
|
455 |
gr.Markdown(
|
456 |
-
f"从 <a href='filelists'>filelists文件夹</a>
|
457 |
)
|
458 |
inputFile = gr.inputs.File(label="上传游戏脚本(日文)、中文脚本(需设置角色对应关系)、自制文、(需设置角色对应关系")
|
459 |
groupSize = gr.Slider(
|
|
|
273 |
content = [page.extract_text() for page in reader.pages]
|
274 |
return '\n'.join(content)
|
275 |
|
276 |
+
def extract_text_from_game2(data):
|
277 |
current_content = []
|
278 |
|
279 |
def _extract(data, current_data=None):
|
|
|
283 |
current_data = {}
|
284 |
|
285 |
if isinstance(data, dict):
|
286 |
+
if 'name' in data and 'body' in data:
|
287 |
+
current_name = data['name']
|
288 |
+
current_body = data['body'].replace('\n', '')
|
289 |
+
current_content.append(f"{current_name}|{current_body}")
|
|
|
|
|
290 |
|
291 |
+
for key, value in data.items():
|
292 |
+
_extract(value, dict(current_data))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
293 |
|
294 |
elif isinstance(data, list):
|
295 |
for item in data:
|
296 |
+
_extract(item, dict(current_data))
|
297 |
|
298 |
_extract(data)
|
299 |
return '\n'.join(current_content)
|
|
|
311 |
elif file_extension == ".asset":
|
312 |
with open(inputFile, 'r', encoding='utf-8') as f:
|
313 |
content = json.load(f)
|
314 |
+
return extract_text_from_game2(content) if extract_text_from_game(content) != '' else extract_text_from_game(content)
|
315 |
else:
|
316 |
raise ValueError(f"Unsupported file format: {file_extension}")
|
317 |
|
|
|
387 |
]
|
388 |
with gr.Blocks() as app:
|
389 |
gr.Markdown(
|
390 |
+
'# Bang Dream全员TTS,使用本模型请严格遵守法律法规!\n发布二创作品请标注本项目作者及链接、作品使用Bert-VITS2 AI生成!\n <a href='https://nijigaku.top/2023/10/03/BangDreamTTS/'>使用以及本地部署指南</a> '
|
391 |
)
|
392 |
for band in BandList:
|
393 |
with gr.TabItem(band):
|
|
|
444 |
with gr.Row():
|
445 |
with gr.Column():
|
446 |
gr.Markdown(
|
447 |
+
f"从 <a href='https://huggingface.co/spaces/Mahiruoshi/BangDream-Bert-VITS2/filelists'>filelists文件夹</a> 查看示例\n游戏脚本见<a href='https://bestdori.com/tool/explorer/asset/cn/scenario'>bestdori</a>"
|
448 |
)
|
449 |
inputFile = gr.inputs.File(label="上传游戏脚本(日文)、中文脚本(需设置角色对应关系)、自制文、(需设置角色对应关系")
|
450 |
groupSize = gr.Slider(
|