Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
5f9671b
1
Parent(s):
73ac5f9
Robustness change
Browse files
app.py
CHANGED
@@ -142,12 +142,12 @@ def parse_lset_prompt(lset_prompt):
|
|
142 |
def handle_lora_selection_change(preset_name: str, current_prompt: str):
|
143 |
"""
|
144 |
Appends the selected LoRA's trigger words to the current prompt text
|
145 |
-
and controls the visibility of the weight slider.
|
|
|
146 |
"""
|
147 |
-
# If "None" is selected,
|
148 |
if not preset_name or preset_name == "None":
|
149 |
gr.Info("LoRA cleared.")
|
150 |
-
# Return the prompt unchanged, and hide the slider.
|
151 |
return gr.update(value=current_prompt), gr.update(visible=False, interactive=False)
|
152 |
|
153 |
try:
|
@@ -167,24 +167,23 @@ def handle_lora_selection_change(preset_name: str, current_prompt: str):
|
|
167 |
except json.JSONDecodeError:
|
168 |
lset_prompt_raw = lset_content
|
169 |
|
|
|
170 |
if lset_prompt_raw:
|
171 |
-
# Append the new trigger words to the current prompt.
|
172 |
trigger_words = parse_lset_prompt(lset_prompt_raw)
|
173 |
separator = ", " if current_prompt and not current_prompt.endswith((",", " ")) else ""
|
174 |
new_prompt = f"{current_prompt}{separator}{trigger_words}".strip()
|
175 |
gr.Info(f"✅ Appended triggers from '{preset_name}'. You can now edit them.")
|
176 |
-
# Return the updated prompt and show the slider.
|
177 |
return gr.update(value=new_prompt), gr.update(visible=True, interactive=True)
|
178 |
else:
|
179 |
-
# If the .lset file has no prompt,
|
180 |
gr.Info(f"ℹ️ No prompt found in '{preset_name}.lset'. Prompt unchanged.")
|
181 |
-
return gr.update(value=current_prompt), gr.update(visible=
|
182 |
|
183 |
except Exception as e:
|
184 |
print(f"Info: Could not process .lset for '{preset_name}'. Reason: {e}")
|
185 |
gr.Warning(f"⚠️ Could not load triggers for '{preset_name}'.")
|
186 |
-
# On error,
|
187 |
-
return gr.update(value=current_prompt), gr.update(visible=
|
188 |
|
189 |
|
190 |
def _manage_lora_state(pipe, selected_lora: str, lora_weight: float) -> bool:
|
@@ -503,3 +502,4 @@ if __name__ == "__main__":
|
|
503 |
app_ui = build_ui(t2v_pipe, enhancer_pipe, available_loras)
|
504 |
app_ui.queue(max_size=10).launch()
|
505 |
|
|
|
|
142 |
def handle_lora_selection_change(preset_name: str, current_prompt: str):
|
143 |
"""
|
144 |
Appends the selected LoRA's trigger words to the current prompt text
|
145 |
+
and controls the visibility of the weight slider. Ensures slider is only
|
146 |
+
visible on success.
|
147 |
"""
|
148 |
+
# If "None" is selected, hide the slider and return the prompt unchanged.
|
149 |
if not preset_name or preset_name == "None":
|
150 |
gr.Info("LoRA cleared.")
|
|
|
151 |
return gr.update(value=current_prompt), gr.update(visible=False, interactive=False)
|
152 |
|
153 |
try:
|
|
|
167 |
except json.JSONDecodeError:
|
168 |
lset_prompt_raw = lset_content
|
169 |
|
170 |
+
# Only if we successfully get trigger words, we update the prompt and show the slider.
|
171 |
if lset_prompt_raw:
|
|
|
172 |
trigger_words = parse_lset_prompt(lset_prompt_raw)
|
173 |
separator = ", " if current_prompt and not current_prompt.endswith((",", " ")) else ""
|
174 |
new_prompt = f"{current_prompt}{separator}{trigger_words}".strip()
|
175 |
gr.Info(f"✅ Appended triggers from '{preset_name}'. You can now edit them.")
|
|
|
176 |
return gr.update(value=new_prompt), gr.update(visible=True, interactive=True)
|
177 |
else:
|
178 |
+
# If the .lset file has no prompt, don't change the prompt and ensure the slider is hidden.
|
179 |
gr.Info(f"ℹ️ No prompt found in '{preset_name}.lset'. Prompt unchanged.")
|
180 |
+
return gr.update(value=current_prompt), gr.update(visible=False, interactive=False)
|
181 |
|
182 |
except Exception as e:
|
183 |
print(f"Info: Could not process .lset for '{preset_name}'. Reason: {e}")
|
184 |
gr.Warning(f"⚠️ Could not load triggers for '{preset_name}'.")
|
185 |
+
# On any error, don't change the prompt and ensure the slider is hidden.
|
186 |
+
return gr.update(value=current_prompt), gr.update(visible=False, interactive=False)
|
187 |
|
188 |
|
189 |
def _manage_lora_state(pipe, selected_lora: str, lora_weight: float) -> bool:
|
|
|
502 |
app_ui = build_ui(t2v_pipe, enhancer_pipe, available_loras)
|
503 |
app_ui.queue(max_size=10).launch()
|
504 |
|
505 |
+
|