From 3717ff25bff3759cc79fc20990b954a7414c7276 Mon Sep 17 00:00:00 2001 From: kangfenmao Date: Sat, 30 Nov 2024 14:18:45 +0800 Subject: [PATCH] feat: generate random seed for image generation in usepaintings hook --- src/renderer/src/hooks/usePaintings.ts | 3 ++- src/renderer/src/pages/paintings/PaintingsPage.tsx | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/renderer/src/hooks/usePaintings.ts b/src/renderer/src/hooks/usePaintings.ts index 13eb21b1..b01c0acc 100644 --- a/src/renderer/src/hooks/usePaintings.ts +++ b/src/renderer/src/hooks/usePaintings.ts @@ -8,6 +8,7 @@ import { uuid } from '@renderer/utils' export function usePaintings() { const paintings = useAppSelector((state) => state.paintings.paintings) const dispatch = useAppDispatch() + const generateRandomSeed = () => Math.floor(Math.random() * 1000000).toString() return { paintings, @@ -20,7 +21,7 @@ export function usePaintings() { negativePrompt: '', imageSize: '1024x1024', numImages: 1, - seed: '', + seed: generateRandomSeed(), steps: 25, guidanceScale: 4.5, model: TEXT_TO_IMAGES_MODELS[0].id diff --git a/src/renderer/src/pages/paintings/PaintingsPage.tsx b/src/renderer/src/pages/paintings/PaintingsPage.tsx index 275ed070..7e5b4f83 100644 --- a/src/renderer/src/pages/paintings/PaintingsPage.tsx +++ b/src/renderer/src/pages/paintings/PaintingsPage.tsx @@ -1,4 +1,4 @@ -import { PlusOutlined, QuestionCircleOutlined } from '@ant-design/icons' +import { PlusOutlined, QuestionCircleOutlined, RedoOutlined } from '@ant-design/icons' import ImageSize1_1 from '@renderer/assets/images/paintings/image-size-1-1.svg' import ImageSize1_2 from '@renderer/assets/images/paintings/image-size-1-2.svg' import ImageSize3_2 from '@renderer/assets/images/paintings/image-size-3-2.svg' @@ -308,7 +308,12 @@ const PaintingsPage: FC = () => { updatePaintingState({ seed: e.target.value })} - suffix={ updatePaintingState({ seed: '' })} />} + suffix={ + updatePaintingState({ seed: Math.floor(Math.random() * 1000000).toString() })} + style={{ cursor: 'pointer', color: 'var(--color-text-2)' }} + /> + } /> @@ -502,7 +507,7 @@ const InfoIcon = styled(QuestionCircleOutlined)` } ` -const RefreshIcon = styled.span` +const RefreshIcon = styled(RedoOutlined)` cursor: pointer; `