【增加】StableDiffusion

This commit is contained in:
cherishsince 2024-06-21 15:26:08 +08:00
parent 918f35f824
commit 33366efe11
2 changed files with 301 additions and 2 deletions

View File

@ -11,6 +11,7 @@
@on-draw-start="handlerDrawStart"
@on-draw-complete="handlerDrawComplete" />
<Midjourney v-if="selectModel === 'MJ绘画'" />
<StableDiffusion v-if="selectModel === 'Stable Diffusion'" />
</div>
</div>
<div class="main">
@ -23,14 +24,15 @@
// TODO @fan /views/ai/image/index /views/ai/image/manager
import Dall3 from './dall3/index.vue'
import Midjourney from './midjourney/index.vue'
import StableDiffusion from './stable-diffusion/index.vue'
import ImageTask from './ImageTask.vue'
// ref
const imageTaskRef = ref<any>() // image task ref
//
const selectModel = ref('DALL3绘画')
const modelOptions = ['DALL3绘画', 'MJ绘画']
const selectModel = ref('Stable Diffusion')
const modelOptions = ['DALL3绘画', 'MJ绘画', 'Stable Diffusion']
const drawIn = ref<boolean>(false) //
/** 绘画 - start */

View File

@ -0,0 +1,297 @@
<!-- dall3 -->
<template>
<div class="prompt">
<el-text tag="b">画面描述</el-text>
<el-text tag="p">建议使用形容词+动词+风格的格式使用隔开</el-text>
<!-- TODO @fanstyle 看看能不能哟 unocss 替代 -->
<el-input
v-model="prompt"
maxlength="1024"
rows="5"
style="width: 100%; margin-top: 15px;"
input-style="border-radius: 7px;"
placeholder="例如:童话里的小屋应该是什么样子?"
show-word-limit
type="textarea"
/>
</div>
<div class="hot-words">
<div>
<el-text tag="b">随机热词</el-text>
</div>
<el-space wrap class="word-list">
<el-button round
class="btn"
:type="(selectHotWord === hotWord ? 'primary' : 'default')"
v-for="hotWord in hotWords"
:key="hotWord"
@click="handlerHotWordClick(hotWord)"
>
{{ hotWord }}
</el-button>
</el-space>
</div>
<div class="group-item">
<div>
<el-text tag="b">采样</el-text>
</div>
<el-space wrap class="group-item-body">
<el-select
v-model="selectSampler"
placeholder="Select"
size="large"
style="width: 350px;"
>
<el-option
v-for="item in sampler"
:key="item.key"
:label="item.name"
:value="item.key"
/>
</el-select>
</el-space>
</div>
<div class="group-item">
<div>
<el-text tag="b">图片尺寸</el-text>
</div>
<el-space wrap class="group-item-body">
<el-select
v-model="selectImageSize"
placeholder="Select"
size="large"
style="width: 350px;"
>
<el-option
v-for="item in imageSizeList"
:key="item.key"
:label="item.key"
:value="item.key"
/>
</el-select>
</el-space>
</div>
<div class="group-item">
<div>
<el-text tag="b">迭代步数</el-text>
</div>
<el-space wrap class="group-item-body">
<el-input v-model="steps" type="number" size="large" style="width: 350px" placeholder="Please input" />
</el-space>
</div>
<div class="group-item">
<div>
<el-text tag="b">随机性</el-text>
</div>
<el-space wrap class="group-item-body">
<el-input v-model="seed" type="number" size="large" style="width: 350px" placeholder="Please input" />
</el-space>
</div>
<div class="btns">
<el-button type="primary"
size="large"
round
:loading="drawIn"
@click="handlerGenerateImage">
{{drawIn ? '生成中' : '生成内容'}}
</el-button>
</div>
</template>
<script setup lang="ts">
import {ImageApi, ImageDrawReqVO} from '@/api/ai/image';
// image
interface ImageModelVO {
key: string
name: string
}
// image
interface ImageSizeVO {
key: string
width: string,
height: string,
}
//
const prompt = ref<string>('') //
const drawIn = ref<boolean>(false) //
const selectHotWord = ref<string>('') //
const hotWords = ref<string[]>(['中国旗袍', '古装美女', '卡通头像', '机甲战士', '童话小屋', '中国长城']) //
const selectSampler = ref<any>({}) //
// message
const message = useMessage()
//
const sampler = ref<ImageModelVO[]>([
{
key: 'Euler a',
name: 'Euler a',
},
{
key: 'DPM++ 2S a Karras',
name: 'DPM++ 2S a Karras',
},
{
key: 'DPM++ 2M Karras',
name: 'DPM++ 2M Karras',
},
{
key: 'DPM++ SDE Karras',
name: 'DPM++ SDE Karras',
},
{
key: 'DPM++ 2M SDE Karras',
name: 'DPM++ 2M SDE Karras',
},
]) //
selectSampler.value = sampler.value[0]
const selectImageSize = ref<ImageSizeVO>({} as ImageSizeVO) // size
const imageSizeList = ref<ImageSizeVO[]>([
{
key: '512x512',
width: '512',
height: '512',
},
{
key: '1024x1024',
width: '1024',
height: '1024',
},
{
key: '1024x1792',
width: '1024',
height: '1792',
},
{
key: '1792x1024',
width: '1792',
height: '1024',
},
{
key: '2048x2048',
width: '2048',
height: '2048',
},
{
key: '720x1280',
width: '720',
height: '1280',
},
{
key: '1080x1920',
width: '1080',
height: '1920',
},
{
key: '1440x2560',
width: '1440',
height: '2560',
},
{
key: '2160x3840',
width: '2160',
height: '3840',
},
]) // size
selectImageSize.value = imageSizeList.value[0]
const steps = ref<number>(20) //
const seed = ref<number>(-1) //
// Props
const props = defineProps({})
// emits
const emits = defineEmits(['onDrawStart', 'onDrawComplete'])
// TODO @fan /** */~
// TODO @fanhandler handle
/** 热词 - click */
const handlerHotWordClick = async (hotWord: string) => {
//
if (selectHotWord.value == hotWord) {
selectHotWord.value = ''
return
}
//
selectHotWord.value = hotWord
//
prompt.value = hotWord
}
/** 图片生产 */
const handlerGenerateImage = async () => {
//
await message.confirm(`确认生成内容?`)
try {
//
drawIn.value = true
//
emits('onDrawStart', 'StableDiffusion')
const form = {
platform: 'StableDiffusion',
model: 'stable-diffusion-v1-6',
prompt: prompt.value, //
width: selectImageSize.value.width, //
height: selectImageSize.value.height, //
options: {
sampler: selectSampler.value.key, //
seed: seed.value, //
steps: steps.value, //
},
} as ImageDrawReqVO
//
await ImageApi.drawImage(form)
} finally {
//
emits('onDrawComplete', 'StableDiffusion')
//
drawIn.value = false
}
}
</script>
<style scoped lang="scss">
//
.prompt {
}
//
.hot-words {
display: flex;
flex-direction: column;
margin-top: 30px;
.word-list {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: start;
margin-top: 15px;
.btn {
margin: 0;
}
}
}
//
.group-item {
margin-top: 30px;
.group-item-body {
margin-top: 15px;
width: 100%;
}
}
.btns {
display: flex;
justify-content: center;
margin-top: 50px;
}
</style>