Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: filipstrand <filipstrand@users.noreply.github.com>
63 lines
2.1 KiB
Python
63 lines
2.1 KiB
Python
from mflux import Config, StopImageGenerationException
|
|
from mflux.callbacks.callback_manager import CallbackManager
|
|
from mflux.error.exceptions import PromptFileReadError
|
|
from mflux.flux_tools.depth.flux_depth import Flux1Depth
|
|
from mflux.ui import defaults as ui_defaults
|
|
from mflux.ui.cli.parsers import CommandLineParser
|
|
from mflux.ui.prompt_utils import get_effective_prompt
|
|
|
|
|
|
def main():
|
|
# 0. Parse command line arguments
|
|
parser = CommandLineParser(description="Generate an image using the depth tool.")
|
|
parser.add_general_arguments()
|
|
parser.add_model_arguments(require_model_arg=False)
|
|
parser.add_lora_arguments()
|
|
parser.add_image_generator_arguments(supports_metadata_config=False)
|
|
parser.add_depth_arguments()
|
|
parser.add_output_arguments()
|
|
args = parser.parse_args()
|
|
|
|
# 0. Default to a medium guidance value for depth related tasks.
|
|
if args.guidance is None:
|
|
args.guidance = ui_defaults.DEFAULT_DEPTH_GUIDANCE
|
|
|
|
# 1. Load the model
|
|
flux = Flux1Depth(
|
|
quantize=args.quantize,
|
|
local_path=args.path,
|
|
lora_paths=args.lora_paths,
|
|
lora_scales=args.lora_scales,
|
|
)
|
|
|
|
# 2. Register callbacks
|
|
memory_saver = CallbackManager.register_callbacks(args=args, flux=flux, enable_depth_saver=True)
|
|
|
|
try:
|
|
for seed in args.seed:
|
|
# 3. Generate an image for each seed value
|
|
image = flux.generate_image(
|
|
seed=seed,
|
|
prompt=get_effective_prompt(args),
|
|
config=Config(
|
|
num_inference_steps=args.steps,
|
|
height=args.height,
|
|
width=args.width,
|
|
guidance=args.guidance,
|
|
image_path=args.image_path,
|
|
depth_image_path=args.depth_image_path,
|
|
),
|
|
)
|
|
|
|
# 4. Save the image
|
|
image.save(path=args.output.format(seed=seed), export_json_metadata=args.metadata)
|
|
except (StopImageGenerationException, PromptFileReadError) as exc:
|
|
print(exc)
|
|
finally:
|
|
if memory_saver:
|
|
print(memory_saver.memory_stats())
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|