Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -108,10 +108,7 @@ def run_lora(prompt, cfg_scale, steps, selected_index, randomize_seed, seed, wid
|
|
| 108 |
pipe.load_lora_weights(lora_path, weight_name=selected_lora["weights"])
|
| 109 |
else:
|
| 110 |
pipe.load_lora_weights(lora_path)
|
| 111 |
-
|
| 112 |
-
#with calculateDuration(f"Fusing LoRA weights for {selected_lora['title']}"):
|
| 113 |
-
#pipe.fuse_lora(lora_scale)
|
| 114 |
-
|
| 115 |
# Set random seed for reproducibility
|
| 116 |
with calculateDuration("Randomizing seed"):
|
| 117 |
if randomize_seed:
|
|
@@ -121,15 +118,16 @@ def run_lora(prompt, cfg_scale, steps, selected_index, randomize_seed, seed, wid
|
|
| 121 |
|
| 122 |
# Consume the generator to get the final image
|
| 123 |
final_image = None
|
|
|
|
| 124 |
for image in image_generator:
|
|
|
|
| 125 |
final_image = image
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
|
|
|
| 130 |
pipe.unload_lora_weights()
|
| 131 |
-
|
| 132 |
-
return final_image, seed # Return the final image and seed
|
| 133 |
|
| 134 |
def get_huggingface_safetensors(link):
|
| 135 |
split_link = link.split("/")
|
|
@@ -218,6 +216,10 @@ css = '''
|
|
| 218 |
.card_internal{display: flex;height: 100px;margin-top: .5em}
|
| 219 |
.card_internal img{margin-right: 1em}
|
| 220 |
.styler{--form-gap-width: 0px !important}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
'''
|
| 222 |
with gr.Blocks(theme=gr.themes.Soft(), css=css) as app:
|
| 223 |
title = gr.HTML(
|
|
@@ -246,6 +248,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as app:
|
|
| 246 |
custom_lora_info = gr.HTML(visible=False)
|
| 247 |
custom_lora_button = gr.Button("Remove custom LoRA", visible=False)
|
| 248 |
with gr.Column(scale=4):
|
|
|
|
| 249 |
result = gr.Image(label="Generated Image")
|
| 250 |
|
| 251 |
with gr.Row():
|
|
@@ -282,8 +285,8 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as app:
|
|
| 282 |
triggers=[generate_button.click, prompt.submit],
|
| 283 |
fn=run_lora,
|
| 284 |
inputs=[prompt, cfg_scale, steps, selected_index, randomize_seed, seed, width, height, lora_scale],
|
| 285 |
-
outputs=[result, seed]
|
| 286 |
)
|
| 287 |
|
| 288 |
app.queue()
|
| 289 |
-
app.launch(
|
|
|
|
| 108 |
pipe.load_lora_weights(lora_path, weight_name=selected_lora["weights"])
|
| 109 |
else:
|
| 110 |
pipe.load_lora_weights(lora_path)
|
| 111 |
+
|
|
|
|
|
|
|
|
|
|
| 112 |
# Set random seed for reproducibility
|
| 113 |
with calculateDuration("Randomizing seed"):
|
| 114 |
if randomize_seed:
|
|
|
|
| 118 |
|
| 119 |
# Consume the generator to get the final image
|
| 120 |
final_image = None
|
| 121 |
+
step_counter = 0
|
| 122 |
for image in image_generator:
|
| 123 |
+
step_counter+=1
|
| 124 |
final_image = image
|
| 125 |
+
progress_bar = f'<div class="progress-container"><div class="progress-bar" style="--current: {step_counter}; --total: {steps};"></div></div>'
|
| 126 |
+
yield image, seed, gr.update(value=progress_bar, visible=True)
|
| 127 |
+
|
| 128 |
+
yield final_image, seed, gr.update(value=progress_bar, visible=False)
|
| 129 |
+
with calculateDuration("Unloading LoRA"):
|
| 130 |
pipe.unload_lora_weights()
|
|
|
|
|
|
|
| 131 |
|
| 132 |
def get_huggingface_safetensors(link):
|
| 133 |
split_link = link.split("/")
|
|
|
|
| 216 |
.card_internal{display: flex;height: 100px;margin-top: .5em}
|
| 217 |
.card_internal img{margin-right: 1em}
|
| 218 |
.styler{--form-gap-width: 0px !important}
|
| 219 |
+
#progress{height:30px}
|
| 220 |
+
#progress .generating{display:none}
|
| 221 |
+
.progress-container {width: 100%;height: 30px;background-color: #f0f0f0;border-radius: 15px;overflow: hidden;margin-bottom: 20px}
|
| 222 |
+
.progress-bar {height: 100%;background-color: #4f46e5;width: calc(var(--current) / var(--total) * 100%);transition: width 0.5s ease-in-out}
|
| 223 |
'''
|
| 224 |
with gr.Blocks(theme=gr.themes.Soft(), css=css) as app:
|
| 225 |
title = gr.HTML(
|
|
|
|
| 248 |
custom_lora_info = gr.HTML(visible=False)
|
| 249 |
custom_lora_button = gr.Button("Remove custom LoRA", visible=False)
|
| 250 |
with gr.Column(scale=4):
|
| 251 |
+
progress_bar = gr.Markdown(elem_id="progress",visible=False)
|
| 252 |
result = gr.Image(label="Generated Image")
|
| 253 |
|
| 254 |
with gr.Row():
|
|
|
|
| 285 |
triggers=[generate_button.click, prompt.submit],
|
| 286 |
fn=run_lora,
|
| 287 |
inputs=[prompt, cfg_scale, steps, selected_index, randomize_seed, seed, width, height, lora_scale],
|
| 288 |
+
outputs=[result, seed, progress_bar]
|
| 289 |
)
|
| 290 |
|
| 291 |
app.queue()
|
| 292 |
+
app.launch()
|