kaytoo2022 commited on
Commit
9b81854
·
verified ·
1 Parent(s): 3bff17b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -17,20 +17,24 @@ lora_repo = "kaytoo2022/kaytoo2022-flux"
17
  trigger_word = "" # Leave trigger_word blank if not used.
18
  pipe.load_lora_weights(lora_repo, adapter_name='kaytoo')
19
 
20
- # pipe.set_adapters(["kaytoo"], adapter_weights=[0.85])
 
 
 
 
21
 
22
  pipe.to("cuda")
23
 
24
  MAX_SEED = 2**32-1
25
 
26
  @spaces.GPU()
27
- def run_lora(prompt, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale, progress=gr.Progress(track_tqdm=True)):
28
  # Set random seed for reproducibility
29
  if randomize_seed:
30
  seed = random.randint(0, MAX_SEED)
31
  generator = torch.Generator(device="cuda").manual_seed(seed)
32
 
33
- # pipe.set_adapters(["kaytoo"], adapter_weights=[lora_scale])
34
 
35
  # Update progress bar (0% saat mulai)
36
  progress(0, "Starting image generation...")
@@ -66,11 +70,12 @@ example_width = 1152
66
  example_height = 896
67
  example_seed = 3981632454
68
  example_lora_scale = 0.85
 
69
 
70
  def load_example():
71
  # Load example image from file
72
  example_image = Image.open(example_image_path)
73
- return example_prompt, example_cfg_scale, example_steps, True, example_seed, example_width, example_height, example_lora_scale, example_image
74
 
75
  with gr.Blocks() as app:
76
  gr.Markdown("# Flux Lora Image Generator")
@@ -85,12 +90,13 @@ with gr.Blocks() as app:
85
  randomize_seed = gr.Checkbox(True, label="Randomize seed")
86
  seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=example_seed)
87
  lora_scale = gr.Slider(label="LoRA Scale", minimum=0, maximum=1, step=0.01, value=example_lora_scale)
 
88
  with gr.Column(scale=1):
89
  result = gr.Image(label="Generated Image")
90
  gr.Markdown("Generate images using Flux and a text prompt.\nUse `b3lla dog` in the prompt to trigger generating an image of Bella the dog.\n[[non-commercial license, Flux.1 Dev](https://huggingface.co/black-forest-labs/FLUX.1-dev/blob/main/LICENSE.md)]")
91
 
92
  # Automatically load example data and image when the interface is launched
93
- app.load(load_example, inputs=[], outputs=[prompt, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale, result])
94
 
95
  generate_button.click(
96
  run_lora,
 
17
  trigger_word = "" # Leave trigger_word blank if not used.
18
  pipe.load_lora_weights(lora_repo, adapter_name='kaytoo')
19
 
20
+ # ghibsky
21
+ lora_repo_2 = "aleksa-codes/flux-ghibsky-illustration"
22
+ pipe.load_lora_weights(lora_repo_ghibsky, adapter_name='lora_2')
23
+
24
+ pipe.set_adapters(["kaytoo", "lora_2"], adapter_weights=[0.85, 0])
25
 
26
  pipe.to("cuda")
27
 
28
  MAX_SEED = 2**32-1
29
 
30
  @spaces.GPU()
31
+ def run_lora(prompt, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale, lora_scale_2, progress=gr.Progress(track_tqdm=True)):
32
  # Set random seed for reproducibility
33
  if randomize_seed:
34
  seed = random.randint(0, MAX_SEED)
35
  generator = torch.Generator(device="cuda").manual_seed(seed)
36
 
37
+ pipe.set_adapters(["kaytoo", "lora_2"], adapter_weights=[lora_scale, lora_scale_2])
38
 
39
  # Update progress bar (0% saat mulai)
40
  progress(0, "Starting image generation...")
 
70
  example_height = 896
71
  example_seed = 3981632454
72
  example_lora_scale = 0.85
73
+ example_lora_scale_2 = 0
74
 
75
  def load_example():
76
  # Load example image from file
77
  example_image = Image.open(example_image_path)
78
+ return example_prompt, example_cfg_scale, example_steps, True, example_seed, example_width, example_height, example_lora_scale, example_lora_scale_2, example_image
79
 
80
  with gr.Blocks() as app:
81
  gr.Markdown("# Flux Lora Image Generator")
 
90
  randomize_seed = gr.Checkbox(True, label="Randomize seed")
91
  seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=example_seed)
92
  lora_scale = gr.Slider(label="LoRA Scale", minimum=0, maximum=1, step=0.01, value=example_lora_scale)
93
+ lora_scale_2 = gr.Slider(label="LoRA Scale (GhibSky)", minimum=0, maximum=1, step=0.01, value=example_lora_scale)
94
  with gr.Column(scale=1):
95
  result = gr.Image(label="Generated Image")
96
  gr.Markdown("Generate images using Flux and a text prompt.\nUse `b3lla dog` in the prompt to trigger generating an image of Bella the dog.\n[[non-commercial license, Flux.1 Dev](https://huggingface.co/black-forest-labs/FLUX.1-dev/blob/main/LICENSE.md)]")
97
 
98
  # Automatically load example data and image when the interface is launched
99
+ app.load(load_example, inputs=[], outputs=[prompt, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale, lora_scale_2, result])
100
 
101
  generate_button.click(
102
  run_lora,