Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f19e8c4d
authored
Jun 30, 2024
by
cherishsince
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【修改todo】增加 sd 各种参数
parent
f98f794f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
186 additions
and
78 deletions
+186
-78
src/api/ai/image/index.ts
+1
-1
src/views/ai/image/index.vue
+1
-1
src/views/ai/image/stable-diffusion/index.vue
+184
-76
No files found.
src/api/ai/image/index.ts
View file @
f19e8c4d
...
@@ -66,7 +66,7 @@ export const ImageApi = {
...
@@ -66,7 +66,7 @@ export const ImageApi = {
},
},
// 获取【我的】绘图记录列表
// 获取【我的】绘图记录列表
getImageListMyByIds
:
async
(
ids
:
number
[])
=>
{
getImageListMyByIds
:
async
(
ids
:
number
[])
=>
{
return
await
request
.
get
({
url
:
`/ai/image/
get-m
y-ids`
,
params
:
{
ids
:
ids
.
join
(
','
)
}
})
return
await
request
.
get
({
url
:
`/ai/image/
my-list-b
y-ids`
,
params
:
{
ids
:
ids
.
join
(
','
)
}
})
},
},
// 生成图片
// 生成图片
drawImage
:
async
(
data
:
ImageDrawReqVO
)
=>
{
drawImage
:
async
(
data
:
ImageDrawReqVO
)
=>
{
...
...
src/views/ai/image/index.vue
View file @
f19e8c4d
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
@
on-draw-start=
"handlerDrawStart"
@
on-draw-start=
"handlerDrawStart"
@
on-draw-complete=
"handlerDrawComplete"
/>
@
on-draw-complete=
"handlerDrawComplete"
/>
<Midjourney
v-if=
"selectModel === 'MJ绘画'"
/>
<Midjourney
v-if=
"selectModel === 'MJ绘画'"
/>
<StableDiffusion
v-if=
"selectModel === 'Stable Diffusion'"
/>
<StableDiffusion
v-if=
"selectModel === 'Stable Diffusion'"
@
on-draw-complete=
"handlerDrawComplete"
/>
</div>
</div>
</div>
</div>
<div
class=
"main"
>
<div
class=
"main"
>
...
...
src/views/ai/image/stable-diffusion/index.vue
View file @
f19e8c4d
...
@@ -26,7 +26,7 @@
...
@@ -26,7 +26,7 @@
:type=
"selectHotWord === hotWord ? 'primary' : 'default'"
:type=
"selectHotWord === hotWord ? 'primary' : 'default'"
v-for=
"hotWord in hotWords"
v-for=
"hotWord in hotWords"
:key=
"hotWord"
:key=
"hotWord"
@
click=
"handle
r
HotWordClick(hotWord)"
@
click=
"handleHotWordClick(hotWord)"
>
>
{{
hotWord
}}
{{
hotWord
}}
</el-button>
</el-button>
...
@@ -44,21 +44,35 @@
...
@@ -44,21 +44,35 @@
</div>
</div>
<div
class=
"group-item"
>
<div
class=
"group-item"
>
<div>
<div>
<el-text
tag=
"b"
>
图片尺寸
</el-text>
<el-text
tag=
"b"
>
CLIP
</el-text>
</div>
</div>
<el-space
wrap
class=
"group-item-body"
>
<el-space
wrap
class=
"group-item-body"
>
<el-select
v-model=
"selectImageSize"
placeholder=
"Select"
size=
"large"
style=
"width: 350px"
>
<el-select
v-model=
"selectClipGuidancePreset"
placeholder=
"Select"
size=
"large"
style=
"width: 350px"
>
<el-option
<el-option
v-for=
"item in clipGuidancePresets"
:key=
"item.key"
:label=
"item.name"
:value=
"item.key"
/>
v-for=
"item in imageSizeList"
:key=
"item.key"
:label=
"item.key"
:value=
"item.key"
/>
</el-select>
</el-select>
</el-space>
</el-space>
</div>
</div>
<div
class=
"group-item"
>
<div
class=
"group-item"
>
<div>
<div>
<el-text
tag=
"b"
>
风格
</el-text>
</div>
<el-space
wrap
class=
"group-item-body"
>
<el-select
v-model=
"selectStylePreset"
placeholder=
"Select"
size=
"large"
style=
"width: 350px"
>
<el-option
v-for=
"item in stylePresets"
: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=
"imageWidth"
style=
"width: 170px"
placeholder=
"图片宽度"
/>
<el-input
v-model=
"imageHeight"
style=
"width: 170px"
placeholder=
"图片高度"
/>
</el-space>
</div>
<div
class=
"group-item"
>
<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"
>
...
@@ -73,6 +87,20 @@
...
@@ -73,6 +87,20 @@
</div>
</div>
<div
class=
"group-item"
>
<div
class=
"group-item"
>
<div>
<div>
<el-text
tag=
"b"
>
引导系数
</el-text>
</div>
<el-space
wrap
class=
"group-item-body"
>
<el-input
v-model=
"scale"
type=
"number"
size=
"large"
style=
"width: 350px"
placeholder=
"Please input"
/>
</el-space>
</div>
<div
class=
"group-item"
>
<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"
>
...
@@ -86,13 +114,13 @@
...
@@ -86,13 +114,13 @@
</el-space>
</el-space>
</div>
</div>
<div
class=
"btns"
>
<div
class=
"btns"
>
<el-button
type=
"primary"
size=
"large"
round
:loading=
"drawIn"
@
click=
"handle
r
GenerateImage"
>
<el-button
type=
"primary"
size=
"large"
round
:loading=
"drawIn"
@
click=
"handleGenerateImage"
>
{{
drawIn
?
'生成中'
:
'生成内容'
}}
{{
drawIn
?
'生成中'
:
'生成内容'
}}
</el-button>
</el-button>
</div>
</div>
</
template
>
</
template
>
<
script
setup
lang=
"ts"
>
<
script
setup
lang=
"ts"
>
import
{
ImageApi
,
ImageDrawReqVO
}
from
'@/api/ai/image'
import
{
ImageApi
,
ImageDrawReqVO
}
from
'@/api/ai/image'
// image 模型
// image 模型
interface
ImageModelVO
{
interface
ImageModelVO
{
...
@@ -100,17 +128,13 @@ interface ImageModelVO {
...
@@ -100,17 +128,13 @@ interface ImageModelVO {
name
:
string
name
:
string
}
}
// image 大小
interface
ImageSizeVO
{
key
:
string
width
:
string
height
:
string
}
// 定义属性
// 定义属性
const
prompt
=
ref
<
string
>
(
''
)
// 提示词
const
prompt
=
ref
<
string
>
(
''
)
// 提示词
const
drawIn
=
ref
<
boolean
>
(
false
)
// 生成中
const
drawIn
=
ref
<
boolean
>
(
false
)
// 生成中
const
selectHotWord
=
ref
<
string
>
(
''
)
// 选中的热词
const
selectHotWord
=
ref
<
string
>
(
''
)
// 选中的热词
const
imageWidth
=
ref
<
number
>
(
512
)
// 图片宽度
const
imageHeight
=
ref
<
number
>
(
512
)
// 图片高度
const
hotWords
=
ref
<
string
[]
>
([
const
hotWords
=
ref
<
string
[]
>
([
'中国旗袍'
,
'中国旗袍'
,
'古装美女'
,
'古装美女'
,
...
@@ -119,100 +143,181 @@ const hotWords = ref<string[]>([
...
@@ -119,100 +143,181 @@ const hotWords = ref<string[]>([
'童话小屋'
,
'童话小屋'
,
'中国长城'
'中国长城'
])
// 热词
])
// 热词
const
selectSampler
=
ref
<
any
>
({})
// 模型
// message
// message
const
message
=
useMessage
()
const
message
=
useMessage
()
// 采样方法 TODO @fan:有 Euler a;DPM++ 2S a;DPM++ 2M;DPM++ SDE;DPM++ 2M SDE;UniPC;Restart;另外,要不这种枚举,我们都放到 image 里?写成 stableDiffusionSampler ?
// 采样方法 TODO @fan:有 Euler a;DPM++ 2S a;DPM++ 2M;DPM++ SDE;DPM++ 2M SDE;UniPC;Restart;另外,要不这种枚举,我们都放到 image 里?写成 stableDiffusionSampler ?
const
selectSampler
=
ref
<
any
>
({})
// 模型
// DDIM DDPM K_DPMPP_2M K_DPMPP_2S_ANCESTRAL K_DPM_2 K_DPM_2_ANCESTRAL K_EULER K_EULER_ANCESTRAL K_HEUN K_LMS
const
sampler
=
ref
<
ImageModelVO
[]
>
([
const
sampler
=
ref
<
ImageModelVO
[]
>
([
{
{
key
:
'
Euler a
'
,
key
:
'
DDIM
'
,
name
:
'
Euler a
'
name
:
'
DDIM
'
},
},
{
{
key
:
'D
PM++ 2S a Karras
'
,
key
:
'D
DPM
'
,
name
:
'D
PM++ 2S a Karras
'
name
:
'D
DPM
'
},
},
{
{
key
:
'
DPM++ 2M Karras
'
,
key
:
'
K_DPMPP_2M
'
,
name
:
'
DPM++ 2M Karras
'
name
:
'
K_DPMPP_2M
'
},
},
{
{
key
:
'
DPM++ SDE Karras
'
,
key
:
'
K_DPMPP_2S_ANCESTRAL
'
,
name
:
'
DPM++ SDE Karras
'
name
:
'
K_DPMPP_2S_ANCESTRAL
'
},
},
{
{
key
:
'DPM++ 2M SDE Karras'
,
key
:
'K_DPM_2'
,
name
:
'DPM++ 2M SDE Karras'
name
:
'K_DPM_2'
}
},
{
key
:
'K_DPM_2_ANCESTRAL'
,
name
:
'K_DPM_2_ANCESTRAL'
},
{
key
:
'K_EULER'
,
name
:
'K_EULER'
},
{
key
:
'K_EULER_ANCESTRAL'
,
name
:
'K_EULER_ANCESTRAL'
},
{
key
:
'K_HEUN'
,
name
:
'K_HEUN'
},
{
key
:
'K_LMS'
,
name
:
'K_LMS'
},
])
])
selectSampler
.
value
=
sampler
.
value
[
0
]
selectSampler
.
value
=
sampler
.
value
[
0
]
// TODO @fan:是不是还有个,采样调度器
// 风格
// TODO @fan:是不是还有个,引导系数
// 3d-model analog-film anime cinematic comic-book digital-art enhance fantasy-art isometric
// line-art low-poly modeling-compound neon-punk origami photographic pixel-art tile-texture
const
selectImageSize
=
ref
<
ImageSizeVO
>
({}
as
ImageSizeVO
)
// 选中 size
const
selectStylePreset
=
ref
<
any
>
({})
// 模型
// TODO @fan:这个我们是不是只写 width、height 就好啦。key 可以在 option 拼接出来?
const
stylePresets
=
ref
<
ImageModelVO
[]
>
([
const
imageSizeList
=
ref
<
ImageSizeVO
[]
>
([
{
{
key
:
'512x512'
,
key
:
'3d-model'
,
width
:
'512'
,
name
:
'3d-model'
height
:
'512'
},
},
{
{
key
:
'1024x1024'
,
key
:
'analog-film'
,
width
:
'1024'
,
name
:
'analog-film'
height
:
'1024'
},
},
{
{
key
:
'1024x1792'
,
key
:
'anime'
,
width
:
'1024'
,
name
:
'anime'
height
:
'1792'
},
},
{
{
key
:
'1792x1024'
,
key
:
'cinematic'
,
width
:
'1792'
,
name
:
'cinematic'
height
:
'1024'
},
},
{
{
key
:
'2048x2048'
,
key
:
'comic-book'
,
width
:
'2048'
,
name
:
'comic-book'
height
:
'2048'
},
},
{
{
key
:
'720x1280'
,
key
:
'digital-art'
,
width
:
'720'
,
name
:
'digital-art'
height
:
'1280'
},
},
{
{
key
:
'1080x1920'
,
key
:
'enhance'
,
width
:
'1080'
,
name
:
'enhance'
height
:
'1920'
},
},
{
{
key
:
'1440x2560'
,
key
:
'fantasy-art'
,
width
:
'1440'
,
name
:
'fantasy-art'
height
:
'2560'
},
},
{
{
key
:
'2160x3840'
,
key
:
'isometric'
,
width
:
'2160'
,
name
:
'isometric'
height
:
'3840'
},
}
{
])
// size
key
:
'line-art'
,
selectImageSize
.
value
=
imageSizeList
.
value
[
0
]
name
:
'line-art'
},
{
key
:
'low-poly'
,
name
:
'low-poly'
},
{
key
:
'modeling-compound'
,
name
:
'modeling-compound'
},
// neon-punk origami photographic pixel-art tile-texture
{
key
:
'neon-punk'
,
name
:
'neon-punk'
},
{
key
:
'origami'
,
name
:
'origami'
},
{
key
:
'photographic'
,
name
:
'photographic'
},
{
key
:
'pixel-art'
,
name
:
'pixel-art'
},
{
key
:
'tile-texture'
,
name
:
'tile-texture'
},
])
selectStylePreset
.
value
=
stylePresets
.
value
[
0
]
// 文本提示相匹配的图像(clip_guidance_preset) 简称 CLIP
// https://platform.stability.ai/docs/api-reference#tag/SDXL-and-SD1.6/operation/textToImage
// FAST_BLUE FAST_GREEN NONE SIMPLE SLOW SLOWER SLOWEST
const
selectClipGuidancePreset
=
ref
<
any
>
({})
// 模型
const
clipGuidancePresets
=
ref
<
ImageModelVO
[]
>
([
{
key
:
'NONE'
,
name
:
'NONE'
},
{
key
:
'FAST_BLUE'
,
name
:
'FAST_BLUE'
},
{
key
:
'FAST_GREEN'
,
name
:
'FAST_GREEN'
},
{
key
:
'SIMPLE'
,
name
:
'SIMPLE'
},
{
key
:
'SLOW'
,
name
:
'SLOW'
},
{
key
:
'SLOWER'
,
name
:
'SLOWER'
},
{
key
:
'SLOWEST'
,
name
:
'SLOWEST'
},
])
selectClipGuidancePreset
.
value
=
clipGuidancePresets
.
value
[
0
]
const
steps
=
ref
<
number
>
(
20
)
// 迭代步数
const
steps
=
ref
<
number
>
(
20
)
// 迭代步数
const
seed
=
ref
<
number
>
(
-
1
)
// 控制生成图像的随机性
const
seed
=
ref
<
number
>
(
42
)
// 控制生成图像的随机性
const
scale
=
ref
<
number
>
(
7.5
)
// 引导系数
// 定义 Props
// 定义 Props
const
props
=
defineProps
({})
const
props
=
defineProps
({})
// 定义 emits
// 定义 emits
const
emits
=
defineEmits
([
'onDrawStart'
,
'onDrawComplete'
])
const
emits
=
defineEmits
([
'onDrawStart'
,
'onDrawComplete'
])
// TODO @fan:如果是简单注释,建议用 /** */,主要是现在项目里是这种风格哈,保持一致好点~
// TODO @fan:handler 应该改成 handle 哈
/** 热词 - click */
/** 热词 - click */
const
handle
r
HotWordClick
=
async
(
hotWord
:
string
)
=>
{
const
handleHotWordClick
=
async
(
hotWord
:
string
)
=>
{
// 取消选中
// 取消选中
if
(
selectHotWord
.
value
==
hotWord
)
{
if
(
selectHotWord
.
value
==
hotWord
)
{
selectHotWord
.
value
=
''
selectHotWord
.
value
=
''
...
@@ -225,7 +330,7 @@ const handlerHotWordClick = async (hotWord: string) => {
...
@@ -225,7 +330,7 @@ const handlerHotWordClick = async (hotWord: string) => {
}
}
/** 图片生产 */
/** 图片生产 */
const
handle
r
GenerateImage
=
async
()
=>
{
const
handleGenerateImage
=
async
()
=>
{
// 二次确认
// 二次确认
await
message
.
confirm
(
`确认生成内容?`
)
await
message
.
confirm
(
`确认生成内容?`
)
try
{
try
{
...
@@ -233,19 +338,22 @@ const handlerGenerateImage = async () => {
...
@@ -233,19 +338,22 @@ const handlerGenerateImage = async () => {
drawIn
.
value
=
true
drawIn
.
value
=
true
// 回调
// 回调
emits
(
'onDrawStart'
,
'StableDiffusion'
)
emits
(
'onDrawStart'
,
'StableDiffusion'
)
// 发送请求
const
form
=
{
const
form
=
{
platform
:
'StableDiffusion'
,
platform
:
'StableDiffusion'
,
model
:
'stable-diffusion-v1-6'
,
model
:
'stable-diffusion-v1-6'
,
prompt
:
prompt
.
value
,
// 提示词
prompt
:
prompt
.
value
,
// 提示词
width
:
selectImageSize
.
value
.
width
,
// 图片宽度
width
:
imageWidth
.
value
,
// 图片宽度
height
:
selectImageSize
.
value
.
height
,
// 图片高度
height
:
imageHeight
.
value
,
// 图片高度
options
:
{
options
:
{
sampler
:
selectSampler
.
value
.
key
,
// 采样算法
seed
:
seed
.
value
,
// 随机种子
seed
:
seed
.
value
,
// 随机种子
steps
:
steps
.
value
// 图片生成步数
steps
:
steps
.
value
,
// 图片生成步数
scale
:
scale
.
value
,
// 引导系数
sampler
:
selectSampler
.
value
.
key
,
// 采样算法
clipGuidancePreset
:
selectClipGuidancePreset
.
value
.
key
,
// 文本提示相匹配的图像 CLIP
stylePreset
:
selectStylePreset
.
value
.
key
,
// 风格
}
}
}
as
ImageDrawReqVO
}
as
ImageDrawReqVO
// 发送请求
await
ImageApi
.
drawImage
(
form
)
await
ImageApi
.
drawImage
(
form
)
}
finally
{
}
finally
{
// 回调
// 回调
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment