Add feature support for qrart (#34)

This commit is contained in:
AceDataCloud committed 2024-04-28 13:32:02 +00:00
1 parent 091fa4d18a
commit 2fe1cb4e1d
110 files changed
+5767 -334

No files matched your search

+36 -24
View File
@@ -4,22 +4,25 @@
<preset-panel />
</template>
<template #operation>
<mode-selector class="mb-4" />
<application-status
:initializing="initializing"
:application="application"
:service="service"
:need-apply="needApply"
class="mb-4"
@refresh="onGetApplication"
/>
<div class="pt-4">
<div class="top">
<mode-selector class="mb-4" />
<application-status
:initializing="initializing"
:application="application"
:service="service"
:need-apply="needApply"
class="mb-4"
@refresh="onGetApplication"
/>
<reference-image class="mb-4" @change="references = $event" />
<prompt-input v-model="prompt" class="mb-4" />
<elements-selector v-model="elements" :advanced="preset?.advanced" class="mb-4" />
<ignore-selector v-if="preset?.advanced" v-model="ignore" class="mb-4" />
<final-prompt v-if="finalPrompt" :model-value="finalPrompt" />
</div>
<div class="bottom">
<el-button type="primary" round class="btn btn-generate" :disabled="!finalPrompt" @click="onGenerate">
<font-awesome-icon icon="fa-solid fa-magic" class="mr-2" />
{{ $t('midjourney.button.generate') }}
</el-button>
</div>
@@ -53,6 +56,7 @@ import {
MIDJOURNEY_DEFAULT_STYLIZE,
MIDJOURNEY_DEFAULT_WIRED
} from '@/constants';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
interface IData {
prompt: string;
@@ -68,6 +72,7 @@ export default defineComponent({
components: {
ModeSelector,
ReferenceImage,
FontAwesomeIcon,
PresetPanel,
PromptInput,
ElementsSelector,
@@ -125,7 +130,7 @@ export default defineComponent({
if (this.preset.version && !content.includes(`--version `) && !content.includes(`--v `)) {
content += ` --version ${this.preset.version}`;
}
if (this.preset.chaos && !content.includes(`--chaos `)) {
if (this.preset.chaos && this.preset.advanced && !content.includes(`--chaos `)) {
content += ` --chaos ${this.preset.chaos}`;
}
if (this.preset.quality && !content.includes(`--quality `) && !content.includes(`--q `)) {
@@ -143,6 +148,7 @@ export default defineComponent({
this.preset.stylize &&
!content.includes(`--stylize `) &&
!content.includes(`--s `) &&
this.preset.advanced &&
this.preset.stylize !== MIDJOURNEY_DEFAULT_STYLIZE
) {
content += ` --stylize ${this.preset.stylize}`;
@@ -151,6 +157,7 @@ export default defineComponent({
this.preset.weird &&
!content.includes(`--weird `) &&
!content.includes(`--w `) &&
this.preset.advanced &&
this.preset.weird !== MIDJOURNEY_DEFAULT_WIRED
) {
content += ` --weird ${this.preset.weird}`;
@@ -158,10 +165,15 @@ export default defineComponent({
if (this.ignore && !content.includes(`--no `)) {
content += ` --no ${this.ignore}`;
}
if (this.preset.iw && !content.includes(`--iw `) && this.preset.iw !== MIDJOURNEY_DEFAULT_IMAGE_WEIGHT) {
if (
this.preset.iw &&
!content.includes(`--iw `) &&
this.preset.advanced &&
this.preset.iw !== MIDJOURNEY_DEFAULT_IMAGE_WEIGHT
) {
content += ` --iw ${this.preset.iw}`;
}
if (this.preset.style && !content.includes(`--style`)) {
if (this.preset.style && this.preset.advanced && !content.includes(`--style`)) {
content += ` --style ${this.preset.style}`;
}
return this.prompt || this.references?.length > 0 ? content : '';
@@ -209,6 +221,7 @@ export default defineComponent({
const request = {
image_id: payload.image_id,
action: payload.action,
mode: this.mode.name as MidjourneyImagineMode,
callback_url: CALLBACK_URL
};
this.onStartTask(request);
@@ -228,18 +241,17 @@ export default defineComponent({
</script>
<style lang="scss" scoped>
.operation {
.top {
flex: 1;
padding: 15px;
height: 100%;
overflow-x: scroll;
.title {
font-size: 14px;
margin-bottom: 10px;
}
.btn.btn-generate {
width: 80px;
border-radius: 20px;
height: calc(100% - 40px);
margin-bottom: 5px;
overflow-y: scroll;
}
.bottom {
height: 35px;
width: 100%;
.btn {
width: 100%;
}
}
</style>
+154
View File
@@ -0,0 +1,154 @@
<template>
<layout>
<template #config>
<config-panel @generate="onGenerate" />
</template>
<template #result>
<application-status
:initializing="initializing"
:application="application"
:service="service"
:need-apply="needApply"
class="mb-4"
@refresh="onGetApplication"
/>
<detail-panel class="panel detail" />
<recent-panel class="panel recent" />
</template>
</layout>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import Layout from '@/layouts/Qrart.vue';
import ConfigPanel from '@/components/qrart/ConfigPanel.vue';
import { applicationOperator, qrartOperator } from '@/operators';
import { IApplicationDetailResponse, IQrartGenerateRequest, Status } from '@/models';
import { ElMessage } from 'element-plus';
import { ERROR_CODE_DUPLICATION } from '@/constants';
import ApplicationStatus from '@/components/application/Status.vue';
import DetailPanel from '@/components/qrart/DetailPanel.vue';
import RecentPanel from '@/components/qrart/RecentPanel.vue';
import { IQrartTask } from '@/models';
const CALLBACK_URL = 'https://webhook.acedata.cloud/qrart';
interface IData {
task: IQrartTask | undefined;
}
export default defineComponent({
name: 'QrartIndex',
components: {
ConfigPanel,
Layout,
ApplicationStatus,
DetailPanel,
RecentPanel
},
data(): IData {
return {
task: undefined
};
},
computed: {
service() {
return this.$store.state.qrart.service;
},
credential() {
return this.$store.state.qrart.credential;
},
config() {
return this.$store.state.qrart.config;
},
initializing() {
return this.$store.state.qrart.status.getApplication === Status.Request;
},
needApply() {
return this.$store.state.qrart.status.getApplication === Status.Success && !this.application;
},
application() {
return this.$store.state.qrart.application;
}
},
methods: {
onApply() {
applicationOperator
.create({
// @ts-ignore
application: this.application
})
.then(({ data: data }: { data: IApplicationDetailResponse }) => {
this.application = data;
ElMessage.success(this.$t('application.message.applySuccessfully'));
})
.catch((error) => {
if (error?.response?.data?.code === ERROR_CODE_DUPLICATION) {
ElMessage.error(this.$t('application.message.alreadyApplied'));
}
});
},
async onGetApplication() {
await this.$store.dispatch('qrart/getApplication');
},
async onGenerate() {
const request = {
type: this.config?.type,
content: this.config?.content,
prompt: this.config?.prompt,
aspect_ratio: this.config?.aspect_ratio,
callback_url: CALLBACK_URL
} as IQrartGenerateRequest;
const token = this.credential?.token;
if (!token) {
console.error('no token specified');
return;
}
ElMessage.success(this.$t('qrart.message.startingTask'));
qrartOperator
.generate(request, {
token
})
.then(() => {
ElMessage.success(this.$t('qrart.message.startTaskSuccess'));
})
.catch(() => {
ElMessage.error(this.$t('qrart.message.startTaskFailed'));
});
}
}
});
</script>
<style lang="scss" scoped>
.operation {
flex: 1;
padding: 15px;
height: 100%;
overflow-x: scroll;
.title {
font-size: 14px;
margin-bottom: 10px;
}
.btn.btn-generate {
width: 80px;
border-radius: 20px;
}
}
.status {
margin-bottom: 10px;
}
.panel {
&.detail {
width: 100%;
flex: 1;
overflow-y: scroll;
}
&.recent {
height: 300px;
width: 100%;
}
}
</style>