Update app.py
Browse files
app.py
CHANGED
@@ -440,60 +440,56 @@ def get_huggingface_safetensors(link):
|
|
440 |
raise Exception(f"You didn't include a link neither a valid Hugging Face repository with a *.safetensors LoRA")
|
441 |
return split_link[1], link, safetensors_name, trigger_word, image_url
|
442 |
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
# def remove_custom_lora():
|
490 |
-
# return gr.update(visible=False), gr.update(visible=False), gr.update(), "", None, ""
|
491 |
-
|
492 |
-
run_lora.zerogpu = True
|
493 |
-
|
494 |
-
#import gradio as gr
|
495 |
|
|
|
|
|
496 |
|
|
|
497 |
|
498 |
|
499 |
collos = gr.themes.Soft(
|
@@ -550,11 +546,11 @@ with gr.Blocks(theme=collos, delete_cache=(60, 60)) as app:
|
|
550 |
columns=3,
|
551 |
show_share_button=False
|
552 |
)
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
with gr.Group():
|
559 |
with gr.Group():
|
560 |
gr.Text(value="Dica: Sempre digite a Palavra-chave referente ao modelo que são: José Alves, Júlio, Pedro e Clóvis, com os devidos acentos.", elem_id="padded_text")
|
@@ -587,15 +583,15 @@ with gr.Blocks(theme=collos, delete_cache=(60, 60)) as app:
|
|
587 |
inputs=[width, height],
|
588 |
outputs=[prompt, selected_info, selected_index, width, height]
|
589 |
)
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
gr.on(
|
600 |
triggers=[generate_button.click, prompt.submit],
|
601 |
fn=run_lora,
|
|
|
440 |
raise Exception(f"You didn't include a link neither a valid Hugging Face repository with a *.safetensors LoRA")
|
441 |
return split_link[1], link, safetensors_name, trigger_word, image_url
|
442 |
|
443 |
+
def check_custom_model(link):
|
444 |
+
if(link.startswith("https://")):
|
445 |
+
if(link.startswith("https://huggingface.co") or link.startswith("https://www.huggingface.co")):
|
446 |
+
link_split = link.split("huggingface.co/")
|
447 |
+
return get_huggingface_safetensors(link_split[1])
|
448 |
+
else:
|
449 |
+
return get_huggingface_safetensors(link)
|
450 |
+
|
451 |
+
def add_custom_lora(custom_lora):
|
452 |
+
global loras
|
453 |
+
if(custom_lora):
|
454 |
+
try:
|
455 |
+
title, repo, path, trigger_word, image = check_custom_model(custom_lora)
|
456 |
+
print(f"Modelo Externo: {repo}")
|
457 |
+
card = f'''
|
458 |
+
<div class="custom_lora_card">
|
459 |
+
<span>Loaded custom LoRA:</span>
|
460 |
+
<div class="card_internal">
|
461 |
+
<img src="{image}" />
|
462 |
+
<div>
|
463 |
+
<h3>{title}</h3>
|
464 |
+
<small>{"Usando: <code><b>"+trigger_word+"</code></b> como palavra-chave" if trigger_word else "Não encontramos a palavra-chave, se tiver, coloque-a no prompt."}<br></small>
|
465 |
+
</div>
|
466 |
+
</div>
|
467 |
+
</div>
|
468 |
+
'''
|
469 |
+
existing_item_index = next((index for (index, item) in enumerate(loras) if item['repo'] == repo), None)
|
470 |
+
if(not existing_item_index):
|
471 |
+
new_item = {
|
472 |
+
"image": image,
|
473 |
+
"title": title,
|
474 |
+
"repo": repo,
|
475 |
+
"weights": path,
|
476 |
+
"trigger_word": trigger_word
|
477 |
+
}
|
478 |
+
print(new_item)
|
479 |
+
existing_item_index = len(loras)
|
480 |
+
loras.append(new_item)
|
481 |
+
|
482 |
+
return gr.update(visible=True, value=card), gr.update(visible=True), gr.Gallery(selected_index=None), f"Custom: {path}", existing_item_index, trigger_word
|
483 |
+
except Exception as e:
|
484 |
+
gr.Warning(f"Modelo Inválido: ou o link está errado ou não é um FLUX")
|
485 |
+
return gr.update(visible=True, value=f"Modelo Inválido: ou o link está errado ou não é um FLUX"), gr.update(visible=False), gr.update(), "", None, ""
|
486 |
+
else:
|
487 |
+
return gr.update(visible=False), gr.update(visible=False), gr.update(), "", None, ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
488 |
|
489 |
+
def remove_custom_lora():
|
490 |
+
return gr.update(visible=False), gr.update(visible=False), gr.update(), "", None, ""
|
491 |
|
492 |
+
run_lora.zerogpu = True
|
493 |
|
494 |
|
495 |
collos = gr.themes.Soft(
|
|
|
546 |
columns=3,
|
547 |
show_share_button=False
|
548 |
)
|
549 |
+
with gr.Group():
|
550 |
+
custom_lora = gr.Textbox(label="Selecione um Modelo Externo", placeholder="black-forest-labs/FLUX.1-dev")
|
551 |
+
gr.Markdown("[Cheque a lista de modelos do Huggingface](https://huggingface.co/models?other=base_model:adapter:black-forest-labs/FLUX.1-dev)", elem_id="lora_list")
|
552 |
+
custom_lora_info = gr.HTML(visible=False)
|
553 |
+
custom_lora_button = gr.Button("Remova modelo Externo", visible=False)
|
554 |
with gr.Group():
|
555 |
with gr.Group():
|
556 |
gr.Text(value="Dica: Sempre digite a Palavra-chave referente ao modelo que são: José Alves, Júlio, Pedro e Clóvis, com os devidos acentos.", elem_id="padded_text")
|
|
|
583 |
inputs=[width, height],
|
584 |
outputs=[prompt, selected_info, selected_index, width, height]
|
585 |
)
|
586 |
+
custom_lora.input(
|
587 |
+
add_custom_lora,
|
588 |
+
inputs=[custom_lora],
|
589 |
+
outputs=[custom_lora_info, custom_lora_button, gallery, selected_info, selected_index, prompt]
|
590 |
+
)
|
591 |
+
custom_lora_button.click(
|
592 |
+
remove_custom_lora,
|
593 |
+
outputs=[custom_lora_info, custom_lora_button, gallery, selected_info, selected_index, custom_lora]
|
594 |
+
)
|
595 |
gr.on(
|
596 |
triggers=[generate_button.click, prompt.submit],
|
597 |
fn=run_lora,
|