Skip to content

Commit

Permalink
configurable AIGC feature (#726)
Browse files Browse the repository at this point in the history
  • Loading branch information
nighca authored Aug 9, 2024
1 parent 2b0440d commit 40c7824
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
3 changes: 3 additions & 0 deletions spx-gui/.env
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ VITE_CASDOOR_APP_NAME="application_goplusCommunity"

VITE_API_BASE_URL="/api"

# Features control
VITE_DISABLE_AIGC="false"

# This base URL is used by Vercel Edge Middleware to proxy all '/api/(.*)' requests.
# The path prefix '/api' is stripped before forwarding.
VERCEL_PROXIED_API_BASE_URL="https://goplus-builder.qiniu.io/api"
38 changes: 29 additions & 9 deletions spx-gui/src/components/asset/preprocessing/PreprocessModal.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<UIFormModal
style="width: 780px"
:visible="props.visible"
:visible="props.visible && ready"
:title="$t(actionMessage)"
:body-style="{ padding: '0' }"
@update:visible="emit('cancelled')"
Expand Down Expand Up @@ -45,7 +45,7 @@
:input="getMethodInput(method.value)"
:applied="isMethodApplied(method.value)"
@applied="(output) => handleMethodApplied(method.value, output)"
@cancel="cancelMethod(method.value)"
@cancel="handleMethodCancel(method.value)"
/>
</div>
</main>
Expand Down Expand Up @@ -80,6 +80,7 @@
import { computed, ref, shallowReactive, shallowRef, watch } from 'vue'
import { stripExt } from '@/utils/path'
import type { LocaleMessage } from '@/utils/i18n'
import { disableAIGC } from '@/utils/env'
import { Costume } from '@/models/costume'
import { File } from '@/models/common/file'
import { UIButton, UIFormModal } from '@/components/ui'
Expand Down Expand Up @@ -123,14 +124,16 @@ type MethodItem = {
* The order of methods is the order of applying.
*/
const supportedMethods = computed(() => {
const methods: MethodItem[] = [
{
const methods: MethodItem[] = []
if (!disableAIGC) {
methods.push({
value: Method.RemoveBackground,
name: { en: 'Remove background', zh: '去除背景' },
thumbnail: removeBackgroundThumbnail,
component: RemoveBackground
}
]
})
}
if (props.files.length === 1) {
methods.push({
Expand Down Expand Up @@ -180,13 +183,18 @@ function handleMethodApplied(method: Method, output: File[]) {
updateCostumes(output)
}
function cancelMethod(method: Method) {
function handleMethodCancel(method: Method) {
const idx = supportedMethods.value.findIndex((m) => m.value === method)
outputs.splice(idx)
outputs.push(null)
updateCostumes(getMethodInput(method))
}
function resetOutputs() {
outputs.splice(0)
updateCostumes(props.files)
}
const costumes = shallowRef<Costume[]>([])
const selectedCostumes = shallowReactive<Costume[]>([])
Expand All @@ -213,10 +221,22 @@ function handleConfirm() {
emit('resolved', selectedCostumes)
}
// Avoid UI flickering when there's no supported methods
const ready = ref(false)
watch(
() => props.files,
// The first method cancelled, all methods cancelled
() => cancelMethod(supportedMethods.value[0].value),
async (files) => {
// If there's no supported methods, skip user interaction and resolve with costumes created with original files
if (supportedMethods.value.length === 0) {
await updateCostumes(files)
emit('resolved', costumes.value)
return
}
ready.value = true
resetOutputs()
},
{ immediate: true }
)
</script>
Expand Down
6 changes: 6 additions & 0 deletions spx-gui/src/utils/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ export const casdoorConfig = {
organizationName: import.meta.env.VITE_CASDOOR_ORGANIZATION_NAME as string,
appName: import.meta.env.VITE_CASDOOR_APP_NAME as string
}

/**
* If we should disable features that rely on AIGC service.
* For now AIGC service is not ready for production. We disable it until it's ready.
*/
export const disableAIGC = import.meta.env.VITE_DISABLE_AIGC === 'true'

0 comments on commit 40c7824

Please sign in to comment.