Spaces:
Sleeping
Sleeping
kaytoo2022
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -17,26 +17,23 @@ 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(
|
22 |
|
23 |
-
|
24 |
-
pipe.load_lora_weights(lora_repo_anime, adapter_name='ghibsky')
|
25 |
-
|
26 |
-
pipe.set_adapters(["kaytoo", "ghibli", "ghibsky"], adapter_weights=[0.7, 0.3, 0.3])
|
27 |
|
28 |
pipe.to("cuda")
|
29 |
|
30 |
MAX_SEED = 2**32-1
|
31 |
|
32 |
@spaces.GPU()
|
33 |
-
def run_lora(prompt, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale,
|
34 |
# Set random seed for reproducibility
|
35 |
if randomize_seed:
|
36 |
seed = random.randint(0, MAX_SEED)
|
37 |
generator = torch.Generator(device="cuda").manual_seed(seed)
|
38 |
|
39 |
-
pipe.set_adapters(["kaytoo", "
|
40 |
|
41 |
# Update progress bar (0% saat mulai)
|
42 |
progress(0, "Starting image generation...")
|
@@ -72,13 +69,12 @@ example_width = 1152
|
|
72 |
example_height = 896
|
73 |
example_seed = 3981632454
|
74 |
example_lora_scale = 0.8
|
75 |
-
example_lora_scale_ghibli = 0.3
|
76 |
example_lora_scale_ghibsky = 0.3
|
77 |
|
78 |
def load_example():
|
79 |
# Load example image from file
|
80 |
example_image = Image.open(example_image_path)
|
81 |
-
return example_prompt, example_cfg_scale, example_steps, True, example_seed, example_width, example_height, example_lora_scale,
|
82 |
|
83 |
with gr.Blocks() as app:
|
84 |
gr.Markdown("# Flux Lora Image Generator")
|
@@ -93,18 +89,17 @@ with gr.Blocks() as app:
|
|
93 |
randomize_seed = gr.Checkbox(True, label="Randomize seed")
|
94 |
seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=example_seed)
|
95 |
lora_scale = gr.Slider(label="LoRA Scale", minimum=0, maximum=1, step=0.01, value=example_lora_scale)
|
96 |
-
lora_scale_ghibli = gr.Slider(label="LoRA Scale (Ghibli)", minimum=0, maximum=1, step=0.01, value=example_lora_scale_ghibli)
|
97 |
lora_scale_ghibsky = gr.Slider(label="LoRA Scale (Ghibli sky)", minimum=0, maximum=1, step=0.01, value=example_lora_scale_ghibsky)
|
98 |
with gr.Column(scale=1):
|
99 |
result = gr.Image(label="Generated Image")
|
100 |
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)]")
|
101 |
|
102 |
# Automatically load example data and image when the interface is launched
|
103 |
-
app.load(load_example, inputs=[], outputs=[prompt, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale,
|
104 |
|
105 |
generate_button.click(
|
106 |
run_lora,
|
107 |
-
inputs=[prompt, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale,
|
108 |
outputs=[result, seed]
|
109 |
)
|
110 |
|
|
|
17 |
trigger_word = "" # Leave trigger_word blank if not used.
|
18 |
pipe.load_lora_weights(lora_repo, adapter_name='kaytoo')
|
19 |
|
20 |
+
lora_repo_ghibsky = "aleksa-codes/flux-ghibsky-illustration"
|
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()
|
30 |
+
def run_lora(prompt, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale, lora_scale_ghibsky, progress=gr.Progress(track_tqdm=True)):
|
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", "ghibsky"], adapter_weights=[lora_scale, lora_scale_ghibsky])
|
37 |
|
38 |
# Update progress bar (0% saat mulai)
|
39 |
progress(0, "Starting image generation...")
|
|
|
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, example_lora_scale_ghibsky, example_image
|
78 |
|
79 |
with gr.Blocks() as app:
|
80 |
gr.Markdown("# Flux Lora Image Generator")
|
|
|
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, lora_scale_ghibsky, result])
|
99 |
|
100 |
generate_button.click(
|
101 |
run_lora,
|
102 |
+
inputs=[prompt, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale, lora_scale_ghibsky],
|
103 |
outputs=[result, seed]
|
104 |
)
|
105 |
|