Spaces:
Sleeping
Sleeping
Commit
·
ce04d24
1
Parent(s):
3eb8dac
Update app.py
Browse files
app.py
CHANGED
@@ -36,13 +36,17 @@ for item, saved_name in zip(sdxl_loras, saved_names):
|
|
36 |
item["saved_name"] = saved_name
|
37 |
|
38 |
css = '''
|
39 |
-
#title{text-align:center}
|
40 |
-
#
|
41 |
-
|
42 |
-
.
|
43 |
#prompt input{width: calc(100% - 160px);border-top-right-radius: 0px;border-bottom-right-radius: 0px;}
|
44 |
-
#run_button{position:absolute;margin-top:
|
45 |
border-top-left-radius: 0px;}
|
|
|
|
|
|
|
|
|
46 |
'''
|
47 |
|
48 |
#@spaces.GPU
|
@@ -51,7 +55,7 @@ original_pipe = copy.deepcopy(pipe)
|
|
51 |
|
52 |
def merge_and_run(prompt, negative_prompt, shuffled_items, lora_1_scale=0.5, lora_2_scale=0.5, progress=gr.Progress(track_tqdm=True)):
|
53 |
pipe = copy.deepcopy(original_pipe)
|
54 |
-
pipe.to(
|
55 |
print("Loading LoRAs")
|
56 |
pipe.load_lora_weights(shuffled_items[0]['saved_name'])
|
57 |
pipe.fuse_lora(lora_1_scale)
|
@@ -69,7 +73,7 @@ def merge_and_run(prompt, negative_prompt, shuffled_items, lora_1_scale=0.5, lor
|
|
69 |
|
70 |
def get_description(item):
|
71 |
trigger_word = item["trigger_word"]
|
72 |
-
return f"
|
73 |
|
74 |
def shuffle_images():
|
75 |
compatible_items = [item for item in sdxl_loras if item['is_compatible']]
|
@@ -91,30 +95,39 @@ with gr.Blocks(css=css) as demo:
|
|
91 |
shuffled_items = gr.State()
|
92 |
title = gr.HTML(
|
93 |
'''<h1>LoRA Roulette 🎲</h1>
|
94 |
-
<h4>This 2 LoRAs are loaded to SDXL at random, find a fun way to combine them 🎨</h4>
|
95 |
''',
|
96 |
elem_id="title"
|
97 |
)
|
98 |
-
with gr.Row():
|
99 |
-
with gr.Column(min_width=10, scale=
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
|
111 |
-
output_image = gr.Image()
|
112 |
with gr.Accordion("Advanced settings", open=False):
|
113 |
negative_prompt = gr.Textbox(label="Negative prompt")
|
114 |
with gr.Row():
|
115 |
lora_1_scale = gr.Slider(label="LoRA 1 Scale", minimum=0, maximum=1, step=0.1, value=0.7)
|
116 |
lora_2_scale = gr.Slider(label="LoRa 2 Scale", minimum=0, maximum=1, step=0.1, value=0.7)
|
117 |
-
shuffle_button = gr.Button("Reshuffle LoRAs!")
|
118 |
|
119 |
demo.load(shuffle_images, inputs=[], outputs=[lora_1, lora_1_prompt, lora_2, lora_2_prompt, prompt, shuffled_items], queue=False, show_progress="hidden")
|
120 |
shuffle_button.click(shuffle_images, outputs=[lora_1, lora_1_prompt, lora_2, lora_2_prompt, prompt, shuffled_items], queue=False, show_progress="hidden")
|
@@ -123,4 +136,4 @@ with gr.Blocks(css=css) as demo:
|
|
123 |
prompt.submit(merge_and_run, inputs=[prompt, negative_prompt, shuffled_items, lora_1_scale, lora_2_scale], outputs=[output_image])
|
124 |
|
125 |
demo.queue()
|
126 |
-
demo.launch()
|
|
|
36 |
item["saved_name"] = saved_name
|
37 |
|
38 |
css = '''
|
39 |
+
#title{text-align:center;}
|
40 |
+
#title h1{font-size: 250%}
|
41 |
+
.plus_column{align-self: center}
|
42 |
+
.plus_button{font-size: 235% !important; text-align: center;margin-bottom: 19px}
|
43 |
#prompt input{width: calc(100% - 160px);border-top-right-radius: 0px;border-bottom-right-radius: 0px;}
|
44 |
+
#run_button{position:absolute;margin-top: 12px;right: 0;margin-right: 1.5em;border-bottom-left-radius: 0px;
|
45 |
border-top-left-radius: 0px;}
|
46 |
+
.random_column{align-self: center}
|
47 |
+
@media (max-width: 1024px) {
|
48 |
+
.roulette_group{flex-direction: column}
|
49 |
+
}
|
50 |
'''
|
51 |
|
52 |
#@spaces.GPU
|
|
|
55 |
|
56 |
def merge_and_run(prompt, negative_prompt, shuffled_items, lora_1_scale=0.5, lora_2_scale=0.5, progress=gr.Progress(track_tqdm=True)):
|
57 |
pipe = copy.deepcopy(original_pipe)
|
58 |
+
pipe.to("cuda")
|
59 |
print("Loading LoRAs")
|
60 |
pipe.load_lora_weights(shuffled_items[0]['saved_name'])
|
61 |
pipe.fuse_lora(lora_1_scale)
|
|
|
73 |
|
74 |
def get_description(item):
|
75 |
trigger_word = item["trigger_word"]
|
76 |
+
return f"Trigger: `{trigger_word}`" if trigger_word else "No trigger word, will be applied automatically", trigger_word
|
77 |
|
78 |
def shuffle_images():
|
79 |
compatible_items = [item for item in sdxl_loras if item['is_compatible']]
|
|
|
95 |
shuffled_items = gr.State()
|
96 |
title = gr.HTML(
|
97 |
'''<h1>LoRA Roulette 🎲</h1>
|
|
|
98 |
''',
|
99 |
elem_id="title"
|
100 |
)
|
101 |
+
with gr.Row(elem_classes="roulette_group"):
|
102 |
+
with gr.Column(min_width=10, scale=16, elem_classes="plus_column"):
|
103 |
+
gr.HTML("<p>This 2 random LoRAs are loaded to SDXL, find a fun way to combine them 🎨</p>")
|
104 |
+
with gr.Row():
|
105 |
+
with gr.Column(min_width=10, scale=8, elem_classes="random_column"):
|
106 |
+
lora_1 = gr.Image(interactive=False, height=263)
|
107 |
+
lora_1_prompt = gr.Markdown(visible=False)
|
108 |
+
with gr.Column(min_width=10, scale=1, elem_classes="plus_column"):
|
109 |
+
plus = gr.HTML("+", elem_classes="plus_button")
|
110 |
+
with gr.Column(min_width=10, scale=8, elem_classes="random_column"):
|
111 |
+
lora_2 = gr.Image(interactive=False, height=263)
|
112 |
+
lora_2_prompt = gr.Markdown(visible=False)
|
113 |
+
with gr.Column(min_width=10, scale=1, elem_classes="plus_column"):
|
114 |
+
equal = gr.HTML("=", elem_classes="plus_button")
|
115 |
+
shuffle_button = gr.Button("Reshuffle!", visible=False)
|
116 |
+
with gr.Column(min_width=10, scale=14):
|
117 |
+
with gr.Box():
|
118 |
+
with gr.Row():
|
119 |
+
prompt = gr.Textbox(label="Your prompt", show_label=False, interactive=True, elem_id="prompt")
|
120 |
+
run_btn = gr.Button("Run", elem_id="run_button")
|
121 |
+
output_image = gr.Image(label="Output", height=355)
|
122 |
+
|
123 |
+
|
124 |
+
|
125 |
|
|
|
126 |
with gr.Accordion("Advanced settings", open=False):
|
127 |
negative_prompt = gr.Textbox(label="Negative prompt")
|
128 |
with gr.Row():
|
129 |
lora_1_scale = gr.Slider(label="LoRA 1 Scale", minimum=0, maximum=1, step=0.1, value=0.7)
|
130 |
lora_2_scale = gr.Slider(label="LoRa 2 Scale", minimum=0, maximum=1, step=0.1, value=0.7)
|
|
|
131 |
|
132 |
demo.load(shuffle_images, inputs=[], outputs=[lora_1, lora_1_prompt, lora_2, lora_2_prompt, prompt, shuffled_items], queue=False, show_progress="hidden")
|
133 |
shuffle_button.click(shuffle_images, outputs=[lora_1, lora_1_prompt, lora_2, lora_2_prompt, prompt, shuffled_items], queue=False, show_progress="hidden")
|
|
|
136 |
prompt.submit(merge_and_run, inputs=[prompt, negative_prompt, shuffled_items, lora_1_scale, lora_2_scale], outputs=[output_image])
|
137 |
|
138 |
demo.queue()
|
139 |
+
demo.launch(share=True)
|