Optimize nano panel (#288)
This commit is contained in:
1 parent
429f1c176d
commit
fcbbfbf4fe
7 files changed
+40
-35
No files matched your search
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "patch",
|
||||
"comment": "optimize experience of nano",
|
||||
"packageName": "@acedatacloud/nexior",
|
||||
"email": "cqc@cuiqingcai.com",
|
||||
"dependentChangeType": "patch"
|
||||
}
|
||||
@@ -3,10 +3,9 @@
|
||||
<div class="flex-1 overflow-y-auto p-[15px]">
|
||||
<model-selector class="mb-4" />
|
||||
<resolution-selector class="mb-4" />
|
||||
<action-selector class="mb-4" />
|
||||
<prompt-input class="mb-4" />
|
||||
<aspect-ratio-selector class="mb-4" />
|
||||
<image-urls-input v-if="config?.action === 'edit'" class="mb-4" />
|
||||
<image-urls-input class="mb-4" />
|
||||
</div>
|
||||
<div class="flex flex-col items-center justify-center px-[15px] pb-[15px]">
|
||||
<consumption :value="consumption" :service="service" />
|
||||
@@ -22,7 +21,6 @@
|
||||
import { defineComponent } from 'vue';
|
||||
import { ElButton } from 'element-plus';
|
||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
||||
import ActionSelector from './config/ActionSelector.vue';
|
||||
import PromptInput from './config/PromptInput.vue';
|
||||
import ImageUrlsInput from './config/ImageUrlsInput.vue';
|
||||
import AspectRatioSelector from './config/AspectRatioSelector.vue';
|
||||
@@ -38,7 +36,6 @@ export default defineComponent({
|
||||
FontAwesomeIcon,
|
||||
PromptInput,
|
||||
Consumption,
|
||||
ActionSelector,
|
||||
ImageUrlsInput,
|
||||
AspectRatioSelector,
|
||||
ModelSelector,
|
||||
@@ -50,7 +47,15 @@ export default defineComponent({
|
||||
return this.$store.state.nanobanana?.config;
|
||||
},
|
||||
consumption() {
|
||||
return getConsumption(this.config, this.service?.metadata?.price);
|
||||
const cfg: any = { ...(this.config || {}) };
|
||||
const hasReferenceImages = Array.isArray(cfg?.image_urls) && cfg.image_urls.length > 0;
|
||||
return getConsumption(
|
||||
{
|
||||
...cfg,
|
||||
action: hasReferenceImages ? 'edit' : 'generate'
|
||||
},
|
||||
this.service?.metadata?.price
|
||||
);
|
||||
},
|
||||
service() {
|
||||
return this.$store.state.nanobanana?.service;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<div class="field">
|
||||
<h2 class="title font-bold">{{ $t('nanobanana.name.aspectRatio') }}</h2>
|
||||
<el-select v-model="value" class="value" :placeholder="$t('nanobanana.placeholder.select')">
|
||||
<el-select v-model="value" class="value" clearable :placeholder="$t('nanobanana.placeholder.select')">
|
||||
<el-option v-for="opt in options" :key="opt" :label="opt" :value="opt" />
|
||||
</el-select>
|
||||
</div>
|
||||
@@ -10,7 +10,6 @@
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { ElSelect, ElOption } from 'element-plus';
|
||||
import { NANOBANANA_DEFAULT_ASPECT_RATIO } from '@/constants';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'AspectRatioSelector',
|
||||
@@ -25,19 +24,17 @@ export default defineComponent({
|
||||
get() {
|
||||
return this.$store.state.nanobanana?.config?.aspect_ratio;
|
||||
},
|
||||
set(val: string) {
|
||||
set(val: string | null | undefined) {
|
||||
console.debug('set aspect_ratio', val);
|
||||
this.$store.commit('nanobanana/setConfig', {
|
||||
...this.$store.state.nanobanana?.config,
|
||||
aspect_ratio: val
|
||||
});
|
||||
const nextConfig = { ...(this.$store.state.nanobanana?.config || {}) };
|
||||
if (!val) {
|
||||
delete (nextConfig as any).aspect_ratio;
|
||||
} else {
|
||||
(nextConfig as any).aspect_ratio = val;
|
||||
}
|
||||
this.$store.commit('nanobanana/setConfig', nextConfig);
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
if (!this.value) {
|
||||
this.value = NANOBANANA_DEFAULT_ASPECT_RATIO;
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -197,12 +197,11 @@ export default defineComponent({
|
||||
onEdit(imageUrl?: string) {
|
||||
if (!imageUrl) return;
|
||||
console.debug('Edit image:', imageUrl);
|
||||
// Switch to edit mode and preload image into uploader list
|
||||
this.$store.commit('nanobanana/setConfig', {
|
||||
...this.$store.state.nanobanana?.config,
|
||||
action: 'edit',
|
||||
image_urls: [imageUrl]
|
||||
});
|
||||
// Preload image into uploader list for editing
|
||||
const nextConfig = { ...(this.$store.state.nanobanana?.config || {}) };
|
||||
delete (nextConfig as any).action;
|
||||
(nextConfig as any).image_urls = [imageUrl];
|
||||
this.$store.commit('nanobanana/setConfig', nextConfig);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -2,8 +2,6 @@ export const NANOBANANA_SERVICE_ID = '';
|
||||
|
||||
export const NANOBANANA_DEFAULT_ACTION: 'generate' | 'edit' = 'generate';
|
||||
|
||||
export const NANOBANANA_DEFAULT_ASPECT_RATIO = '1:1';
|
||||
|
||||
export const NANOBANANA_RESOLUTION_1K = '1K';
|
||||
export const NANOBANANA_RESOLUTION_2K = '2K';
|
||||
export const NANOBANANA_RESOLUTION_4K = '4K';
|
||||
|
||||
@@ -129,10 +129,15 @@ export default defineComponent({
|
||||
},
|
||||
async onGenerate() {
|
||||
const cfg: any = { ...(this.config || {}) };
|
||||
// When action is 'generate', do not send image_urls
|
||||
if (cfg?.action === 'generate' && 'image_urls' in cfg) {
|
||||
const hasReferenceImages = Array.isArray(cfg?.image_urls) && cfg.image_urls.length > 0;
|
||||
delete cfg.action;
|
||||
// If creating new images, omit reference images from payload
|
||||
if (!hasReferenceImages && 'image_urls' in cfg) {
|
||||
delete cfg.image_urls;
|
||||
}
|
||||
if (!cfg?.aspect_ratio) {
|
||||
delete cfg.aspect_ratio;
|
||||
}
|
||||
if (cfg?.model !== NANOBANANA_MODEL_NANO_BANANA_PRO && 'resolution' in cfg) {
|
||||
delete cfg.resolution;
|
||||
}
|
||||
@@ -141,6 +146,7 @@ export default defineComponent({
|
||||
}
|
||||
const request = {
|
||||
...cfg,
|
||||
action: hasReferenceImages ? 'edit' : 'generate',
|
||||
callback_url: CALLBACK_URL
|
||||
} as INanobananaGenerateRequest;
|
||||
const token = this.credential?.token;
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
import { INanobananaState } from './models';
|
||||
import { Status } from '@/models';
|
||||
import {
|
||||
NANOBANANA_DEFAULT_ACTION,
|
||||
NANOBANANA_DEFAULT_ASPECT_RATIO,
|
||||
NANOBANANA_DEFAULT_MODEL,
|
||||
NANOBANANA_DEFAULT_RESOLUTION
|
||||
} from '@/constants';
|
||||
import { NANOBANANA_DEFAULT_MODEL, NANOBANANA_DEFAULT_RESOLUTION } from '@/constants';
|
||||
|
||||
export default (): INanobananaState => {
|
||||
return {
|
||||
@@ -15,8 +10,6 @@ export default (): INanobananaState => {
|
||||
tasks: undefined,
|
||||
credential: undefined,
|
||||
config: {
|
||||
action: NANOBANANA_DEFAULT_ACTION,
|
||||
aspect_ratio: NANOBANANA_DEFAULT_ASPECT_RATIO,
|
||||
model: NANOBANANA_DEFAULT_MODEL,
|
||||
resolution: NANOBANANA_DEFAULT_RESOLUTION
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user