【增加】ai 作图 other模块,临时提交

pull/478/MERGE
cherishsince 2024-07-10 18:50:34 +08:00
parent ece1533436
commit 20054b28c3
3 changed files with 380 additions and 1 deletions

View File

@ -0,0 +1,295 @@
<!-- dall3 -->
<template>
<div class="prompt">
<el-text tag="b">画面描述</el-text>
<el-text tag="p">建议使用形容词+动词+风格的格式使用隔开</el-text>
<el-input
v-model="prompt"
maxlength="1024"
rows="5"
class="w-100% mt-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 ImageHotWords"
:key="hotWord"
@click="handleHotWordClick(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="otherPlatform" placeholder="Select" size="large" class="!w-350px" @change="handlerPlatformChange">
<el-option
v-for="item in OtherPlatformEnum"
: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="model" placeholder="Select" size="large" class="!w-350px">
<el-option
v-for="item in models"
: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="stylePreset" placeholder="Select" size="large" class="!w-350px">
<el-option
v-for="item in stylePresetList"
: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-input v-model="width" class="w-170px" placeholder="图片宽度" />
<el-input v-model="height" class="w-170px" placeholder="图片高度" />
</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"
class="!w-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="scale"
type="number"
size="large"
class="!w-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"
class="!w-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">
<UploadImg v-model="referImageUrl" height="120px" width="120px" />
</el-space>
</div>
<div class="btns">
<el-button type="primary" size="large" round :loading="drawIn" @click="handleGenerateImage">
{{ drawIn ? '生成中' : '生成内容' }}
</el-button>
</div>
</template>
<script setup lang="ts">
import {ImageApi, ImageDrawReqVO, ImageVO} from '@/api/ai/image'
import {hasChinese} from '@/views/ai/utils/utils'
import {
AiPlatformEnum,
ImageHotWords, ImageModelVO, OtherPlatformEnum, TongYiWanXiangModels,
TongYiWanXiangStylePresets
} from '@/views/ai/utils/constants'
const message = useMessage() //
//
const drawIn = ref<boolean>(false) //
const selectHotWord = ref<string>('') //
//
const prompt = ref<string>('') //
const width = ref<number>(512) //
const height = ref<number>(512) //
const steps = ref<number>(20) //
const seed = ref<number>(42) //
const scale = ref<number>(7.5) //
const referImageUrl = ref<any>() //
const stylePreset = ref<string>('-1') //
const stylePresetList = ref<ImageModelVO[]>(TongYiWanXiangStylePresets) //
const otherPlatform = ref<string>(AiPlatformEnum.TONG_YI_WAN_XIANG) //
const models = ref<ImageModelVO[]>(TongYiWanXiangModels) //
const model = ref<string>(models.value[0].key) //
const emits = defineEmits(['onDrawStart', 'onDrawComplete']) // emits
/** 选择热词 */
const handleHotWordClick = async (hotWord: string) => {
//
if (selectHotWord.value == hotWord) {
selectHotWord.value = ''
return
}
//
selectHotWord.value = hotWord //
prompt.value = hotWord //
}
/** 图片生成 */
const handleGenerateImage = async () => {
//
await message.confirm(`确认生成内容?`)
try {
//
drawIn.value = true
//
emits('onDrawStart', AiPlatformEnum.STABLE_DIFFUSION)
//
const form = {
platform: otherPlatform.value,
model: '---', // 1
prompt: prompt.value, // 1
width: width.value, // 1
height: height.value, // 1
options: {
seed: seed.value, // 1
steps: steps.value, // 1
scale: scale.value, // 1
stylePreset: stylePreset.value, //
referImage: referImageUrl.value //
}
} as ImageDrawReqVO
await ImageApi.drawImage(form)
} finally {
//
emits('onDrawComplete', AiPlatformEnum.STABLE_DIFFUSION)
//
drawIn.value = false
}
}
/** 填充值 */
const settingValues = async (detail: ImageVO) => {
prompt.value = detail.prompt
width.value = detail.width
height.value = detail.height
seed.value = detail.options?.seed
steps.value = detail.options?.steps
scale.value = detail.options?.scale
stylePreset.value = detail.options?.stylePreset
}
/** 平台切换 */
const handlerPlatformChange = async (platform) => {
//
if (AiPlatformEnum.TONG_YI_WAN_XIANG === platform) {
models.value = TongYiWanXiangModels
stylePresetList.value = TongYiWanXiangStylePresets
} else {
models.value = []
stylePresetList.value = []
}
//
if (stylePresetList.value.length > 0) {
model.value = models.value[0].key
stylePreset.value = stylePresetList.value[0].key
} else {
model.value = ''
stylePreset.value = ''
}
}
/** 暴露组件方法 */
defineExpose({ settingValues })
</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>

View File

@ -18,6 +18,12 @@
ref="stableDiffusionRef"
@on-draw-complete="handleDrawComplete"
/>
<Other
v-if="selectPlatform === 'other'"
ref="otherRef"
@on-draw-complete="handleDrawComplete"
/>
</div>
</div>
<div class="main">
@ -33,11 +39,13 @@ import { ImageVO } from '@/api/ai/image'
import Dall3 from './components/dall3/index.vue'
import Midjourney from './components/midjourney/index.vue'
import StableDiffusion from './components/stableDiffusion/index.vue'
import Other from './components/other/index.vue'
const imageListRef = ref<any>() // image ref
const dall3Ref = ref<any>() // dall3(openai) ref
const midjourneyRef = ref<any>() // midjourney ref
const stableDiffusionRef = ref<any>() // stable diffusion ref
const otherRef = ref<any>() // stable diffusion ref
//
const selectPlatform = ref(AiPlatformEnum.MIDJOURNEY)
@ -53,6 +61,10 @@ const platformOptions = [
{
label: 'Stable Diffusion',
value: AiPlatformEnum.STABLE_DIFFUSION
},
{
label: '其他',
value: 'other'
}
]

View File

@ -20,9 +20,23 @@ export const AiPlatformEnum = {
Ollama: 'Ollama',
STABLE_DIFFUSION: 'StableDiffusion', // Stability AI
MIDJOURNEY: 'Midjourney', // Midjourney
SUNO: 'Suno' // Suno AI
SUNO: 'Suno', // Suno AI
TONG_YI_WAN_XIANG: 'TongYiWanXiang', //// 通义万相
YI_YAN_IMAGE: 'YiYanImage' //// 百度 image
}
export const OtherPlatformEnum:ImageModelVO [] = [
{
key: AiPlatformEnum.TONG_YI_WAN_XIANG,
name: '通义万相'
},
{
key: AiPlatformEnum.YI_YAN_IMAGE,
name: '百度图片'
}
]
/**
* AI
*/
@ -189,6 +203,64 @@ export const StableDiffusionStylePresets: ImageModelVO[] = [
}
]
export const TongYiWanXiangStylePresets: ImageModelVO[] = [
{
key: '-1',
name: '上传图像风格'
},
{
key: '0',
name: '复古漫画'
},
{
key: '1',
name: '3D童话'
},
{
key: '2',
name: '二次元'
},
{
key: '3',
name: '小清新'
},
{
key: '4',
name: '未来科技'
},
{
key: '5',
name: '国画古风'
},
{
key: '6',
name: '将军百战'
},
{
key: '7',
name: '炫彩卡通'
},
{
key: '8',
name: '清雅国风'
},
{
key: '9',
name: '喜迎新年'
}
]
export const TongYiWanXiangModels: ImageModelVO[] = [
{
key: 'wanx-v1',
name: 'wanx-v1'
},
{
key: 'wanx-sketch-to-image-v1',
name: 'wanx-sketch-to-image-v1'
}
]
export const StableDiffusionClipGuidancePresets: ImageModelVO[] = [
{
key: 'NONE',