Skip to content

Commit

Permalink
stable-diffusion-webui
Browse files Browse the repository at this point in the history
  • Loading branch information
yArna committed Apr 9, 2023
1 parent db346aa commit d339222
Show file tree
Hide file tree
Showing 11 changed files with 303 additions and 49 deletions.
39 changes: 39 additions & 0 deletions data/src/dict/构图-画面效果.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
text,lang_zh,subType,dir
chromatic aberration,色差,风格,构图/画面效果
lens flare,镜头光晕,风格,构图/画面效果
motion blur,动态模糊,风格,构图/画面效果
sparkle,闪耀效果,风格,构图/画面效果
jpeg artifacts,JPEG 压缩失真,风格,构图/画面效果
blurry,模糊的,风格,构图/画面效果
cinematic lighting,电影光效,风格,构图/画面效果
glowing light,荧光,风格,构图/画面效果
god rays,自上而下的光,风格,构图/画面效果
ray tracing,光线追踪,风格,构图/画面效果
reflection light,反射光,风格,构图/画面效果
overexposure,过曝,风格,构图/画面效果
backlighting,逆光,风格,构图/画面效果
blending,混合,风格,构图/画面效果
bloom,盛开,风格,构图/画面效果
bokeh,背景散焦,风格,构图/画面效果
caustics,焦散,风格,构图/画面效果
chiaroscuro,明暗对比,风格,构图/画面效果
chromatic aberration abuse,色差滥用,风格,构图/画面效果
diffraction spikes,衍射十字星,风格,构图/画面效果
depth of field,背景虚化,风格,构图/画面效果
dithering,抖动,风格,构图/画面效果
drop shadow,立绘阴影,风格,构图/画面效果
emphasis lines,集中线,风格,构图/画面效果
film grain,胶片颗粒感/老电影滤镜,风格,构图/画面效果
foreshortening,正前缩距透视法,风格,构图/画面效果
halftone,一种漫画中常见的网点状的组色组图画法,风格,构图/画面效果
image fill,图像填充,风格,构图/画面效果
lens flare abuse,镜头光晕滥用,风格,构图/画面效果
motion lines,体现运动的线,风格,构图/画面效果
multiple monochrome,多个单色结构拼接成的,风格,构图/画面效果
optical illusion,视错觉,风格,构图/画面效果
anaglyph,互补色,风格,构图/画面效果
stereogram,立体画,风格,构图/画面效果
scanlines,扫描线,风格,构图/画面效果
silhouette,剪影,风格,构图/画面效果
speed lines,速度线,风格,构图/画面效果
vignetting,晕影,风格,构图/画面效果
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@moonvy/open-prompt-studio",
"version": "1.1.6",
"version": "1.2.0",
"license": "MIT",
"type": "module",
"scripts": {
Expand Down
36 changes: 34 additions & 2 deletions src/Compoents/PromptEditor/Components/PromptItem/PromptItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@click="onClick"
@contextmenu.prevent="$emit('contextmenu', { el: $el, item, event: $event })"
@mousedown="onMousedown"
v-tooltip="item.data.word.desc"
v-tooltip="{ content: item.data.word.desc, delay: 500 }"
>
<div class="content">
<div class="displayName name">
Expand Down Expand Up @@ -39,6 +39,9 @@
<span v-else> {{ langName }}</span>
</div>
</div>
<div class="link" v-if="item.data?.word?.link" @click.stop="doOpenUrl(item.data.word.link)" @mousedown.stop>
<Icon icon="radix-icons:link-2" />
</div>
<div class="dnd-slots">
<div class="dnd-slot-pre"></div>
<div class="dnd-slot-next"></div>
Expand Down Expand Up @@ -186,6 +189,32 @@
}
}
}

.link {
display: none;
position: absolute;
right: -14px;
top: -14px;
background: linear-gradient(#285edb, #504f94);
height: 24px;
width: 24px;
place-content: center;
place-items: center;
border-radius: 280px;
box-shadow: 0 2px 4px rgba(86, 82, 199, 0.2392156863);
box-shadow: 0 2px 2px rgba(51, 54, 67, 0.2509803922);
font-size: 16px;
transition: all 0.2s ease;
}
&:hover {
.link {
display: flex;

&:hover {
transform: scale(1.1);
}
}
}
}

.dnd-ing {
Expand Down Expand Up @@ -239,6 +268,9 @@ export default Vue.extend({
e.preventDefault()
}
},
doOpenUrl(url: string) {
window.open(url)
},
doFoucs() {
setTimeout(() => {
if (this.item.state.isEdit == "text") {
Expand Down Expand Up @@ -305,7 +337,7 @@ export default Vue.extend({
},
displayLv(): number | undefined {
let word: IPromptWord = (<any>this.item).data.word
if (word.lv && word.lv > 1) {
if (word.lv && word.lv != 1) {
return word.lv
}
},
Expand Down
15 changes: 13 additions & 2 deletions src/Compoents/PromptEditor/Components/PromptWork/PromptWork.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<div class="line more-options">
<select v-model="inputParser" class="parser-select" v-tooltip="`提示词语法类型`">
<option value="midjourney">Midjourney</option>
<option value="stable-diffusion" disabled>Stable-Diffusion (WIP)</option>
<option value="stable-diffusion-webui">stable-diffusion-webui</option>
</select>
<button @click="doDeleteWorkspace()" v-tooltip="`删除工作区`" class="icon">
<Icon icon="radix-icons:trash" />
Expand Down Expand Up @@ -342,6 +342,11 @@

.more-options {
margin-top: auto;
.parser-select {
margin-left: auto;
width: auto;
padding-right: 35px;
}
}
}
}
Expand Down Expand Up @@ -434,7 +439,7 @@ export default Vue.extend({
return {
inputText: "",
outputText: "",
inputParser: "midjourney",
inputParser: this.promptWork?.data?.parser ?? "midjourney",
isPNGExporting: false,
}
},
Expand All @@ -445,6 +450,12 @@ export default Vue.extend({
this.inputText = this.promptWork.data.initText ?? ""
this.doImportByInput()
},
watch: {
inputParser(val) {
this.promptWork.data.parser = val
this.doImportByInput()
},
},
methods: {
async doImportByInput() {
await this.promptWork.importPrompts(this.inputText, { parser: <any>this.inputParser })
Expand Down
22 changes: 20 additions & 2 deletions src/Compoents/PromptEditor/Lib/parsePrompts/parsePrompts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { midjourneyParse } from "./parsers/Midjourney"
import { midjourneyParse, midjourneyStringify } from "./parsers/Midjourney"
import {stableDiffusionWebUIParse, stableDiffusionWebUIStringify} from "./parsers/StableDiffusionWebUI"
import { useDatabaseServer } from "../DatabaseServer/DatabaseServer"
import { IPromptGroup } from "../../Sub/PromptWork"

export interface IPromptWord {
id: string
Expand All @@ -10,9 +12,11 @@ export interface IPromptWord {
langText?: string
subType?: string
desc?: string
link?: string
args?: string[]
dir?: string
lv?: number
alv?: number
isEg?: boolean
}
export enum PromptWordType {
Expand All @@ -24,13 +28,15 @@ export interface IPromptParseResult {

export async function parsePrompts(
text: string,
options: { parser: "midjourney" | "stable-diffusion"; minify?: boolean; zh2en?: boolean } = {
options: { parser: string; minify?: boolean; zh2en?: boolean } = {
parser: "midjourney",
}
): Promise<IPromptParseResult> {
let words: IPromptWord[]
if (options.parser === "midjourney") {
words = await midjourneyParse(text, options)
} else if (options.parser === "stable-diffusion-webui") {
words = await stableDiffusionWebUIParse(text, options)
} else {
throw new Error(`err ParsePrompts not support this parser:${options.parser}`)
}
Expand Down Expand Up @@ -67,6 +73,18 @@ export async function parsePrompts(
return result
}

export function stringifyPrompts(groups: IPromptGroup[] = [], options: { parser: string }) {
let prompts: string
if (options.parser === "midjourney") {
prompts = midjourneyStringify(groups)
} else if (options.parser === "stable-diffusion-webui") {
prompts = stableDiffusionWebUIStringify(groups)
} else {
throw new Error(`err ParsePrompts not support this parser:${options.parser}`)
}
return prompts
}

function wordsDeduplicat(words: IPromptWord[]): IPromptWord[] {
let map: any = {}
words.forEach((word) => (map[word.rawText] = word))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { IPromptWord, PromptWordType } from "../../ParsePrompts"
import { translateZh2En } from "../../../translatePrompts"
import { IPromptGroup } from "../../../../Sub/PromptWork"

export async function midjourneyParse(text: string, options?: { zh2en?: boolean }): Promise<IPromptWord[]> {
let re = paresCommands(text)
Expand Down Expand Up @@ -51,6 +52,41 @@ export async function midjourneyParse(text: string, options?: { zh2en?: boolean
return words
}

export function midjourneyStringify(groups: IPromptGroup[] = []) {
let finText = ""
let commands: string[] = []
let i = 0,
len = groups.length
for (let group of groups) {
let chars: string[] = []
for (let list of group.lists) {
for (let item of list.items) {
if (item.data.disabled) continue
if (item.data.word.subType === "command") {
commands.push(item.data.word.rawText!)
} else {
chars.push(item.data.word.rawText!)
}
}
}
finText += chars.filter((x) => x != "").join(", ")
if (len > 0) {
if (i < len - 1) {
finText += ` ::${group.groupLv == 1 ? "" : group.groupLv} `
} else {
if (group.groupLv && group.groupLv != 1) {
finText += ` ::${group.groupLv} `
}
}
}
i++
}
if (commands.length > 0) finText += ` ${commands.join(" ")}`

// console.log("exportPrompts")
return finText.trim()
}

function split(text: string) {
return text.split(/[,|{}\[\]\(\)\n]/).map((word) => word.trim())
}
Expand Down
Loading

0 comments on commit d339222

Please sign in to comment.