Spaces:
Sleeping
Sleeping
Commit
·
adddbc4
1
Parent(s):
885080e
Updates
Browse files
app.py
CHANGED
@@ -13,6 +13,8 @@ import copy
|
|
13 |
import random
|
14 |
import time
|
15 |
|
|
|
|
|
16 |
# Load LoRAs from JSON file
|
17 |
with open('loras.json', 'r') as f:
|
18 |
loras = json.load(f)
|
@@ -57,6 +59,8 @@ class calculateDuration:
|
|
57 |
print(f"Elapsed time: {self.elapsed_time:.6f} seconds")
|
58 |
|
59 |
def update_selection(evt: gr.SelectData, width, height):
|
|
|
|
|
60 |
selected_lora = loras[evt.index]
|
61 |
new_placeholder = f"{selected_lora['trigger_word']} {prompt.value}"
|
62 |
lora_repo = selected_lora["repo"]
|
@@ -74,7 +78,6 @@ def update_selection(evt: gr.SelectData, width, height):
|
|
74 |
return (
|
75 |
gr.update(value=new_placeholder),
|
76 |
updated_text,
|
77 |
-
evt.index,
|
78 |
width,
|
79 |
height,
|
80 |
gr.update(interactive=True) # Enable the Generate button
|
@@ -99,11 +102,12 @@ def generate_image(prompt_mash, steps, seed, cfg_scale, width, height, lora_scal
|
|
99 |
):
|
100 |
yield img
|
101 |
|
102 |
-
def run_lora(prompt, cfg_scale, steps,
|
103 |
-
|
|
|
104 |
raise gr.Error("You must select a LoRA before proceeding.")
|
105 |
|
106 |
-
selected_lora = loras[
|
107 |
lora_path = selected_lora["repo"]
|
108 |
trigger_word = selected_lora["trigger_word"]
|
109 |
|
@@ -196,9 +200,9 @@ with gr.Blocks() as demo:
|
|
196 |
progress_bar = gr.Markdown(visible=False)
|
197 |
|
198 |
# Event handlers
|
199 |
-
gallery.select(update_selection, [width, height], [prompt, selected_lora,
|
200 |
randomize_seed.change(lambda x: gr.update(visible=not x), randomize_seed, seed_input)
|
201 |
-
generate_event = generate.click(run_lora, inputs=[prompt, cfg_scale, steps,
|
202 |
cancel.click(lambda: None, None, None, cancels=[generate_event])
|
203 |
|
204 |
demo.queue().launch()
|
|
|
13 |
import random
|
14 |
import time
|
15 |
|
16 |
+
selected_lora_index = None
|
17 |
+
|
18 |
# Load LoRAs from JSON file
|
19 |
with open('loras.json', 'r') as f:
|
20 |
loras = json.load(f)
|
|
|
59 |
print(f"Elapsed time: {self.elapsed_time:.6f} seconds")
|
60 |
|
61 |
def update_selection(evt: gr.SelectData, width, height):
|
62 |
+
global selected_lora_index
|
63 |
+
selected_lora_index = evt.index
|
64 |
selected_lora = loras[evt.index]
|
65 |
new_placeholder = f"{selected_lora['trigger_word']} {prompt.value}"
|
66 |
lora_repo = selected_lora["repo"]
|
|
|
78 |
return (
|
79 |
gr.update(value=new_placeholder),
|
80 |
updated_text,
|
|
|
81 |
width,
|
82 |
height,
|
83 |
gr.update(interactive=True) # Enable the Generate button
|
|
|
102 |
):
|
103 |
yield img
|
104 |
|
105 |
+
def run_lora(prompt, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale, progress=gr.Progress(track_tqdm=True)):
|
106 |
+
global selected_lora_index
|
107 |
+
if selected_lora_index is None:
|
108 |
raise gr.Error("You must select a LoRA before proceeding.")
|
109 |
|
110 |
+
selected_lora = loras[selected_lora_index]
|
111 |
lora_path = selected_lora["repo"]
|
112 |
trigger_word = selected_lora["trigger_word"]
|
113 |
|
|
|
200 |
progress_bar = gr.Markdown(visible=False)
|
201 |
|
202 |
# Event handlers
|
203 |
+
gallery.select(update_selection, [width, height], [prompt, selected_lora, width, height, generate])
|
204 |
randomize_seed.change(lambda x: gr.update(visible=not x), randomize_seed, seed_input)
|
205 |
+
generate_event = generate.click(run_lora, inputs=[prompt, cfg_scale, steps, randomize_seed, seed_input, width, height, lora_scale], outputs=[result, seed_output, progress_bar])
|
206 |
cancel.click(lambda: None, None, None, cancels=[generate_event])
|
207 |
|
208 |
demo.queue().launch()
|