Update app.py
Browse files
app.py
CHANGED
@@ -121,41 +121,15 @@ def update_selection(evt: gr.SelectData, selected_indices, loras_state, width, h
|
|
121 |
gr.Warning("You can select up to 4 LoRAs, remove one to select a new one.")
|
122 |
return gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), selected_indices, gr.update(), gr.update(), gr.update(), gr.update(), width, height, gr.update(), gr.update(), gr.update()
|
123 |
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
lora_image_2 = None
|
134 |
-
lora_image_3 = None
|
135 |
-
lora_image_4 = None
|
136 |
-
if len(selected_indices) >= 1:
|
137 |
-
lora1 = loras_state[selected_indices[0]]
|
138 |
-
trigger_word = lora1.get('trigger_word', '') # Get actual trigger word from LoRA 1
|
139 |
-
selected_info_1 = f"### LoRA 1 Selected: [{lora1['title']}](https://huggingface.co/{lora1['repo']}) ✨ {trigger_word}"
|
140 |
-
lora_image_1 = lora1['image']
|
141 |
-
|
142 |
-
if len(selected_indices) >= 2:
|
143 |
-
lora2 = loras_state[selected_indices[1]]
|
144 |
-
trigger_word = lora2.get('trigger_word', '') # Get actual trigger word from LoRA 2
|
145 |
-
selected_info_2 = f"### LoRA 2 Selected: [{lora2['title']}](https://huggingface.co/{lora2['repo']}) ✨ {trigger_word}"
|
146 |
-
lora_image_2 = lora2['image']
|
147 |
-
|
148 |
-
if len(selected_indices) >= 3:
|
149 |
-
lora3 = loras_state[selected_indices[2]]
|
150 |
-
trigger_word = lora3.get('trigger_word', '') # Get actual trigger word from LoRA 3
|
151 |
-
selected_info_3 = f"### LoRA 3 Selected: [{lora3['title']}](https://huggingface.co/{lora3['repo']}) ✨ {trigger_word}"
|
152 |
-
lora_image_3 = lora3['image']
|
153 |
-
|
154 |
-
if len(selected_indices) >= 4:
|
155 |
-
lora4 = loras_state[selected_indices[3]]
|
156 |
-
trigger_word = lora4.get('trigger_word', '') # Get actual trigger word from LoRA 4
|
157 |
-
selected_info_4 = f"### LoRA 4 Selected: [{lora4['title']}](https://huggingface.co/{lora4['repo']}) ✨ {trigger_word}"
|
158 |
-
lora_image_4 = lora4['image']
|
159 |
|
160 |
if selected_indices:
|
161 |
last_selected_lora = loras_state[selected_indices[-1]]
|
@@ -164,11 +138,11 @@ def update_selection(evt: gr.SelectData, selected_indices, loras_state, width, h
|
|
164 |
new_placeholder = "Type a prompt after selecting a LoRA"
|
165 |
|
166 |
return (gr.update(placeholder=new_placeholder),
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
)
|
173 |
|
174 |
def randomize_loras(selected_indices, loras_state):
|
|
|
121 |
gr.Warning("You can select up to 4 LoRAs, remove one to select a new one.")
|
122 |
return gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), selected_indices, gr.update(), gr.update(), gr.update(), gr.update(), width, height, gr.update(), gr.update(), gr.update()
|
123 |
|
124 |
+
selected_info = ["Select a LoRA {}".format(i) for i in range(1, 5)]
|
125 |
+
lora_images = [None] * 4
|
126 |
+
lora_scales = [0.5] * 4
|
127 |
+
|
128 |
+
for i in range(len(selected_indices)):
|
129 |
+
lora = loras_state[selected_indices[i]]
|
130 |
+
trigger_word = lora.get('trigger_word', '')
|
131 |
+
selected_info[i] = f"### LoRA {i + 1} Selected: [{lora['title']}](https://huggingface.co/{lora['repo']}) ✨ {trigger_word}"
|
132 |
+
lora_images[i] = lora['image']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
|
134 |
if selected_indices:
|
135 |
last_selected_lora = loras_state[selected_indices[-1]]
|
|
|
138 |
new_placeholder = "Type a prompt after selecting a LoRA"
|
139 |
|
140 |
return (gr.update(placeholder=new_placeholder),
|
141 |
+
*selected_info, selected_indices,
|
142 |
+
*lora_scales,
|
143 |
+
width, height,
|
144 |
+
*lora_images,
|
145 |
+
gr.update()
|
146 |
)
|
147 |
|
148 |
def randomize_loras(selected_indices, loras_state):
|