Commit b15284cb authored by 周成波's avatar 周成波

edit

parent 7831c281
<script setup lang="ts">
import { onMounted, reactive, ref } from "vue";
import { ElMessage } from "element-plus";
import text2videoService from "@/api/service/text2videoService";
import utils from "@/utils/utils";
const loading = ref(false);
const form = reactive({
chatgpt_prompt: "帮我生成一个关于医生穿越到古代行侠仗义的故事,约200字左右",
chatgpt_answer:
"曾经的医生王强穿越回了古代,发现这个时代正值战乱时期。他觉得自己是时候行侠仗义,保护那些无辜受苦的人们了。王强在一个村庄里遇到了一个年轻的农民,叫李明。李明父母在战乱中被杀,他成了孤儿,并且被恶势力欺压。王强决定帮助李明。他教授李明一些基本的医术,并且帮助他恢复村庄的秩序。为了支援农民,王强到处奔走,为那些受伤的人们进行治疗。他在古代用现代医学知识,快速治愈了一些以前无法治愈的疾病。他趁机收集了一群志同道合的人,组建了一个抗击恶势力的义勇军。由于他的医术悉心教导,王强手下的队伍战斗力大增,并且开始挑战恶势力的统治。在战斗中,王强发现一支正义的侠盗团队正在保护受苦的人们。他决定与他们合作,将农民们和侠盗团队联合起来,共同对抗恶势力。最终,王强和他的队伍,还有侠盗团队成功地将恶势力赶出了村庄,恢复了和平。他们在古代留下了无穷的传奇,为人们带来了新的希望和幸福。医生王强也与李明成了好朋友,他们一起守护着村庄的和平与安宁。",
adapt_restrict: '',
adapt_result: {
"task_id": "20240131095112500",
"task_info": [
{
"scene_no": "1",
"scene_describe": "曾经的医生王强穿越回了古代,发现这个时代正值战乱时期。",
"scene_keyword": "古代,时空穿越,未知时间段,室内",
"characters": "王强",
"characters_keyword": "男性,中年,普通人装扮,短发,黑色,平静,站立",
"image_promt":
"Wang Qiang found himself standing in an unfamiliar room. The dimly lit interior had an ancient feel to it, with wooden beams and ornate decorations adorning the room. Wang Qiang, a middle-aged man dressed in ordinary clothes, was startled by his sudden transportation through time and space. Although a bit confused, he remained calm and composed. Standing in the room, he observed his surroundings, trying to figure out which era he had arrived in.",
"domain_image_path":
"http://wm_tools_backend.frp.wmdigit.com:8888/assets/outputs/20240131095112500/img/1.png",
"local_image_path": "assets/outputs/20240131095112500/img/1.png",
},
{
"scene_no": "2",
"scene_describe": "他觉得自己是时候行侠仗义,保护那些无辜受苦的人们了。",
"scene_keyword": "古代,战乱时期,白天,村庄",
"characters": "王强,受苦的人们",
"characters_keyword": "男性,中年,普通人装扮,短发,黑色,平静,站立 - 众人,年轻,农民装扮,短发,黑色,悲伤,跪地",
"image_promt":
"Scene: War-torn VillageCharacters:Wang Qiang - Male, Middle-aged, Commoner attire, Short hair, Black, Calm, StandingLi Ming - Male, Young, Peasant attire, Short hair, Black, Sad, KneelingWang Qiang stands in the ruins of the war-torn village, observing the destruction surrounding him. The once peaceful village now lies in ruins, with burnt houses and debris scattered everywhere. It is daytime, and the sun casts a gloomy light on the desolate scene.Nearby, Li Ming is seen kneeling on the ground, his head bowed in sorrow. His worn-out farmer's clothes reflect the hardships he has endured. His face, covered in dirt and tears, reveals the deep sadness in his heart. His farm tools lie abandoned next to him, useless in the chaos of war.Wang Qiang remains calm, his eyes filled with determination as he surveys the devastation. Despite the turmoil and despair, he stands tall, his resilience evident. As a middle-aged man, he carries the weight of the village's hopes and dreams on his shoulders, fighting bravely to protect what is left.Meanwhile, Li Ming's youthful innocence and optimism have been shattered by the brutality of war. Kneeling on the ground, he clings onto the fading memories of the peaceful past. The loss and grief he feels are evident in his posture, his trembling hands clasped in prayer, as he seeks solace in a higher power.In this war-torn village, Wang Qiang and Li Ming represent the contrast between the resilience of experience and the vulnerability of youth. They stand as symbols of the collective struggle and resilience of the villagers, amidst the chaos and destruction brought upon by the ancient era of war.",
"domain_image_path":
"http://wm_tools_backend.frp.wmdigit.com:8888/assets/outputs/20240131095112500/img/2.png",
"local_image_path": "assets/outputs/20240131095112500/img/2.png",
},
]
},
final_video: "",
});
const sd_prompt_prefix = `best quality,masterpiece,realistic,HDR,UHD,8K,best quality,highres,absurdres,realistic,masterpiece,
Highly detailed,extreme detail description,Professional,cinematic_lighting,ultra-fine painting,full body,
Vivid Colors,physically-based rendering,cinematic,`;
const sd_negative_prompt_prefix = `multiple breasts, (mutated hands and fingers:1.5 ), (long body :1.3),
(mutation, poorly drawn :1.2) , black-white, bad anatomy, liquid body, liquid tongue, disfigured,
malformed, mutated, anatomical nonsense, malformed hands, long neck, blurred,
lowers, bad proportions, bad shadow, uncoordinated body, unnatural body, fused breasts,
bad breasts, huge breasts, poorly drawn breasts, extra breasts, liquid breasts, heavy breasts, missing breasts,
huge haunch, huge thighs, huge calf, bad hands, fused hand, missing hand, disappearing arms, disappearing thigh,
disappearing calf, disappearing legs, fused ears, bad ears, poorly drawn ears, extra ears, liquid ears, heavy ears,
missing ears, fused animal ears, bad animal ears, poorly drawn animal ears, extra animal ears, liquid animal ears,
heavy animal ears, missing animal ears, text, ui, error, missing fingers, missing limb, fused fingers,
one hand with more than 5 fingers, one hand with less than 5 fingers, one hand with more than 5 digit,
one hand with less than 5 digit, extra digit, fewer digits, fused digit, missing digit, bad digit, liquid digit,
colorful tongue, black tongue, cropped, watermark, username, blurry, JPEG artifacts, signature, 3D, 3D game,
3D game scene, 3D character, malformed feet, extra feet, bad feet, poorly drawn feet, fused feet, missing feet,
extra shoes, bad shoes, fused shoes, more than two shoes, poorly drawn shoes, bad gloves, poorly drawn gloves,
fused gloves, bad cum, poorly drawn cum, fused cum, bad hairs, poorly drawn hairs, fused hairs, big muscles, ugly,
bad face, fused face, poorly drawn face, cloned face, big face, long face, bad eyes, fused eyes poorly drawn eyes,
extra eyes, malformed limbs, more than 2 nipples, missing nipples, different nipples, fused nipples, bad nipples,
poorly drawn nipples, black nipples, colorful nipples, gross proportions. short arm, (((missing arms))), missing thighs,
missing calf, missing legs, mutation, duplicate, morbid, mutilated, poorly drawn hands, more than 1 left hand,
more than 1 right hand, deformed, (blurry), disfigured, missing legs, extra arms, extra thighs, more than 2 thighs,
extra calf, fused calf, nsfw,logo,text,extra legs, bad knee, extra knee, more than 2 legs, bad tails, bad mouth,
fused mouth, poorly drawn mouth, bad tongue, tongue within mouth, too long tongue, black tongue, big mouth, cracked mouth,
bad mouth, dirty face, dirty teeth, dirty pantie, fused pantie, poorly drawn pantie, fused cloth, poorly drawn cloth, bad pantie,
yellow teeth, thick lips, bad cameltoe, colorful cameltoe, bad asshole, poorly drawn asshole, fused asshole, missing asshole,
bad anus, bad pussy, bad crotch, bad crotch seam, fused anus, fused pussy, fused anus, fused crotch, poorly drawn crotch,
fused seam, poorly drawn anus, poorly drawn pussy, poorly drawn crotch, poorly drawn crotch seam, bad thigh gap, missing thigh gap,
fused thigh gap, liquid thigh gap, poorly drawn thigh gap, poorly drawn anus, bad collarbone, fused collarbone, missing collarbone,
liquid collarbone, obesity, worst quality, low quality, normal quality, liquid tentacles, bad tentacles, poorly drawn tentacles,
split tentacles, fused tentacles, missing clit, bad clit, fused clit, colorful clit, black clit, liquid clit, QR code, bar code, censored,
safety panties, safety knickers, beard, furry ,pony, pubic hair, mosaic, excrement, faeces, shit, futa, testis,mutated hands and fingers,
deformed,bad anatomy,disfigured,poorly drawn face,lowres,mutated,extra limb,ugly,poorly drawn hands,missing limb,floating limbs,
disconnected limbs,malformed hands,out of focus,long neck,long body,gape,`;
onMounted(() => { });
const onSubmitGpt = () => {
text2videoService
.submitGpt(form.chatgpt_prompt)
.then((result: string) => {
// console.log(result);
form.chatgpt_answer = result;
})
.catch((error: any) => {
// console.error(error);
ElMessage({
message: error,
type: "error",
});
});
};
const onAdapt = async () => {
if (!form.chatgpt_answer) {
ElMessage({
message: "内容不能为空",
type: "error",
});
return;
}
loading.value = true;
const task_id = utils.genDateTimeStr();
form.adapt_result.task_id = task_id;
// 分镜
const sentences = utils.splitText(form.chatgpt_answer);
form.adapt_result.task_info = []
for (let i = 0; i < sentences.length; i++) {
form.adapt_result.task_info.push({
scene_no: (i + 1).toString(),
scene_describe: sentences[i],
scene_keyword: "",
characters: "",
characters_keyword: "",
image_promt: "",
domain_image_path: "",
local_image_path: "",
});
if (i == 2){
break;
}
}
console.log(form.adapt_result)
// 循环处理每个分镜:生成关键字、翻译、绘图
const taskPromises = form.adapt_result.task_info.map(async (item) => {
// 生成关键字
try {
const adapt_restrict = `以上是一个短视频故事,请理解整个故事,以及本镜头“${item.scene_describe}”的内容,给出:场景(年代,空间,时间段,地理环境,天气,物品,人物,镜头角度)、角色、角色关键词(性别,年龄,肤色,衣服,发型,发色,脸色,五官特点,体态,情绪,肢体动作)。`;
const scene_describe = await text2videoService.submitGpt(form.chatgpt_answer + "\n" + adapt_restrict);
item.scene_keyword = scene_describe;
const sd_describe = await text2videoService.submitGpt(`${scene_describe}\n请将以上内容翻译为英文,结果必须全部为英文,不允许包含中文。`);
item.image_promt = sd_describe;
const sd_prompt = item.image_promt + "," + sd_prompt_prefix;
const sd_img = await text2videoService.submitSD(task_id, item.scene_no, sd_prompt, sd_negative_prompt_prefix);
item.domain_image_path = sd_img.domain_image_path;
console.log(form.adapt_result)
} catch (error) {
ElMessage({
message: String(error),
type: "error",
});
return {
scene_keyword: "",
characters: "",
characters_keyword: "",
};
}
});
};
const onDrawOne = (idxStr: string) => {
const idx = parseInt(idxStr) - 1;
// const task_id = form.ai_draw_json.task_id;
// // console.log(task_id)
// const newResult = form.ai_draw_json.task_info[idx].画面描述词;
// const sd_prompt = newResult + "," + sd_prompt_prefix;
// text2videoService
// .submitSD(task_id, idxStr, sd_prompt, sd_negative_prompt_prefix)
// .then((result: string) => {
// // console.log(result);
// form.ai_draw_json.task_info[idx].本镜配图 = "";
// form.ai_draw_json.task_info[idx].本镜配图 = result;
// })
// .catch((error: any) => {
// // console.error(error);
// ElMessage({
// message: error,
// type: "error",
// });
// });
};
// const onGenVideo = () => {
// // ElMessage({
// // message: "开发中",
// // type: "error",
// // });
// // return;
// const video_param_items = form.ai_draw_json.task_info.map(item => {
// return {
// idx: item.编号,
// text: item.场景描述,
// img_path: item.本镜配图
// };
// });
// const video_param = {
// task_id: form.ai_draw_json.task_id,
// task_info: video_param_items
// }
// console.log(video_param)
// text2videoService
// .submitGenVideo(video_param)
// .then((result: string) => {
// // console.log(result);
// form.final_video = result;
// })
// .catch((error: any) => {
// // console.error(error);
// ElMessage({
// message: error,
// type: "error",
// });
// });
// };
</script>
<template>
<main class="home-container">
<!-- 标题 -->
<el-divider content-position="left">text2video</el-divider>
<el-form :model="form" label-width="114px">
<!-- 小说到文案 -->
<el-form-item label="小说">
<el-input v-model="form.chatgpt_prompt" :autosize="true" type="textarea" placeholder="输入小说" />
</el-form-item>
<el-form-item>
<el-button type="primary" @click="onSubmitGpt">提交chatgpt,生成文案</el-button>
</el-form-item>
<el-form-item label="文案">
<el-input v-model="form.chatgpt_answer" :autosize="true" type="textarea" />
</el-form-item>
<!-- 文案到分镜 -->
<el-form-item label="分镜要求">
<el-input v-model="form.adapt_restrict" :autosize="true" type="textarea" placeholder="" />
</el-form-item>
<el-form-item>
<el-button type="primary" @click="onAdapt">提交chatgpt,生成分镜</el-button>
</el-form-item>
<el-form-item label="分镜">
<el-table :data="form.adapt_result.task_info" border style="width: 100%; z-index: calc(var(--el-table-index) -1)">
<el-table-column prop="scene_no" label="编号" width="60" />
<el-table-column prop="scene_describe" label="场景描述">
<template v-slot="scope">
<el-input v-model="scope.row.scene_describe" :autosize="true" type="textarea"></el-input>
</template>
</el-table-column>
<el-table-column prop="scene_keyword" label="场景关键词">
<template v-slot="scope">
<el-input v-model="scope.row.scene_keyword" :autosize="true" type="textarea"></el-input>
</template>
</el-table-column>
<el-table-column prop="image_promt" label="画面描述词">
<template v-slot="scope">
<el-input v-model="scope.row.image_promt" :autosize="true" type="textarea"></el-input>
</template>
</el-table-column>
<el-table-column prop="domain_image_path" label="本镜配图">
<template v-slot="scope">
<div>
<el-image :src="scope.row.domain_image_path" :zoom-rate="1.2" :max-scale="1.5" :min-scale="0.5"
:preview-src-list="[scope.row.domain_image_path]" fit="cover" :hide-on-click-modal="true" />
</div>
</template>
</el-table-column>
<el-table-column width="100" label="操作">
<template v-slot="scope">
<el-button type="primary" size="small" @click="onDrawOne(scope.row.scene_no)">重绘本镜</el-button>
</template>
</el-table-column>
</el-table>
</el-form-item>
</el-form>
</main>
</template>
<style lang="scss" scoped>
.home-container {
width: 100%;
}
</style>
<style lang="scss">
.home-container {
.el-table .el-table__cell {
z-index: calc(var(--el-table-index) -1);
}
}
</style>
<script setup lang="ts">
import { onMounted, reactive, ref } from "vue";
import { Sunny, UploadFilled } from "@element-plus/icons-vue";
import { ElMessage, ElLoading } from "element-plus";
import text2videoService from "@/api/service/text2videoService";
import utils from "@/utils/utils";
const loading = ref(false);
const step = ref(1);
const is_adapt_result_json = ref(1);
const form = reactive({
chatgpt_prompt: "帮我生成一个关于医生穿越到古代行侠仗义的故事,约200字左右",
chatgpt_answer:
"曾经的医生王强穿越回了古代,发现这个时代正值战乱时期。他觉得自己是时候行侠仗义,保护那些无辜受苦的人们了。王强在一个村庄里遇到了一个年轻的农民,叫李明。李明父母在战乱中被杀,他成了孤儿,并且被恶势力欺压。王强决定帮助李明。他教授李明一些基本的医术,并且帮助他恢复村庄的秩序。为了支援农民,王强到处奔走,为那些受伤的人们进行治疗。他在古代用现代医学知识,快速治愈了一些以前无法治愈的疾病。他趁机收集了一群志同道合的人,组建了一个抗击恶势力的义勇军。由于他的医术悉心教导,王强手下的队伍战斗力大增,并且开始挑战恶势力的统治。在战斗中,王强发现一支正义的侠盗团队正在保护受苦的人们。他决定与他们合作,将农民们和侠盗团队联合起来,共同对抗恶势力。最终,王强和他的队伍,还有侠盗团队成功地将恶势力赶出了村庄,恢复了和平。他们在古代留下了无穷的传奇,为人们带来了新的希望和幸福。医生王强也与李明成了好朋友,他们一起守护着村庄的和平与安宁。",
adapt_restrict:
'将上述文案改编为10个短视频分镜,给出每个分镜的场景描述、场景关键词(年代,空间,时间段,地理环境,天气,物品,人物,镜头角度)、角色、角色关键词(性别,年龄,肤色,衣服,发型,发色,脸色,五官特点,体态,情绪,肢体动作)。以如下json字符串的格式返回:{"分镜":[{"编号":"","场景描述":"","场景关键词":"","角色":"","角色关键词":""},...]}',
adapt_result: "",
adapt_result_json: {
"task_id": "20240131095112500",
"task_info": [
{
"scene_no": "1",
"scene_describe": "曾经的医生王强穿越回了古代,发现这个时代正值战乱时期。",
"scene_keyword": "古代,时空穿越,未知时间段,室内",
"characters": "王强",
"characters_keyword": "男性,中年,普通人装扮,短发,黑色,平静,站立",
"image_promt":
"Wang Qiang found himself standing in an unfamiliar room. The dimly lit interior had an ancient feel to it, with wooden beams and ornate decorations adorning the room. Wang Qiang, a middle-aged man dressed in ordinary clothes, was startled by his sudden transportation through time and space. Although a bit confused, he remained calm and composed. Standing in the room, he observed his surroundings, trying to figure out which era he had arrived in.",
"domain_image_path":
"http://wm_tools_backend.frp.wmdigit.com:8888/assets/outputs/20240131095112500/img/1.png",
"local_image_path": "assets/outputs/20240131095112500/img/1.png",
},
{
"scene_no": "2",
"scene_describe": "他觉得自己是时候行侠仗义,保护那些无辜受苦的人们了。",
"scene_keyword": "古代,战乱时期,白天,村庄",
"characters": "王强,受苦的人们",
"characters_keyword": "男性,中年,普通人装扮,短发,黑色,平静,站立 - 众人,年轻,农民装扮,短发,黑色,悲伤,跪地",
"image_promt":
"Scene: War-torn VillageCharacters:Wang Qiang - Male, Middle-aged, Commoner attire, Short hair, Black, Calm, StandingLi Ming - Male, Young, Peasant attire, Short hair, Black, Sad, KneelingWang Qiang stands in the ruins of the war-torn village, observing the destruction surrounding him. The once peaceful village now lies in ruins, with burnt houses and debris scattered everywhere. It is daytime, and the sun casts a gloomy light on the desolate scene.Nearby, Li Ming is seen kneeling on the ground, his head bowed in sorrow. His worn-out farmer's clothes reflect the hardships he has endured. His face, covered in dirt and tears, reveals the deep sadness in his heart. His farm tools lie abandoned next to him, useless in the chaos of war.Wang Qiang remains calm, his eyes filled with determination as he surveys the devastation. Despite the turmoil and despair, he stands tall, his resilience evident. As a middle-aged man, he carries the weight of the village's hopes and dreams on his shoulders, fighting bravely to protect what is left.Meanwhile, Li Ming's youthful innocence and optimism have been shattered by the brutality of war. Kneeling on the ground, he clings onto the fading memories of the peaceful past. The loss and grief he feels are evident in his posture, his trembling hands clasped in prayer, as he seeks solace in a higher power.In this war-torn village, Wang Qiang and Li Ming represent the contrast between the resilience of experience and the vulnerability of youth. They stand as symbols of the collective struggle and resilience of the villagers, amidst the chaos and destruction brought upon by the ancient era of war.",
"domain_image_path":
"http://wm_tools_backend.frp.wmdigit.com:8888/assets/outputs/20240131095112500/img/2.png",
"local_image_path": "assets/outputs/20240131095112500/img/2.png",
},
]
},
final_video: "",
});
const sd_prompt_prefix = `best quality,masterpiece,realistic,HDR,UHD,8K,best quality,highres,absurdres,realistic,masterpiece,
Highly detailed,extreme detail description,Professional,cinematic_lighting,ultra-fine painting,full body,
Vivid Colors,physically-based rendering,cinematic,`;
const sd_negative_prompt_prefix = `multiple breasts, (mutated hands and fingers:1.5 ), (long body :1.3),
(mutation, poorly drawn :1.2) , black-white, bad anatomy, liquid body, liquid tongue, disfigured,
malformed, mutated, anatomical nonsense, malformed hands, long neck, blurred,
lowers, bad proportions, bad shadow, uncoordinated body, unnatural body, fused breasts,
bad breasts, huge breasts, poorly drawn breasts, extra breasts, liquid breasts, heavy breasts, missing breasts,
huge haunch, huge thighs, huge calf, bad hands, fused hand, missing hand, disappearing arms, disappearing thigh,
disappearing calf, disappearing legs, fused ears, bad ears, poorly drawn ears, extra ears, liquid ears, heavy ears,
missing ears, fused animal ears, bad animal ears, poorly drawn animal ears, extra animal ears, liquid animal ears,
heavy animal ears, missing animal ears, text, ui, error, missing fingers, missing limb, fused fingers,
one hand with more than 5 fingers, one hand with less than 5 fingers, one hand with more than 5 digit,
one hand with less than 5 digit, extra digit, fewer digits, fused digit, missing digit, bad digit, liquid digit,
colorful tongue, black tongue, cropped, watermark, username, blurry, JPEG artifacts, signature, 3D, 3D game,
3D game scene, 3D character, malformed feet, extra feet, bad feet, poorly drawn feet, fused feet, missing feet,
extra shoes, bad shoes, fused shoes, more than two shoes, poorly drawn shoes, bad gloves, poorly drawn gloves,
fused gloves, bad cum, poorly drawn cum, fused cum, bad hairs, poorly drawn hairs, fused hairs, big muscles, ugly,
bad face, fused face, poorly drawn face, cloned face, big face, long face, bad eyes, fused eyes poorly drawn eyes,
extra eyes, malformed limbs, more than 2 nipples, missing nipples, different nipples, fused nipples, bad nipples,
poorly drawn nipples, black nipples, colorful nipples, gross proportions. short arm, (((missing arms))), missing thighs,
missing calf, missing legs, mutation, duplicate, morbid, mutilated, poorly drawn hands, more than 1 left hand,
more than 1 right hand, deformed, (blurry), disfigured, missing legs, extra arms, extra thighs, more than 2 thighs,
extra calf, fused calf, nsfw,logo,text,extra legs, bad knee, extra knee, more than 2 legs, bad tails, bad mouth,
fused mouth, poorly drawn mouth, bad tongue, tongue within mouth, too long tongue, black tongue, big mouth, cracked mouth,
bad mouth, dirty face, dirty teeth, dirty pantie, fused pantie, poorly drawn pantie, fused cloth, poorly drawn cloth, bad pantie,
yellow teeth, thick lips, bad cameltoe, colorful cameltoe, bad asshole, poorly drawn asshole, fused asshole, missing asshole,
bad anus, bad pussy, bad crotch, bad crotch seam, fused anus, fused pussy, fused anus, fused crotch, poorly drawn crotch,
fused seam, poorly drawn anus, poorly drawn pussy, poorly drawn crotch, poorly drawn crotch seam, bad thigh gap, missing thigh gap,
fused thigh gap, liquid thigh gap, poorly drawn thigh gap, poorly drawn anus, bad collarbone, fused collarbone, missing collarbone,
liquid collarbone, obesity, worst quality, low quality, normal quality, liquid tentacles, bad tentacles, poorly drawn tentacles,
split tentacles, fused tentacles, missing clit, bad clit, fused clit, colorful clit, black clit, liquid clit, QR code, bar code, censored,
safety panties, safety knickers, beard, furry ,pony, pubic hair, mosaic, excrement, faeces, shit, futa, testis,mutated hands and fingers,
deformed,bad anatomy,disfigured,poorly drawn face,lowres,mutated,extra limb,ugly,poorly drawn hands,missing limb,floating limbs,
disconnected limbs,malformed hands,out of focus,long neck,long body,gape,`;
onMounted(() => { });
const onSubmitGpt = () => {
text2videoService
.submitGpt(form.chatgpt_prompt)
.then((result: string) => {
// console.log(result);
form.chatgpt_answer = result;
})
.catch((error: any) => {
// console.error(error);
ElMessage({
message: error,
type: "error",
});
});
};
const onAdapt = async () => {
if (!form.chatgpt_answer) {
ElMessage({
message: "内容不能为空",
type: "error",
});
return;
}
loading.value = true;
const task_id = utils.genDateTimeStr();
form.adapt_result_json.task_id = task_id;
// 开始分镜
text2videoService
.submitGpt(form.chatgpt_answer + "\n" + form.adapt_restrict)
.then(async (result: string) => {
console.log(result);
try {
const scene_result = utils.formatJsonObj(result).分镜
form.adapt_result_json.task_info = scene_result.map((item: any) => {
return {
scene_no: item.编号,
scene_describe: item.场景描述,
scene_keyword: item.场景关键词,
characters: item.角色,
characters_keyword: item.角色关键词,
};
});
// 分镜结束,开始逐个绘图
const taskPromises = form.adapt_result_json.task_info.map(async (item) => {
// 翻译英文场景
try {
const result = await text2videoService.submitGpt(
`场景描述为:${item.scene_describe}\n场景关键词为:${item.scene_keyword}\n场景中的角色有:${item.characters}\n角色关键词为:${item.characters_keyword}\n
请理解以上内容,并翻译为相应的英文场景,返回结果不允许有中文。`
);
// const newResult = result.replaceAll(".", "").replaceAll('"', "");
const newResult = result
// 提交SD绘图
try {
const sd_prompt = newResult + "," + sd_prompt_prefix;
const sd_result = await text2videoService.submitSD(
task_id,
item.scene_no,
sd_prompt,
sd_negative_prompt_prefix
);
return {
scene_no: item.scene_no,
image_promt: newResult,
domain_image_path: sd_result.domain_image_path,
local_image_path: sd_result.local_image_path,
};
} catch (error) {
ElMessage({
message: String(error),
type: "error",
});
return {
scene_no: item.scene_no,
image_promt: newResult,
domain_image_path: "",
local_image_path: "",
};
}
} catch (error) {
ElMessage({
message: String(error),
type: "error",
});
return {
scene_no: item.scene_no,
image_promt: "",
domain_image_path: "",
local_image_path: "",
};
}
});
// 所有请求都返回后,重新排序
try {
const results = await Promise.all(taskPromises);
form.adapt_result_json.task_info = results.sort((a, b) => parseInt(a.scene_no) - parseInt(b.scene_no));
console.log(form.adapt_result_json);
} catch (error) {
// 处理错误
ElMessage({
message: String(error),
type: "error",
});
}
} catch (error) {
form.adapt_result = result;
is_adapt_result_json.value = 0;
} finally {
// 最终关闭loading(无论成功或失败)
loading.value = false;
}
})
.catch((error: any) => {
console.error(error);
ElMessage({
message: error,
type: "error",
});
});
};
const onDrawOne = (idxStr: string) => {
const idx = parseInt(idxStr) - 1;
// const task_id = form.ai_draw_json.task_id;
// // console.log(task_id)
// const newResult = form.ai_draw_json.task_info[idx].画面描述词;
// const sd_prompt = newResult + "," + sd_prompt_prefix;
// text2videoService
// .submitSD(task_id, idxStr, sd_prompt, sd_negative_prompt_prefix)
// .then((result: string) => {
// // console.log(result);
// form.ai_draw_json.task_info[idx].本镜配图 = "";
// form.ai_draw_json.task_info[idx].本镜配图 = result;
// })
// .catch((error: any) => {
// // console.error(error);
// ElMessage({
// message: error,
// type: "error",
// });
// });
};
// const onGenVideo = () => {
// // ElMessage({
// // message: "开发中",
// // type: "error",
// // });
// // return;
// const video_param_items = form.ai_draw_json.task_info.map(item => {
// return {
// idx: item.编号,
// text: item.场景描述,
// img_path: item.本镜配图
// };
// });
// const video_param = {
// task_id: form.ai_draw_json.task_id,
// task_info: video_param_items
// }
// console.log(video_param)
// text2videoService
// .submitGenVideo(video_param)
// .then((result: string) => {
// // console.log(result);
// form.final_video = result;
// })
// .catch((error: any) => {
// // console.error(error);
// ElMessage({
// message: error,
// type: "error",
// });
// });
// };
</script>
<template>
<main class="home-container">
<!-- 标题 -->
<el-divider content-position="left">text2video</el-divider>
<el-form :model="form" label-width="114px">
<!-- 小说到文案 -->
<el-form-item label="小说">
<el-input v-model="form.chatgpt_prompt" :autosize="true" type="textarea" placeholder="输入小说" />
</el-form-item>
<el-form-item>
<el-button type="primary" @click="onSubmitGpt">提交chatgpt,生成文案</el-button>
</el-form-item>
<el-form-item label="文案">
<el-input v-model="form.chatgpt_answer" :autosize="true" type="textarea" />
</el-form-item>
<!-- 文案到分镜 -->
<el-form-item label="分镜要求">
<el-input v-model="form.adapt_restrict" :autosize="true" type="textarea" placeholder="" />
</el-form-item>
<el-form-item>
<el-button type="primary" @click="onAdapt">提交chatgpt,生成分镜</el-button>
</el-form-item>
<el-form-item label="分镜" v-if="is_adapt_result_json === 0">
<el-input v-model="form.adapt_result" :autosize="true" type="textarea" />
</el-form-item>
<el-form-item label="分镜" v-if="is_adapt_result_json === 1">
<el-table :data="form.adapt_result_json.task_info" border style="width: 100%; z-index: calc(var(--el-table-index) -1)">
<el-table-column prop="scene_no" label="编号" width="60" />
<el-table-column prop="scene_describe" label="场景描述">
<template v-slot="scope">
<el-input v-model="scope.row.scene_describe" :autosize="true" type="textarea"></el-input>
</template>
</el-table-column>
<el-table-column prop="scene_keyword" label="场景关键词">
<template v-slot="scope">
<el-input v-model="scope.row.scene_keyword" :autosize="true" type="textarea"></el-input>
</template>
</el-table-column>
<el-table-column prop="characters" label="角色">
<template v-slot="scope">
<el-input v-model="scope.row.characters" :autosize="true" type="textarea"></el-input>
</template>
</el-table-column>
<el-table-column prop="characters_keyword" label="角色关键词">
<template v-slot="scope">
<el-input v-model="scope.row.characters_keyword" :autosize="true" type="textarea"></el-input>
</template>
</el-table-column>
<el-table-column prop="image_promt" label="画面描述词">
<template v-slot="scope">
<el-input v-model="scope.row.image_promt" :autosize="true" type="textarea"></el-input>
</template>
</el-table-column>
<el-table-column prop="domain_image_path" label="本镜配图">
<template v-slot="scope">
<div>
<el-image :src="scope.row.domain_image_path" :zoom-rate="1.2" :max-scale="1.5" :min-scale="0.5"
:preview-src-list="[scope.row.domain_image_path]" fit="cover" :hide-on-click-modal="true" />
</div>
</template>
</el-table-column>
<el-table-column width="100" label="操作">
<template v-slot="scope">
<el-button type="primary" size="small" @click="onDrawOne(scope.row.scene_no)">重绘本镜</el-button>
</template>
</el-table-column>
</el-table>
</el-form-item>
</el-form>
</main>
</template>
<style lang="scss" scoped>
.home-container {
width: 100%;
}
</style>
<style lang="scss">
.home-container {
.el-table .el-table__cell {
z-index: calc(var(--el-table-index) -1);
}
}
</style>
declare namespace Wm {
interface ScriptsItem {
编号: string
场景描述: string
场景关键词: string
角色: string
角色关键词: string
}
interface AiDrawItem {
编号: string
场景描述: string
画面描述词: string
本镜配图: string
task_id: string
}
interface GenVideo {
task_id: string
task_info: GenVideoItem[]
}
interface GenVideoItem {
idx: string
text: string
img_path: string
}
}
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