Skip to content

Commit

Permalink
improve config detection
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonywu committed Oct 19, 2024
1 parent 50cab7b commit 6d5d213
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/mflux/ui/cli/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,15 @@ def add_controlnet_arguments(self) -> None:

def add_metadata_config(self) -> None:
self.supports_metadata_config = True
self.add_argument("--config-from-metadata", "-C", type=Path, required=False, default=argparse.SUPPRESS, help="Re-use the parameters from prior metadata. Params from metadata are secondary to other args you provide.")
self.add_argument("--config-from-metadata", "-C", type=Path, required=False, default=None, help="Re-use the parameters from prior metadata. Params from metadata are secondary to other args you provide.")

def parse_args(self, **kwargs) -> argparse.Namespace:
namespace = super().parse_args()
if hasattr(namespace, "path") and namespace.path is not None and namespace.model is None:
namespace.error("--model must be specified when using --path")

if getattr(namespace, "config_from_metadata", False):
if self.supports_metadata_config and namespace.config_from_metadata is not None:
prior_gen_metadata = json.load(namespace.config_from_metadata.open("rt"))

if namespace.prompt is None:
namespace.prompt = prior_gen_metadata.get("prompt", None)

Expand Down Expand Up @@ -108,13 +107,13 @@ def parse_args(self, **kwargs) -> argparse.Namespace:
namespace.init_image_strength = init_img_strength_from_metadata

if self.supports_controlnet:
# todo: support more controlnet flags, but may require a follow-up PR
# and maybe after consolidating the flux/cnet implementations somehow
if namespace.controlnet_image_path is None:
namespace.controlnet_image_path = prior_gen_metadata.get("controlnet_image_path", None)
if namespace.controlnet_strength == self.get_default("controlnet_strength") and (cnet_strength_from_metadata := prior_gen_metadata.get("controlnet_strength", None)):
namespace.controlnet_strength = cnet_strength_from_metadata



if namespace.prompt is None:
# not supplied by CLI and not supplied by metadata config file
self.error("--prompt argument required or 'prompt' required in metadata config file")
Expand Down

0 comments on commit 6d5d213

Please sign in to comment.