refactor: optimize the display of SST nodes

This commit is contained in:
wxg0103 2024-12-19 17:27:55 +08:00 committed by wxg
parent c000ee4a82
commit cc078ec353
3 changed files with 25 additions and 10 deletions

View File

@ -70,7 +70,7 @@ class BaseDocumentExtractNode(IDocumentExtractNode):
# 回到文件头
buffer.seek(0)
file_content = split_handle.get_content(buffer, save_image)
content.append('## ' + doc['name'] + '\n' + file_content)
content.append('### ' + doc['name'] + '\n' + file_content)
break
return NodeResult({'content': splitter.join(content)}, {})

View File

@ -14,7 +14,6 @@ from common.util.common import split_and_transcribe, any_to_mp3
from dataset.models import File
from setting.models_provider.tools import get_model_instance_by_model_user_id
class BaseSpeechToTextNode(ISpeechToTextNode):
def save_context(self, details, workflow_manage):
@ -37,7 +36,8 @@ class BaseSpeechToTextNode(ISpeechToTextNode):
temp_mp3_path = temp_amr_file.name
any_to_mp3(temp_file_path, temp_mp3_path)
try:
return split_and_transcribe(temp_mp3_path, model)
transcription = split_and_transcribe(temp_mp3_path, model)
return {file.file_name: transcription}
finally:
os.remove(temp_file_path)
os.remove(temp_mp3_path)
@ -45,10 +45,17 @@ class BaseSpeechToTextNode(ISpeechToTextNode):
def process_audio_items(audio_list, model):
with ThreadPoolExecutor(max_workers=5) as executor:
results = list(executor.map(lambda item: process_audio_item(item, model), audio_list))
return '\n\n'.join(results)
return results
result = process_audio_items(audio_list, stt_model)
return NodeResult({'answer': result, 'result': result}, {})
content = []
result_content = []
for item in result:
for key, value in item.items():
content.append(f'### {key}\n{value}')
result_content.append(value)
return NodeResult({'answer': '\n'.join(result_content), 'result': '\n'.join(result_content),
'content': content}, {})
def get_details(self, index: int, **kwargs):
return {
@ -56,6 +63,7 @@ class BaseSpeechToTextNode(ISpeechToTextNode):
"index": index,
'run_time': self.context.get('run_time'),
'answer': self.context.get('answer'),
'content': self.context.get('content'),
'type': self.node.type,
'status': self.status,
'err_message': self.err_message,

View File

@ -293,15 +293,22 @@
<div class="card-never border-r-4">
<h5 class="p-8-12">参数输出</h5>
<div class="p-8-12 border-t-dashed lighter">
<p class="mb-8 color-secondary">文本内容:</p>
<div v-if="item.answer">
<el-card
shadow="never"
style="--el-card-padding: 8px"
v-for="(file_content, index) in item.content"
:key="index"
class="mb-8"
>
<MdPreview
v-if="file_content"
ref="editorRef"
editorId="preview-only"
:modelValue="item.answer"
:modelValue="file_content"
style="background: none"
/>
</div>
<template v-else> -</template>
</el-card>
</div>
</div>
</template>
@ -544,7 +551,7 @@
:modelValue="item.answer"
style="background: none"
/>
<template v-else> - </template>
<template v-else> -</template>
</div>
</div>
</template>