Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation for custom scripts? #139

Open
pjain opened this issue Mar 8, 2025 · 0 comments
Open

Documentation for custom scripts? #139

pjain opened this issue Mar 8, 2025 · 0 comments

Comments

@pjain
Copy link

pjain commented Mar 8, 2025

Using the example below, I'd like to instantiate the model once and generate multiple images. In some cases, the image may require a LoRA or Multiple LoRAs.


# Load the model
flux = Flux1.from_name(
   model_name="schnell",  # "schnell" or "dev"
   quantize=8,            # 4 or 8
)

# Generate an image
image = flux.generate_image(
   seed=2,
   prompt="Luxury food photograph",
   config=Config(
      num_inference_steps=2,  # "schnell" works well with 2-4 steps, "dev" works well with 20-25 steps
      height=1024,
      width=1024,
   )
)

image.save(path="image.png")

Is there a way to do something like this to set and reset LoRAs per image being created rather than having to initialize the model again?

from mflux import Flux1, Config

# Load the model
flux = Flux1.from_name(
   model_name="schnell",  # "schnell" or "dev"
   quantize=8,            # 4 or 8
)


foo = {
    'a': {'prompt': 'foo',
          'lora': '/usr/local/fbar'},
    'b': {'prompt': 'bar'},
    'c': {'prompt': 'fubar',
          'lora': ['/usr/local/fbar', '/usr/lcoal/bbar'],
          'scales': '0.5 0.9'
          }
}

for key, value in foo.items():
    if 'lora' in value and value['lora']:
        flux.lora_paths = value['lora']
    else:
        # reset the lora to nothing in case this image doesn't have one
        flux.lora_paths = None
    if 'scales' in value and value['scales']:
        flux.lora_scales = value['scales']
    else:
        # reset the lora to nothing in case this image doesn't have one
        flux.lora_scales = Nonex
                                   
    # Generate an image
    image = flux.generate_image(
        seed=2,
        prompt=p,
        config=Config(
            num_inference_steps=2,  # "schnell" works well with 2-4 steps, "dev" works well with 20-25 steps
            height=1024,
            width=1024,
        )
    )

    image.save(path="image.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant