Spaces:
Running
on
Zero
Running
on
Zero
kaytoo2022
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -17,23 +17,20 @@ 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 |
-
|
21 |
-
pipe.load_lora_weights(lora_repo_ghibsky, adapter_name='ghibsky')
|
22 |
-
|
23 |
-
pipe.set_adapters(["kaytoo", "ghibsky"], adapter_weights=[0.7, 0.3])
|
24 |
|
25 |
pipe.to("cuda")
|
26 |
|
27 |
MAX_SEED = 2**32-1
|
28 |
|
29 |
@spaces.GPU(duration=80)
|
30 |
-
def run_lora(prompt, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale,
|
31 |
# Set random seed for reproducibility
|
32 |
if randomize_seed:
|
33 |
seed = random.randint(0, MAX_SEED)
|
34 |
generator = torch.Generator(device="cuda").manual_seed(seed)
|
35 |
|
36 |
-
pipe.set_adapters(["kaytoo"
|
37 |
|
38 |
# Update progress bar (0% saat mulai)
|
39 |
progress(0, "Starting image generation...")
|
@@ -52,7 +49,7 @@ def run_lora(prompt, cfg_scale, steps, randomize_seed, seed, width, height, lora
|
|
52 |
width=width,
|
53 |
height=height,
|
54 |
generator=generator,
|
55 |
-
|
56 |
).images[0]
|
57 |
|
58 |
# Final update (100%)
|
@@ -69,12 +66,11 @@ example_width = 1152
|
|
69 |
example_height = 896
|
70 |
example_seed = 3981632454
|
71 |
example_lora_scale = 0.8
|
72 |
-
example_lora_scale_ghibsky = 0.3
|
73 |
|
74 |
def load_example():
|
75 |
# Load example image from file
|
76 |
example_image = Image.open(example_image_path)
|
77 |
-
return example_prompt, example_cfg_scale, example_steps, True, example_seed, example_width, example_height, example_lora_scale,
|
78 |
|
79 |
with gr.Blocks() as app:
|
80 |
gr.Markdown("# Flux Lora Image Generator")
|
@@ -89,17 +85,16 @@ with gr.Blocks() as app:
|
|
89 |
randomize_seed = gr.Checkbox(True, label="Randomize seed")
|
90 |
seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=example_seed)
|
91 |
lora_scale = gr.Slider(label="LoRA Scale", minimum=0, maximum=1, step=0.01, value=example_lora_scale)
|
92 |
-
lora_scale_ghibsky = gr.Slider(label="LoRA Scale (Ghibli sky)", minimum=0, maximum=1, step=0.01, value=example_lora_scale_ghibsky)
|
93 |
with gr.Column(scale=1):
|
94 |
result = gr.Image(label="Generated Image")
|
95 |
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)]")
|
96 |
|
97 |
# Automatically load example data and image when the interface is launched
|
98 |
-
app.load(load_example, inputs=[], outputs=[prompt, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale,
|
99 |
|
100 |
generate_button.click(
|
101 |
run_lora,
|
102 |
-
inputs=[prompt, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale
|
103 |
outputs=[result, seed]
|
104 |
)
|
105 |
|
|
|
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(duration=80)
|
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...")
|
|
|
49 |
width=width,
|
50 |
height=height,
|
51 |
generator=generator,
|
52 |
+
joint_attention_kwargs={"scale": lora_scale},
|
53 |
).images[0]
|
54 |
|
55 |
# Final update (100%)
|
|
|
66 |
example_height = 896
|
67 |
example_seed = 3981632454
|
68 |
example_lora_scale = 0.8
|
|
|
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 |
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,
|
97 |
+
inputs=[prompt, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale],
|
98 |
outputs=[result, seed]
|
99 |
)
|
100 |
|