refactor: optimize the display of SST nodes
This commit is contained in:
parent
c000ee4a82
commit
cc078ec353
@ -70,7 +70,7 @@ class BaseDocumentExtractNode(IDocumentExtractNode):
|
|||||||
# 回到文件头
|
# 回到文件头
|
||||||
buffer.seek(0)
|
buffer.seek(0)
|
||||||
file_content = split_handle.get_content(buffer, save_image)
|
file_content = split_handle.get_content(buffer, save_image)
|
||||||
content.append('## ' + doc['name'] + '\n' + file_content)
|
content.append('### ' + doc['name'] + '\n' + file_content)
|
||||||
break
|
break
|
||||||
|
|
||||||
return NodeResult({'content': splitter.join(content)}, {})
|
return NodeResult({'content': splitter.join(content)}, {})
|
||||||
|
|||||||
@ -14,7 +14,6 @@ from common.util.common import split_and_transcribe, any_to_mp3
|
|||||||
from dataset.models import File
|
from dataset.models import File
|
||||||
from setting.models_provider.tools import get_model_instance_by_model_user_id
|
from setting.models_provider.tools import get_model_instance_by_model_user_id
|
||||||
|
|
||||||
|
|
||||||
class BaseSpeechToTextNode(ISpeechToTextNode):
|
class BaseSpeechToTextNode(ISpeechToTextNode):
|
||||||
|
|
||||||
def save_context(self, details, workflow_manage):
|
def save_context(self, details, workflow_manage):
|
||||||
@ -37,7 +36,8 @@ class BaseSpeechToTextNode(ISpeechToTextNode):
|
|||||||
temp_mp3_path = temp_amr_file.name
|
temp_mp3_path = temp_amr_file.name
|
||||||
any_to_mp3(temp_file_path, temp_mp3_path)
|
any_to_mp3(temp_file_path, temp_mp3_path)
|
||||||
try:
|
try:
|
||||||
return split_and_transcribe(temp_mp3_path, model)
|
transcription = split_and_transcribe(temp_mp3_path, model)
|
||||||
|
return {file.file_name: transcription}
|
||||||
finally:
|
finally:
|
||||||
os.remove(temp_file_path)
|
os.remove(temp_file_path)
|
||||||
os.remove(temp_mp3_path)
|
os.remove(temp_mp3_path)
|
||||||
@ -45,10 +45,17 @@ class BaseSpeechToTextNode(ISpeechToTextNode):
|
|||||||
def process_audio_items(audio_list, model):
|
def process_audio_items(audio_list, model):
|
||||||
with ThreadPoolExecutor(max_workers=5) as executor:
|
with ThreadPoolExecutor(max_workers=5) as executor:
|
||||||
results = list(executor.map(lambda item: process_audio_item(item, model), audio_list))
|
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)
|
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):
|
def get_details(self, index: int, **kwargs):
|
||||||
return {
|
return {
|
||||||
@ -56,6 +63,7 @@ class BaseSpeechToTextNode(ISpeechToTextNode):
|
|||||||
"index": index,
|
"index": index,
|
||||||
'run_time': self.context.get('run_time'),
|
'run_time': self.context.get('run_time'),
|
||||||
'answer': self.context.get('answer'),
|
'answer': self.context.get('answer'),
|
||||||
|
'content': self.context.get('content'),
|
||||||
'type': self.node.type,
|
'type': self.node.type,
|
||||||
'status': self.status,
|
'status': self.status,
|
||||||
'err_message': self.err_message,
|
'err_message': self.err_message,
|
||||||
|
|||||||
@ -293,15 +293,22 @@
|
|||||||
<div class="card-never border-r-4">
|
<div class="card-never border-r-4">
|
||||||
<h5 class="p-8-12">参数输出</h5>
|
<h5 class="p-8-12">参数输出</h5>
|
||||||
<div class="p-8-12 border-t-dashed lighter">
|
<div class="p-8-12 border-t-dashed lighter">
|
||||||
<p class="mb-8 color-secondary">文本内容:</p>
|
<el-card
|
||||||
<div v-if="item.answer">
|
shadow="never"
|
||||||
|
style="--el-card-padding: 8px"
|
||||||
|
v-for="(file_content, index) in item.content"
|
||||||
|
:key="index"
|
||||||
|
class="mb-8"
|
||||||
|
>
|
||||||
<MdPreview
|
<MdPreview
|
||||||
|
v-if="file_content"
|
||||||
ref="editorRef"
|
ref="editorRef"
|
||||||
editorId="preview-only"
|
editorId="preview-only"
|
||||||
:modelValue="item.answer"
|
:modelValue="file_content"
|
||||||
style="background: none"
|
style="background: none"
|
||||||
/>
|
/>
|
||||||
</div>
|
<template v-else> -</template>
|
||||||
|
</el-card>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -544,7 +551,7 @@
|
|||||||
:modelValue="item.answer"
|
:modelValue="item.answer"
|
||||||
style="background: none"
|
style="background: none"
|
||||||
/>
|
/>
|
||||||
<template v-else> - </template>
|
<template v-else> -</template>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user