Skip to content

Commit

Permalink
feat: improved real-time painting generation support
Browse files Browse the repository at this point in the history
  • Loading branch information
kangfenmao committed Oct 31, 2024
1 parent f6aa0dc commit 31fa10f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/renderer/src/pages/paintings/PaintingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ import { TEXT_TO_IMAGES_MODELS } from '@renderer/config/models'
import { useTheme } from '@renderer/context/ThemeProvider'
import { usePaintings } from '@renderer/hooks/usePaintings'
import { useAllProviders } from '@renderer/hooks/useProvider'
import { useRuntime } from '@renderer/hooks/useRuntime'
import AiProvider from '@renderer/providers/AiProvider'
import { getProviderByModel } from '@renderer/services/AssistantService'
import FileManager from '@renderer/services/FileManager'
import { useAppDispatch } from '@renderer/store'
import { DEFAULT_PAINTING } from '@renderer/store/paintings'
import { setGenerating } from '@renderer/store/runtime'
import { FileType, Painting } from '@renderer/types'
import { getErrorMessage } from '@renderer/utils'
import { Button, Input, InputNumber, Radio, Select, Slider, Tooltip } from 'antd'
Expand Down Expand Up @@ -76,6 +79,8 @@ const PaintingsPage: FC = () => {

const [isLoading, setIsLoading] = useState(false)
const [abortController, setAbortController] = useState<AbortController | null>(null)
const dispatch = useAppDispatch()
const { generating } = useRuntime()

const modelOptions = TEXT_TO_IMAGES_MODELS.map((model) => ({
label: model.name,
Expand Down Expand Up @@ -138,6 +143,7 @@ const PaintingsPage: FC = () => {
const controller = new AbortController()
setAbortController(controller)
setIsLoading(true)
dispatch(setGenerating(true))
const AI = new AiProvider(provider)

try {
Expand Down Expand Up @@ -179,6 +185,7 @@ const PaintingsPage: FC = () => {
}
} finally {
setIsLoading(false)
dispatch(setGenerating(false))
setAbortController(null)
}
}
Expand Down Expand Up @@ -219,6 +226,7 @@ const PaintingsPage: FC = () => {
}

const onSelectPainting = (newPainting: Painting) => {
if (generating) return
setPainting(newPainting)
setCurrentImageIndex(0)
}
Expand Down

0 comments on commit 31fa10f

Please sign in to comment.