【增加】ai image 对接通义参数

This commit is contained in:
cherishsince 2024-07-10 21:35:45 +08:00
parent 51c6bfe42c
commit c76b622722
2 changed files with 17 additions and 101 deletions

View File

@ -61,79 +61,13 @@
</el-select> </el-select>
</el-space> </el-space>
</div> </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 class="group-item">
<div> <div>
<el-text tag="b">图片尺寸</el-text> <el-text tag="b">图片尺寸</el-text>
</div> </div>
<el-space wrap class="group-item-body"> <el-space wrap class="group-item-body">
<el-input v-model="width" class="w-170px" placeholder="图片宽度" /> <el-input v-model="width" type="number" class="w-170px" placeholder="图片宽度" />
<el-input v-model="height" class="w-170px" placeholder="图片高度" /> <el-input v-model="height" type="number" 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> </el-space>
</div> </div>
<div class="btns"> <div class="btns">
@ -144,11 +78,12 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import {ImageApi, ImageDrawReqVO, ImageVO} from '@/api/ai/image' import {ImageApi, ImageDrawReqVO, ImageVO} from '@/api/ai/image'
import {hasChinese} from '@/views/ai/utils/utils'
import { import {
AiPlatformEnum, AiPlatformEnum,
ImageHotWords, ImageModelVO, OtherPlatformEnum, TongYiWanXiangModels, ImageHotWords,
TongYiWanXiangStylePresets ImageModelVO,
OtherPlatformEnum,
TongYiWanXiangModels
} from '@/views/ai/utils/constants' } from '@/views/ai/utils/constants'
const message = useMessage() // const message = useMessage() //
@ -160,13 +95,7 @@ const selectHotWord = ref<string>('') // 选中的热词
const prompt = ref<string>('') // const prompt = ref<string>('') //
const width = ref<number>(512) // const width = ref<number>(512) //
const height = ref<number>(512) // const height = ref<number>(512) //
const steps = ref<number>(20) // const otherPlatform = ref<string>(AiPlatformEnum.TONG_YI) //
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 models = ref<ImageModelVO[]>(TongYiWanXiangModels) //
const model = ref<string>(models.value[0].key) // const model = ref<string>(models.value[0].key) //
@ -198,16 +127,11 @@ const handleGenerateImage = async () => {
// //
const form = { const form = {
platform: otherPlatform.value, platform: otherPlatform.value,
model: '---', // 1 model: model.value, //
prompt: prompt.value, // 1 prompt: prompt.value, //
width: width.value, // 1 width: width.value, //
height: height.value, // 1 height: height.value, //
options: { options: {
seed: seed.value, // 1
steps: steps.value, // 1
scale: scale.value, // 1
stylePreset: stylePreset.value, //
referImage: referImageUrl.value //
} }
} as ImageDrawReqVO } as ImageDrawReqVO
await ImageApi.drawImage(form) await ImageApi.drawImage(form)
@ -224,29 +148,22 @@ const settingValues = async (detail: ImageVO) => {
prompt.value = detail.prompt prompt.value = detail.prompt
width.value = detail.width width.value = detail.width
height.value = detail.height 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) => { const handlerPlatformChange = async (platform) => {
// //
if (AiPlatformEnum.TONG_YI_WAN_XIANG === platform) { if (AiPlatformEnum.YI_YAN === platform) {
models.value = TongYiWanXiangModels models.value = TongYiWanXiangModels
stylePresetList.value = TongYiWanXiangStylePresets
} else { } else {
models.value = [] models.value = []
stylePresetList.value = []
} }
// //
if (stylePresetList.value.length > 0) { if (models.value.length > 0) {
model.value = models.value[0].key model.value = models.value[0].key
stylePreset.value = stylePresetList.value[0].key
} else { } else {
model.value = '' model.value = ''
stylePreset.value = ''
} }
} }

View File

@ -21,17 +21,15 @@ export const AiPlatformEnum = {
STABLE_DIFFUSION: 'StableDiffusion', // Stability AI STABLE_DIFFUSION: 'StableDiffusion', // Stability AI
MIDJOURNEY: 'Midjourney', // Midjourney 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 [] = [ export const OtherPlatformEnum:ImageModelVO [] = [
{ {
key: AiPlatformEnum.TONG_YI_WAN_XIANG, key: AiPlatformEnum.TONG_YI,
name: '通义万相' name: '通义万相'
}, },
{ {
key: AiPlatformEnum.YI_YAN_IMAGE, key: AiPlatformEnum.YI_YAN,
name: '百度图片' name: '百度图片'
} }
] ]
@ -203,6 +201,7 @@ export const StableDiffusionStylePresets: ImageModelVO[] = [
} }
] ]
// todo @芋艿 这些是通义的风格,看要不要删除
export const TongYiWanXiangStylePresets: ImageModelVO[] = [ export const TongYiWanXiangStylePresets: ImageModelVO[] = [
{ {
key: '-1', key: '-1',