Commit 6dd93cc2 authored by Administrator's avatar Administrator

modify index_en

parent 25d59794
...@@ -27,14 +27,32 @@ const form = reactive({ ...@@ -27,14 +27,32 @@ const form = reactive({
const sd_prompt_prefix = default_data.sd_prompt_prefix; const sd_prompt_prefix = default_data.sd_prompt_prefix;
const sd_negative_prompt_prefix = default_data.sd_negative_prompt_prefix; const sd_negative_prompt_prefix = default_data.sd_negative_prompt_prefix;
const tyqw = {'api': 'tyqw', 'name':'通义千问'};
const baichuan = {'api': 'langchain', 'name':'baichuan2-7b'};
const qwen = {'api': 'langchain', 'name':'Qwen-7B-Chat'};
const wenan_llm = qwen.api
const wenan_llm_name = qwen.name
const role_llm = tyqw.api
const role_llm_name = tyqw.name
const role_keywords_llm = qwen.api
const role_keywords_llm_name = qwen.name
const tuili_llm = qwen.api
const tuili_llm_name = qwen.name
const fanyi_llm = qwen.api
const fanyi_llm_name = qwen.name
onMounted(() => { onMounted(() => {
// 初始化示例数据 // 初始化示例数据
onChangeScreen(form.screen); onChangeScreen(form.screen);
}); });
const delay = (ms: any) => new Promise(res => setTimeout(res, ms));
const onSubmitGpt = () => { const onSubmitGpt = () => {
text2videoService text2videoService
.submitGpt(form.chatgpt_prompt) .submitGpt(form.chatgpt_prompt, wenan_llm)
.then((result: string) => { .then((result: string) => {
console.log(form.chatgpt_prompt); console.log(form.chatgpt_prompt);
console.log(result); console.log(result);
...@@ -59,28 +77,47 @@ const onAdaptRoles = async () => { ...@@ -59,28 +77,47 @@ const onAdaptRoles = async () => {
} }
loading.value = true; loading.value = true;
// 推理角色 // 推理角色
form.chatgpt_answer_roles = [];
try { try {
const adapt_restrict = ` const adapt_restrict = `
Instructions: Instructions:
Please understand this story and provide all the characters and key words (gender (can be supplemented with imagination, but must be clear), age (can be supplemented with imagination, but must be clear), race (can be supplemented with imagination, but must be clear), Please understand this story and provide all the characters in it, with multiple characters separated by commas`;
skin color (can be supplemented with imagination, but must be clear), clothing (can be supplemented with imagination, but must be clear), hairstyle (can be supplemented with imagination, but must be clear), hair color (can be supplemented with imagination, but must be clear), let roles = await text2videoService.submitGpt("story:\n" + form.chatgpt_answer + "\n" + adapt_restrict, role_llm);
facial features (can be supplemented with imagination, but must be clear). \n roles = roles.replace(/。/g, '').replace(/、/g, ',')
console.log(roles)
const roles_arr = roles.split(/[,,]/);
console.log(roles_arr)
async function processRoles() {
for (const one_role of roles_arr) {
await delay(100);
const adapt_keyword_restrict = `
Instructions:
Please understand this story and provide the keywords for the character "${one_role.trim()}" (gender (can be supplemented with imagination, but must have it), age (can be supplemented with imagination, but must have it),
Skin color (can be supplemented with imagination, but must have it), clothing (can be supplemented with imagination, but must have it), hairstyle (can be supplemented with imagination, but must have it),
Hair color (can be supplemented with imagination, but must have it), facial color (can be supplemented with imagination, but must have it), facial features (can be supplemented with imagination, but must have it).
Requirement: Requirement:
The roles and keywords should correspond. Keywords are separated by commas.
Strictly return in the following format: [{"Role": "", "Role Keywords": ""}]`; As long as the keyword is returned, no additional explanatory text is required.`;
const keywords = await text2videoService.submitGpt(form.chatgpt_answer + "\n" + adapt_restrict); let keywords = await text2videoService.submitGpt(form.chatgpt_answer + "\n" + adapt_keyword_restrict, role_keywords_llm);
// console.log(keywords) keywords = keywords.replace(/。/g, '').replace(/、/g, ',')
const keywords_obj = utils.formatJsonObj(keywords.replace(/```json/g, '').replace(/```/g, '')) form.chatgpt_answer_roles.push({
// console.log(keywords_obj) "角色": one_role.trim(),
form.chatgpt_answer_roles = [] "角色关键词": keywords.trim()+",dressed"
for (let item of keywords_obj) { });
let newObjItem = { }
"角色": JSON.stringify(item["Role"]).replace(/"/g, ''),
"角色关键词": JSON.stringify(item["Role Keywords"]).replace(/"/g, '')
};
form.chatgpt_answer_roles.push(newObjItem);
} }
try {
await processRoles();
console.log(form.chatgpt_answer_roles) console.log(form.chatgpt_answer_roles)
} catch (error) {
ElMessage({
message: String(error),
type: "error"
});
} finally {
loading.value = false; // 最终关闭loading(无论成功或失败)
}
} catch (error) { } catch (error) {
ElMessage({ ElMessage({
message: String(error), message: String(error),
...@@ -122,12 +159,10 @@ const onAdapt = async () => { ...@@ -122,12 +159,10 @@ const onAdapt = async () => {
} }
console.log(form.adapt_result_json) console.log(form.adapt_result_json)
const delay = (ms: any) => new Promise(res => setTimeout(res, ms));
async function processScenes() { async function processScenes() {
for (const item of form.adapt_result_json) { for (const item of form.adapt_result_json) {
await onAdaptOne(item); await onAdaptOne(item);
await delay(1000); await delay(100);
await onDrawOne(item); await onDrawOne(item);
} }
} }
...@@ -162,28 +197,39 @@ const onAdaptOne = async (item: any) => { ...@@ -162,28 +197,39 @@ const onAdaptOne = async (item: any) => {
try { try {
const adapt_restrict = ` const adapt_restrict = `
Instructions: Instructions:
Please understand this story and provide the following description for the scene: "${item.场景描述}": Please understand this story and provide the keywords for the scene "${item.场景描述}" (era (can be supplemented with imagination, but must be present), space (can be supplemented with imagination, but must be present),
scene keywords (era, space, time period, geographical environment, weather, objects, characters, camera angle) Time period (imagination can be used to supplement, but it must be present), geographical environment (imagination can be used to supplement, but it must be present), weather (imagination can be used to supplement, but it must be present),
characters (select the character in this scene from all characters) Items (can be supplemented with imagination, but must be present), characters (can be supplemented with imagination, but must be present), camera angles (can be supplemented with imagination, but must be present).
character keywords (select the character keywords for this scene from all characters and copy them as they are).
Requirement: Requirement:
The roles and keywords should correspond. Keywords are separated by commas.
Strictly return in the following format: [{"Scene Keywords": "(Multiple words separated by commas)", "Role": "(Characters separated by commas)", "Role Keywords": "(Give corresponding character keywords separately, multiple words separated by commas)"}] As long as the keyword is returned, no additional explanatory text is required.`;
Do not add any other instructions except for the content returned in format. const keywords = await text2videoService.submitGpt("story:\n" + form.chatgpt_answer + "\n" + adapt_restrict, tuili_llm);
`;
const keywords = await text2videoService.submitGpt("story:\n" + form.chatgpt_answer + "\nall characters:\n"+ JSON.stringify(form.chatgpt_answer_roles)+"\n" + adapt_restrict);
// console.log(keywords) // console.log(keywords)
const keywords_obj = utils.formatJsonObj(keywords.replace(/```json/g, '').replace(/```/g, '')) item.场景关键词 = keywords;
// console.log(keywords_obj)
item.场景关键词 = JSON.stringify(keywords_obj[0]["Scene Keywords"]).replace(/"/g, ''); const adapt_role_restrict = `
Instructions:
Please understand this story and for the scene: "${item.场景描述}", select the character in this scene from all the characters, with multiple characters separated by commas.`;
const item_roles = await text2videoService.submitGpt("story:\n" + form.chatgpt_answer + "\n all the characters: \n"+ JSON.stringify(form.chatgpt_answer_roles)+"\n" + adapt_role_restrict, tuili_llm);
// console.log(role_keywords)
if (form.chatgpt_answer_roles.length === 0) { if (form.chatgpt_answer_roles.length === 0) {
// 总角色为空 // 总角色为空
item.角色 = ''; item.角色 = '';
item.角色关键词 = ''; item.角色关键词 = '';
} else { } else {
// 总角色不为空 // 总角色不为空
item.角色 = JSON.stringify(keywords_obj[0]["Role"]).replace(/"/g, ''); item.角色 = item_roles;
item.角色关键词 = JSON.stringify(keywords_obj[0]["Role Keywords"]).replace(/"/g, ''); let role_kws = ""
const item_roles_arr = item_roles.split(/[,,]/);
item_roles_arr.forEach( one_item_role => {
// 人工指定角色关键词,包含则取
form.chatgpt_answer_roles.forEach(i => {
if (i["角色"].includes(one_item_role.trim()) || one_item_role.includes(i["角色"].trim())) {
role_kws = `${role_kws}${i["角色"]}${i["角色关键词"]}】`
}
})
})
item.角色关键词 = role_kws;
} }
} catch (error) { } catch (error) {
ElMessage({ ElMessage({
...@@ -215,7 +261,7 @@ const onDrawOne = async (item: any) => { ...@@ -215,7 +261,7 @@ const onDrawOne = async (item: any) => {
const sd_describe = await text2videoService.submitGpt( const sd_describe = await text2videoService.submitGpt(
`${temp_prompt} `${temp_prompt}
Instructions: Instructions:
Please understand the above content and return an English description.` Please understand the above content and return an English description.`, fanyi_llm
); );
item.画面描述词 = sd_describe; item.画面描述词 = sd_describe;
const sd_prompt = item.画面描述词 + "," + sd_prompt_prefix; const sd_prompt = item.画面描述词 + "," + sd_prompt_prefix;
...@@ -227,7 +273,11 @@ const onDrawOne = async (item: any) => { ...@@ -227,7 +273,11 @@ const onDrawOne = async (item: any) => {
} }
// console.log(sd_prompt); // console.log(sd_prompt);
// console.log(sd_negative_prompt_prefix); // console.log(sd_negative_prompt_prefix);
const sd_img = await text2videoService.submitSD(form.task_id, item.编号, sd_prompt, sd_negative_prompt_prefix, width, height); const sampler_index = "DPM++ SDE Karras";
const seed = "-1";
const steps = "6";
const cfg_scale = "2";
const sd_img = await text2videoService.submitSD(form.task_id, item.编号, sd_prompt, sd_negative_prompt_prefix, width, height, sampler_index, seed, steps, cfg_scale);
item.本镜配图 = sd_img.domain_image_path+"?v="+utils.genDateTimeStr(); item.本镜配图 = sd_img.domain_image_path+"?v="+utils.genDateTimeStr();
item.local_image_path = sd_img.local_image_path; item.local_image_path = sd_img.local_image_path;
} catch (error) { } catch (error) {
...@@ -375,14 +425,14 @@ const handleExceed: UploadProps['onExceed'] = (files) => { ...@@ -375,14 +425,14 @@ const handleExceed: UploadProps['onExceed'] = (files) => {
<el-input v-model="form.chatgpt_prompt" :autosize="true" type="textarea" /> <el-input v-model="form.chatgpt_prompt" :autosize="true" type="textarea" />
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button type="primary" @click="onSubmitGpt">生成文案</el-button> <el-button type="primary" @click="onSubmitGpt">生成文案{{wenan_llm_name}}</el-button>
</el-form-item> --> </el-form-item> -->
<el-form-item label="文案"> <el-form-item label="文案">
<el-input v-model="form.chatgpt_answer" :autosize="true" type="textarea" /> <el-input v-model="form.chatgpt_answer" :autosize="true" type="textarea" />
</el-form-item> </el-form-item>
<!-- 角色 --> <!-- 角色 -->
<el-form-item> <el-form-item>
<el-button type="primary" @click="onAdaptRoles">推理所有角色</el-button> <el-button type="primary" @click="onAdaptRoles">推理角色({{role_llm_name}})、推理角色关键词({{role_keywords_llm_name}}</el-button>
<el-button plain @click="clean_roles">清空总角色列表</el-button> <el-button plain @click="clean_roles">清空总角色列表</el-button>
</el-form-item> </el-form-item>
<el-form-item label="角色"> <el-form-item label="角色">
...@@ -401,7 +451,7 @@ const handleExceed: UploadProps['onExceed'] = (files) => { ...@@ -401,7 +451,7 @@ const handleExceed: UploadProps['onExceed'] = (files) => {
</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">分镜、推理场景关键词({{tuili_llm_name}})、英文描述({{fanyi_llm_name}})、绘图</el-button>
</el-form-item> </el-form-item>
<el-form-item label="分镜"> <el-form-item label="分镜">
<el-table :data="form.adapt_result_json" border style="width: 100%; z-index: calc(var(--el-table-index) -1)"> <el-table :data="form.adapt_result_json" border style="width: 100%; z-index: calc(var(--el-table-index) -1)">
...@@ -442,8 +492,8 @@ const handleExceed: UploadProps['onExceed'] = (files) => { ...@@ -442,8 +492,8 @@ const handleExceed: UploadProps['onExceed'] = (files) => {
</template> </template>
--> -->
<template v-slot="scope"> <template v-slot="scope">
<div style="margin: 10px 0"><el-button type="primary" size="default" @click="onAdaptOne(scope.row)">重新推理<br />关键字</el-button></div> <div style="margin: 10px 0"><el-button type="primary" size="default" @click="onAdaptOne(scope.row)">推理关键词</el-button></div>
<div style="margin: 10px 0"><el-button type="primary" size="default" @click="onDrawOne(scope.row)">重绘本镜</el-button></div> <div style="margin: 10px 0"><el-button type="primary" size="default" @click="onDrawOne(scope.row)">翻译、绘图</el-button></div>
<el-upload <el-upload
class="upload-demo" class="upload-demo"
ref="upload" ref="upload"
......
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