Fooocus icon indicating copy to clipboard operation
Fooocus copied to clipboard

Add preset selection to Gradio UI (session based)

Open mashb1t opened this issue 1 year ago • 10 comments

This PR implements a preset selection via radio buttons, which only affects the current gradio session and does not change settings globally. To achieve this, the logic of the recently implemented meta_parser is used to update the elements in gradio. If a preset file doesn't include specific keys mentioned in modules.config.possible_preset_keys, the initial config is used (incl. preset set in args). Also directly downlaods requirements of a specific preset, allowing usage without having to restart the app (very helpful for Colab).

This offers the flexibility to change all preset keys without having to reload the UI while still keeping the preset set on application start as default/fallback.

mashb1t avatar Dec 23 '23 20:12 mashb1t

Thank you so much. Unfortunately, the format of the preset is partially the same as the format of the meta_parser. QQ截图20231224085705

"Resolution": "(1152, 896)",---------- "default_aspect_ratio": "896*1152", "Styles": "['Fooocus V2', 'Fooocus Enhance', 'Fooocus Sharp']",--------------- "default_styles": ["Fooocus V2","Fooocus Masterpiece","SAI Anime","SAI Digital Art","SAI Enhance","SAI Fantasy Art"], These two toggles were found to have no effect

xhoxye avatar Dec 24 '23 00:12 xhoxye

Sorry, i do not completely get what you are referring to. Which two toggles do you mean that have no effect?

As of https://github.com/lllyasviel/Fooocus/tree/main/presets the "turbo" preset is not a default preset and you most likely have created this yourself, please double check the content there. In general, only keys of the preset mentioned in https://github.com/lllyasviel/Fooocus/blob/main/modules/config.py#L318 will be used to import settings for preset,s so the key "Styles" from the file you mentioned will not be taken into account.

All options from https://github.com/lllyasviel/Fooocus/blob/main/modules/config.py#L318 (except model download) are mapped to their specific meta identifier counterpart, so they can be set using the same logic as the meta prompt parser, which is intended. Nevertheless, there should not be any overlaps between the features which are user facing.

Please elaborate where exactly you have issues and send the content of your turbo.json preset if this one causes issues for you.

mashb1t avatar Dec 24 '23 01:12 mashb1t

It has nothing to do with turbo, the resolution and style of other default presets cannot be loaded.

xhoxye avatar Dec 24 '23 01:12 xhoxye

thank you for the feedback, i'll double-check tomorrow

mashb1t avatar Dec 24 '23 01:12 mashb1t

@xhoxye both resolution and style are now processed correctly + i've also added style sorting after preset load. Feel free to test again, your feedback is welcome!

mashb1t avatar Dec 24 '23 10:12 mashb1t

It already loads normally. There is a small problem, but it has nothing to do with your code, that is, the "default_refiner": "" in realistic.json will cause the task to cannot be started after the switch, and it needs to be modified to "default_refiner": "None" in order to start the task normally. QQ截图20231224194245 QQ截图20231224194229

xhoxye avatar Dec 24 '23 11:12 xhoxye

@xhoxye both resolution and style are now processed correctly + i've also added style sorting after preset load. Feel free to test again, your feedback is welcome!

THANKS btw I did not understand How i can always run dreamshaperXL-Turbo with all the currect settings like cfg 1.4 sharpness 3 sampler dpmmeSDE etc eg by defult please?

Amit30swgoh avatar Dec 28 '23 09:12 Amit30swgoh

THANKS btw I did not understand How i can always run dreamshaperXL-Turbo with all the currect settings like cfg 1.4 sharpness 3 sampler dpmmeSDE etc eg by defult please?

I think what you're looking for is a combination of this PR and https://github.com/lllyasviel/Fooocus/pull/1580, as Turbo is not included here. For now, it might be easiest for you to apply the changes of both PRs or to download my fork https://github.com/mashb1t/Fooocus including both features already (by changing the git remote URL or downloading code directly).

mashb1t avatar Dec 28 '23 09:12 mashb1t

THANKS btw I did not understand How i can always run dreamshaperXL-Turbo with all the currect settings like cfg 1.4 sharpness 3 sampler dpmmeSDE etc eg by defult please?

I think what you're looking for is a combination of this PR and #1580, as Turbo is not included here. For now, it might be easiest for you to apply the changes of both PRs or to download my fork https://github.com/mashb1t/Fooocus including both features already (by changing the git remote URL or downloading code directly).

Ty again closing btw about nsfw i have option turn it on and off or by default it will be cencored forever?

Amit30swgoh avatar Dec 28 '23 09:12 Amit30swgoh

@Amit30swgoh this PR is not about NSFW, please add your questions/comments to https://github.com/lllyasviel/Fooocus/issues/950.

mashb1t avatar Dec 28 '23 16:12 mashb1t

It's working very well for me. Thanks so much!

Here's some feedback:

  • When switching between presets, the Image Number should remain rather than resetting to 1.
  • A new preset option, similar to the initial, should be added to indicate that the current configurations are parsed from the clipboard. This isn't a major issue, but it would clarify the interface.

I'd also like to suggest some new features:

  • An option in the user interface to save the current configurations as a new preset.
  • It would be helpful if tooltips displayed the contents of a preset when you hover over it.
  • It'd be better if the user-inputted prompts (both positive and negative) were kept when switching presets. Only the preset's default prompts get appended or removed. This is just my own pref, and I understand others might think differently.

Thanks again!

peterng1618 avatar Jan 02 '24 14:01 peterng1618

@peterng1618 all good ideas, but let's keep this MR simple and extend the functionality after it has been merged.

mashb1t avatar Jan 02 '24 21:01 mashb1t

Does it conflict with 2.1.861?

xhoxye avatar Jan 08 '24 05:01 xhoxye

@xhoxye no, why should it?

mashb1t avatar Jan 08 '24 07:01 mashb1t

@xhoxye no, why should it?

This was my mistake because I had a conflict when trying to merge into my branch, but I resolved it later.

xhoxye avatar Jan 08 '24 11:01 xhoxye

How do you enable the presets? My version of Fooocus looks like this: presets missing temp flie

3Diva avatar Jan 14 '24 01:01 3Diva

@3Diva this PR is still awaiting review and has not yet been merged. You can already use the feature by checking out the git branch feature/add-preset-selection or main of my fork https://github.com/mashb1t/Fooocus by adding a git remote to your local repo OR you can use it by manually applying the file changes of this PR to your local installation.

mashb1t avatar Jan 14 '24 08:01 mashb1t

@mashb1t Oh thank you for the link, I appreciate it. I'm looking forward to checking out your fork of Fooocus! :D The presets sound like a great idea! I often use LCM models and Turbo models with Fooocus and it can be a pain to set up and change all the settings every time. Having presets for a quick one button enable of those settings would be amazingly cool and SO HELPFUL! 😊

I hope that a preset system gets added to vanilla Fooocus too, even if the creator of it chooses to hide it behind the "Advanced" tab, it would be nice to have presets available in Fooocus.

3Diva avatar Jan 14 '24 22:01 3Diva

2.1.864 Could not load "default_overwrite_step" this parameter?

xhoxye avatar Feb 03 '24 01:02 xhoxye