Update app.py
Browse files
app.py
CHANGED
|
@@ -449,40 +449,56 @@ def check_custom_model(link):
|
|
| 449 |
return get_huggingface_safetensors(link)
|
| 450 |
|
| 451 |
def add_custom_lora(custom_lora):
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
existing_item_index = next((index for (index, item) in enumerate(loras) if item['repo'] == repo), None)
|
| 470 |
-
if
|
| 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 483 |
except Exception as e:
|
| 484 |
-
gr.Warning(
|
| 485 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 486 |
else:
|
| 487 |
return gr.update(visible=False), gr.update(visible=False), gr.update(), "", None, ""
|
| 488 |
|
|
|
|
| 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 (
|
| 483 |
+
gr.update(visible=True, value=card),
|
| 484 |
+
gr.update(visible=True),
|
| 485 |
+
gr.Gallery(selected_index=None),
|
| 486 |
+
f"Custom: {path}",
|
| 487 |
+
existing_item_index,
|
| 488 |
+
trigger_word,
|
| 489 |
+
)
|
| 490 |
except Exception as e:
|
| 491 |
+
gr.Warning(
|
| 492 |
+
f"Modelo Inválido: ou o link está errado ou não é um FLUX"
|
| 493 |
+
)
|
| 494 |
+
return (
|
| 495 |
+
gr.update(visible=True, value=f"Modelo Inválido: ou o link está errado ou não é um FLUX"),
|
| 496 |
+
gr.update(visible=False),
|
| 497 |
+
gr.update(),
|
| 498 |
+
"",
|
| 499 |
+
None,
|
| 500 |
+
"",
|
| 501 |
+
)
|
| 502 |
else:
|
| 503 |
return gr.update(visible=False), gr.update(visible=False), gr.update(), "", None, ""
|
| 504 |
|