【增加】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-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-input v-model="width" type="number" class="w-170px" placeholder="图片宽度" />
<el-input v-model="height" type="number" class="w-170px" placeholder="图片高度" />
</el-space>
</div>
<div class="btns">
@ -144,11 +78,12 @@
</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
ImageHotWords,
ImageModelVO,
OtherPlatformEnum,
TongYiWanXiangModels
} from '@/views/ai/utils/constants'
const message = useMessage() //
@ -160,13 +95,7 @@ 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 otherPlatform = ref<string>(AiPlatformEnum.TONG_YI) //
const models = ref<ImageModelVO[]>(TongYiWanXiangModels) //
const model = ref<string>(models.value[0].key) //
@ -198,16 +127,11 @@ const handleGenerateImage = async () => {
//
const form = {
platform: otherPlatform.value,
model: '---', // 1
prompt: prompt.value, // 1
width: width.value, // 1
height: height.value, // 1
model: model.value, //
prompt: prompt.value, //
width: width.value, //
height: height.value, //
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)
@ -224,29 +148,22 @@ 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) {
if (AiPlatformEnum.YI_YAN === platform) {
models.value = TongYiWanXiangModels
stylePresetList.value = TongYiWanXiangStylePresets
} else {
models.value = []
stylePresetList.value = []
}
//
if (stylePresetList.value.length > 0) {
if (models.value.length > 0) {
model.value = models.value[0].key
stylePreset.value = stylePresetList.value[0].key
} else {
model.value = ''
stylePreset.value = ''
}
}

View File

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