nroggendorff commited on
Commit
8a0ba18
·
verified ·
1 Parent(s): dbe7fef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -5,11 +5,15 @@ import torch
5
  from diffusers import FluxPipeline
6
 
7
  pipeline = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.float16).to("cuda")
8
- pipeline.load_lora_weights("pepper13/fluxfw")
9
  #pipeline.enable_model_cpu_offload()
10
 
11
  @spaces.GPU(duration=70)
12
- def generate(prompt, negative_prompt, width, height, sample_steps):
 
 
 
 
 
13
  return pipeline(prompt=f"{prompt}\nDO NOT INCLUDE {negative_prompt}", width=width, height=height, num_inference_steps=sample_steps, generator=torch.Generator("cpu").manual_seed(42), guidance_scale=7).images[0]
14
 
15
  with gr.Blocks() as interface:
@@ -29,8 +33,9 @@ with gr.Blocks() as interface:
29
  height = gr.Slider(label="Height", info="The height in pixels of the generated image.", value=512, minimum=128, maximum=4096, step=64, interactive=True)
30
  with gr.Column():
31
  sampling_steps = gr.Slider(label="Sampling Steps", info="The number of denoising steps.", value=20, minimum=4, maximum=50, step=1, interactive=True)
 
32
 
33
- generate_button.click(fn=generate, inputs=[prompt, negative_prompt, width, height, sampling_steps], outputs=[output])
34
 
35
  if __name__ == "__main__":
36
  interface.launch()
 
5
  from diffusers import FluxPipeline
6
 
7
  pipeline = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.float16).to("cuda")
 
8
  #pipeline.enable_model_cpu_offload()
9
 
10
  @spaces.GPU(duration=70)
11
+ def generate(prompt, negative_prompt, width, height, sample_steps, lora_id):
12
+ try:
13
+ pipeline.load_lora_weights(lora_id)
14
+ except Exception as e:
15
+ return f"An error occured while loading the adapter: {e}."
16
+
17
  return pipeline(prompt=f"{prompt}\nDO NOT INCLUDE {negative_prompt}", width=width, height=height, num_inference_steps=sample_steps, generator=torch.Generator("cpu").manual_seed(42), guidance_scale=7).images[0]
18
 
19
  with gr.Blocks() as interface:
 
33
  height = gr.Slider(label="Height", info="The height in pixels of the generated image.", value=512, minimum=128, maximum=4096, step=64, interactive=True)
34
  with gr.Column():
35
  sampling_steps = gr.Slider(label="Sampling Steps", info="The number of denoising steps.", value=20, minimum=4, maximum=50, step=1, interactive=True)
36
+ lora_id = gr.Textbox(label="Adapter Repository", info="ID of the FLUX LoRA", value="pepper13/fluxfw")
37
 
38
+ generate_button.click(fn=generate, inputs=[prompt, negative_prompt, width, height, sampling_steps, lora_id], outputs=[output])
39
 
40
  if __name__ == "__main__":
41
  interface.launch()