Commit b19b752c authored by Administrator's avatar Administrator

增加分镜模式

parent cd50ee18
...@@ -38,41 +38,41 @@ export default class utils { ...@@ -38,41 +38,41 @@ export default class utils {
static splitDetailText(sentences: string[]) { static splitDetailText(sentences: string[]) {
// console.log(sentences) // console.log(sentences)
let result_sentences: string[] = []; let result_sentences: string[] = [];
sentences.forEach(s => { let currentSentence = '';
if(s.length <= 15){ for (let i = 0; i < sentences.length; i++) {
result_sentences.push(s); const str = sentences[i];
} else { currentSentence += str + ',';
let detail_array = s.split(/[,|,]/); if (i < sentences.length - 1 && (currentSentence + sentences[i + 1]).length <= 15) {
let currentSentence = ''; continue;
for (let i = 0; i < detail_array.length; i++) {
const str = detail_array[i];
currentSentence += str + ',';
if (i < detail_array.length - 1 && (currentSentence + detail_array[i + 1]).length <= 15) {
continue;
}
result_sentences.push(currentSentence.endsWith(",") ? currentSentence.slice(0, -1) : currentSentence);
currentSentence = '';
}
// console.log('result_sentences=', result_sentences);
} }
}); result_sentences.push(currentSentence.endsWith(",") ? currentSentence.slice(0, -1) : currentSentence);
currentSentence = '';
}
// console.log('result_sentences=', result_sentences);
return result_sentences; return result_sentences;
} }
// 拆分文本 // 拆分文本
static splitText(str: string) { static splitText(str: string, type: string = 'default') {
str = str.replaceAll('“','').replaceAll('”','') str = str.replaceAll('“','').replaceAll('”','')
// 使用正则表达式拆分文本 // 使用正则表达式拆分文本
let sentences = str.split(/[!|?|。|!|?]/); let sentences: string[] = [];
if(type == 'default'){
sentences = str.split(/[!|?|。|!|?]/);
} else {
sentences = str.split(/[!|?|。|!|?|,|,]/);
}
// 过滤掉长度为 0 的句子 // 过滤掉长度为 0 的句子
sentences = sentences.filter(s => s.length > 0); sentences = sentences.filter(s => s.length > 0);
// 过滤掉只包含标点符号的句子 // 过滤掉只包含标点符号的句子
sentences = sentences.filter(s => !utils.containsOnlyPunctuation(s)); sentences = sentences.filter(s => !utils.containsOnlyPunctuation(s));
// console.log(sentences) if(type == 'default'){
// return sentences return sentences
let detailSplit = utils.splitDetailText(sentences); } else {
return detailSplit; let detailSplit = utils.splitDetailText(sentences);
return detailSplit;
}
} }
// 拆分英文文本 // 拆分英文文本
......
...@@ -250,7 +250,7 @@ const onAdaptRolesKeywords = async () => { ...@@ -250,7 +250,7 @@ const onAdaptRolesKeywords = async () => {
}; };
const onAdapt = async () => { const onAdapt = async (type: string) => {
if (!form.chatgpt_answer || form.chatgpt_answer.length == 0) { if (!form.chatgpt_answer || form.chatgpt_answer.length == 0) {
ElMessage({ ElMessage({
message: "文案不能为空", message: "文案不能为空",
...@@ -264,7 +264,7 @@ const onAdapt = async () => { ...@@ -264,7 +264,7 @@ const onAdapt = async () => {
console.log('分镜,生成task_id=', form.task_id) console.log('分镜,生成task_id=', form.task_id)
} }
// 按标点拆分成分镜 // 按标点拆分成分镜
const sentences = utils.splitText(form.chatgpt_answer); const sentences = utils.splitText(form.chatgpt_answer, type);
// console.log(sentences.length) // console.log(sentences.length)
// 分镜 // 分镜
form.adapt_result_json = [] form.adapt_result_json = []
...@@ -1633,7 +1633,10 @@ const onSubmitInPaint = async () => { ...@@ -1633,7 +1633,10 @@ const onSubmitInPaint = async () => {
</el-form-item> </el-form-item>
<!-- 分镜 --> <!-- 分镜 -->
<el-form-item> <el-form-item>
<el-button type="primary" @click="onAdapt">分镜</el-button> <el-button type="primary" @click="onAdapt('default')">分镜:标准模式</el-button>
<el-button type="primary" @click="onAdapt('more_scene')"
>分镜:更多场景模式</el-button
>
<el-button type="primary" @click="onAdaptScene" <el-button type="primary" @click="onAdaptScene"
>推理场景({{ tuili_llm.name }})</el-button >推理场景({{ tuili_llm.name }})</el-button
> >
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment