fix: image default seed
This commit is contained in:
@@ -8,8 +8,7 @@ import React, {
|
|||||||
useCallback,
|
useCallback,
|
||||||
useEffect,
|
useEffect,
|
||||||
useId,
|
useId,
|
||||||
useImperativeHandle,
|
useImperativeHandle
|
||||||
useMemo
|
|
||||||
} from 'react';
|
} from 'react';
|
||||||
import { ParamsSchema } from '../config/types';
|
import { ParamsSchema } from '../config/types';
|
||||||
|
|
||||||
@@ -36,8 +35,6 @@ const ParamsSettings: React.FC<ParamsSettingsProps> = forwardRef(
|
|||||||
initialValues,
|
initialValues,
|
||||||
paramsConfig,
|
paramsConfig,
|
||||||
modelList,
|
modelList,
|
||||||
watchFields,
|
|
||||||
formFields,
|
|
||||||
showModelSelector = true,
|
showModelSelector = true,
|
||||||
extra
|
extra
|
||||||
},
|
},
|
||||||
@@ -102,12 +99,12 @@ const ParamsSettings: React.FC<ParamsSettingsProps> = forwardRef(
|
|||||||
[intl]
|
[intl]
|
||||||
);
|
);
|
||||||
|
|
||||||
const renderFields = useMemo(() => {
|
const renderFields = () => {
|
||||||
if (!paramsConfig?.length) {
|
if (!paramsConfig?.length) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
console.log('renderFields---------');
|
const values = form.getFieldsValue();
|
||||||
const formValues = form?.getFieldsValue();
|
const formValues = _.isEmpty(values) ? initialValues || {} : values;
|
||||||
return paramsConfig?.map((item: ParamsSchema) => {
|
return paramsConfig?.map((item: ParamsSchema) => {
|
||||||
return (
|
return (
|
||||||
<Form.Item
|
<Form.Item
|
||||||
@@ -136,7 +133,7 @@ const ParamsSettings: React.FC<ParamsSettingsProps> = forwardRef(
|
|||||||
</Form.Item>
|
</Form.Item>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}, [formFields, paramsConfig, intl, watchFields]);
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form
|
<Form
|
||||||
@@ -185,7 +182,7 @@ const ParamsSettings: React.FC<ParamsSettingsProps> = forwardRef(
|
|||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
{renderFields}
|
{renderFields()}
|
||||||
{extra}
|
{extra}
|
||||||
</div>
|
</div>
|
||||||
</Form>
|
</Form>
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
handleToggleParamsStyle,
|
handleToggleParamsStyle,
|
||||||
setParams,
|
setParams,
|
||||||
form,
|
form,
|
||||||
watchFields,
|
|
||||||
formFields,
|
formFields,
|
||||||
paramsConfig,
|
paramsConfig,
|
||||||
initialValues,
|
initialValues,
|
||||||
@@ -142,7 +141,7 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
const generateParams = () => {
|
const generateParams = () => {
|
||||||
const params = {
|
const params = {
|
||||||
..._.omitBy(finalParameters, (value: string) => !value),
|
..._.omitBy(finalParameters, (value: string) => !value),
|
||||||
seed: parameters.random_seed ? generateRandomNumber() : parameters.seed,
|
seed: parameters.random_seed ? generateRandomNumber() : null,
|
||||||
stream: false,
|
stream: false,
|
||||||
prompt: currentPrompt
|
prompt: currentPrompt
|
||||||
};
|
};
|
||||||
@@ -272,7 +271,6 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
<div className="box">
|
<div className="box">
|
||||||
<DynamicParams
|
<DynamicParams
|
||||||
ref={form}
|
ref={form}
|
||||||
watchFields={watchFields}
|
|
||||||
formFields={formFields}
|
formFields={formFields}
|
||||||
parametersTitle={
|
parametersTitle={
|
||||||
<div className="flex-between flex-center">
|
<div className="flex-between flex-center">
|
||||||
|
|||||||
@@ -77,7 +77,6 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
setParamsConfig,
|
setParamsConfig,
|
||||||
form,
|
form,
|
||||||
modelMeta,
|
modelMeta,
|
||||||
watchFields,
|
|
||||||
formFields,
|
formFields,
|
||||||
paramsConfig,
|
paramsConfig,
|
||||||
initialValues,
|
initialValues,
|
||||||
@@ -167,7 +166,7 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
const generateParams = () => {
|
const generateParams = () => {
|
||||||
const params = {
|
const params = {
|
||||||
..._.omitBy(finalParameters, (value: string) => !value),
|
..._.omitBy(finalParameters, (value: string) => !value),
|
||||||
seed: parameters.random_seed ? generateRandomNumber() : parameters.seed,
|
seed: parameters.random_seed ? generateRandomNumber() : null,
|
||||||
stream: false,
|
stream: false,
|
||||||
prompt: currentPrompt
|
prompt: currentPrompt
|
||||||
};
|
};
|
||||||
@@ -518,7 +517,6 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
<div className="box">
|
<div className="box">
|
||||||
<DynamicParams
|
<DynamicParams
|
||||||
ref={form}
|
ref={form}
|
||||||
watchFields={watchFields}
|
|
||||||
formFields={formFields}
|
formFields={formFields}
|
||||||
parametersTitle={
|
parametersTitle={
|
||||||
<div className="flex-between flex-center">
|
<div className="flex-between flex-center">
|
||||||
|
|||||||
@@ -51,15 +51,15 @@ export const llmInitialValues = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const advancedFieldsDefaultValus = {
|
export const advancedFieldsDefaultValus = {
|
||||||
seed: null,
|
seed: null
|
||||||
sample_method: 'euler_a',
|
// sample_method: 'euler_a',
|
||||||
cfg_scale: 4.5,
|
// cfg_scale: 4.5,
|
||||||
guidance: 3.5,
|
// guidance: 3.5,
|
||||||
sampling_steps: 10,
|
// sampling_steps: 10,
|
||||||
negative_prompt: null,
|
// negative_prompt: null,
|
||||||
strength: null,
|
// strength: null,
|
||||||
schedule_method: 'discrete',
|
// schedule_method: 'discrete',
|
||||||
preview: 'preview_faster'
|
// preview: 'preview_faster'
|
||||||
};
|
};
|
||||||
|
|
||||||
export const openaiCompatibleFieldsDefaultValus = {
|
export const openaiCompatibleFieldsDefaultValus = {
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ import {
|
|||||||
ImageAdvancedParamsConfig as ImgAdvancedParamsConfig,
|
ImageAdvancedParamsConfig as ImgAdvancedParamsConfig,
|
||||||
imageSizeOptions as imageSizeList
|
imageSizeOptions as imageSizeList
|
||||||
} from '@/pages/playground/config/params-config';
|
} from '@/pages/playground/config/params-config';
|
||||||
|
import { generateRandomNumber } from '@/utils';
|
||||||
import { useSearchParams } from '@umijs/max';
|
import { useSearchParams } from '@umijs/max';
|
||||||
import { Form } from 'antd';
|
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import React, {
|
import React, {
|
||||||
useCallback,
|
useCallback,
|
||||||
@@ -229,6 +229,8 @@ export const useInitImageMeta = (
|
|||||||
const [initialValues, setInitialValues] = useState<any>({
|
const [initialValues, setInitialValues] = useState<any>({
|
||||||
...imgInitialValues,
|
...imgInitialValues,
|
||||||
...advancedFieldsDefaultValus,
|
...advancedFieldsDefaultValus,
|
||||||
|
seed: generateRandomNumber(),
|
||||||
|
random_seed: true,
|
||||||
model: ''
|
model: ''
|
||||||
});
|
});
|
||||||
const [paramsConfig, setParamsConfig] = useState<ParamsSchema[]>([
|
const [paramsConfig, setParamsConfig] = useState<ParamsSchema[]>([
|
||||||
@@ -240,6 +242,8 @@ export const useInitImageMeta = (
|
|||||||
const [parameters, setParams] = useState<any>({
|
const [parameters, setParams] = useState<any>({
|
||||||
...imgInitialValues,
|
...imgInitialValues,
|
||||||
...advancedFieldsDefaultValus,
|
...advancedFieldsDefaultValus,
|
||||||
|
seed: generateRandomNumber(),
|
||||||
|
random_seed: true,
|
||||||
model: ''
|
model: ''
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -252,11 +256,6 @@ export const useInitImageMeta = (
|
|||||||
...openaiCompatibleFieldsDefaultValus,
|
...openaiCompatibleFieldsDefaultValus,
|
||||||
...advancedFieldsDefaultValus
|
...advancedFieldsDefaultValus
|
||||||
});
|
});
|
||||||
const randomSeed = Form.useWatch('random_seed', form.current?.form);
|
|
||||||
|
|
||||||
const watchFields = useMemo(() => {
|
|
||||||
return ['random_seed'];
|
|
||||||
}, [randomSeed]);
|
|
||||||
|
|
||||||
const getNewImageSizeOptions = (metaData: any) => {
|
const getNewImageSizeOptions = (metaData: any) => {
|
||||||
const { max_height, max_width } = metaData || {};
|
const { max_height, max_width } = metaData || {};
|
||||||
@@ -436,6 +435,7 @@ export const useInitImageMeta = (
|
|||||||
|
|
||||||
const handleOnValuesChange = useCallback(
|
const handleOnValuesChange = useCallback(
|
||||||
(changeValues: Record<string, any>, allValues: Record<string, any>) => {
|
(changeValues: Record<string, any>, allValues: Record<string, any>) => {
|
||||||
|
console.log('changeValues', changeValues);
|
||||||
// model change will reset all values
|
// model change will reset all values
|
||||||
if (changeValues.model) {
|
if (changeValues.model) {
|
||||||
handleOnModelChange(changeValues.model);
|
handleOnModelChange(changeValues.model);
|
||||||
@@ -469,6 +469,16 @@ export const useInitImageMeta = (
|
|||||||
]);
|
]);
|
||||||
setParams(allValues);
|
setParams(allValues);
|
||||||
updateCacheFormData(changeValues);
|
updateCacheFormData(changeValues);
|
||||||
|
} else if (_.isBoolean(changeValues.random_seed)) {
|
||||||
|
const seed = changeValues.random_seed ? generateRandomNumber() : null;
|
||||||
|
setParams({
|
||||||
|
...allValues,
|
||||||
|
seed: seed
|
||||||
|
});
|
||||||
|
form.current?.form?.setFieldsValue({
|
||||||
|
seed: seed
|
||||||
|
});
|
||||||
|
updateCacheFormData(changeValues);
|
||||||
} else {
|
} else {
|
||||||
setParams(allValues);
|
setParams(allValues);
|
||||||
updateCacheFormData(changeValues);
|
updateCacheFormData(changeValues);
|
||||||
@@ -503,7 +513,6 @@ export const useInitImageMeta = (
|
|||||||
form,
|
form,
|
||||||
modelMeta,
|
modelMeta,
|
||||||
formFields,
|
formFields,
|
||||||
watchFields,
|
|
||||||
paramsConfig,
|
paramsConfig,
|
||||||
initialValues,
|
initialValues,
|
||||||
parameters,
|
parameters,
|
||||||
|
|||||||
Reference in New Issue
Block a user