Update app.py
Browse files
app.py
CHANGED
@@ -390,147 +390,149 @@ def update_inputs(is_open, index, state: list):
|
|
390 |
print(indexs)
|
391 |
return indexs, is_open
|
392 |
|
393 |
-
|
394 |
-
|
395 |
-
indexs_state = gr.State([0, 1]) # 添加状态来存储 indexs
|
396 |
|
397 |
-
|
398 |
-
with gr.Row():
|
399 |
-
with gr.Column():
|
400 |
-
prompt = gr.Textbox(label="Prompt", value="")
|
401 |
-
with gr.Accordion("Open for More!", open=False):
|
402 |
-
|
403 |
-
with gr.Row():
|
404 |
-
target_height = gr.Slider(512, 1024, step=128, value=768, label="Generated Height", info="")
|
405 |
-
target_width = gr.Slider(512, 1024, step=128, value=768, label="Generated Width", info="")
|
406 |
-
cond_size = gr.Slider(256, 384, step=128, value=256, label="Condition Size", info="")
|
407 |
-
with gr.Row():
|
408 |
-
weight_id = gr.Slider(0.1, 5, step=0.1, value=3, label="weight_id")
|
409 |
-
weight_ip = gr.Slider(0.1, 5, step=0.1, value=5, label="weight_ip")
|
410 |
-
with gr.Row():
|
411 |
-
ip_scale_str = gr.Slider(0.5, 1.5, step=0.01, value=0.85, label="latent_lora_scale")
|
412 |
-
vae_lora_scale = gr.Slider(0.5, 1.5, step=0.01, value=1.3, label="vae_lora_scale")
|
413 |
-
with gr.Row():
|
414 |
-
vae_skip_iter_s1 = gr.Slider(0, 1, step=0.01, value=0.05, label="vae_skip_iter_before")
|
415 |
-
vae_skip_iter_s2 = gr.Slider(0, 1, step=0.01, value=0.8, label="vae_skip_iter_after")
|
416 |
-
|
417 |
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
)
|
424 |
-
weight_id.change(
|
425 |
-
lambda s1, s2: f"0-1:1/{s1}/{s2}",
|
426 |
-
inputs=[weight_id, weight_ip],
|
427 |
-
outputs=weight_id_ip_str
|
428 |
-
)
|
429 |
-
weight_ip.change(
|
430 |
-
lambda s1, s2: f"0-1:1/{s1}/{s2}",
|
431 |
-
inputs=[weight_id, weight_ip],
|
432 |
-
outputs=weight_id_ip_str
|
433 |
-
)
|
434 |
-
vae_skip_iter = gr.Textbox(
|
435 |
-
value="0-0.05:1,0.8-1:1",
|
436 |
-
label="vae_skip_iter",
|
437 |
-
interactive=False, visible=False
|
438 |
-
)
|
439 |
-
vae_skip_iter_s1.change(
|
440 |
-
lambda s1, s2: f"0-{s1}:1,{s2}-1:1",
|
441 |
-
inputs=[vae_skip_iter_s1, vae_skip_iter_s2],
|
442 |
-
outputs=vae_skip_iter
|
443 |
-
)
|
444 |
-
vae_skip_iter_s2.change(
|
445 |
-
lambda s1, s2: f"0-{s1}:1,{s2}-1:1",
|
446 |
-
inputs=[vae_skip_iter_s1, vae_skip_iter_s2],
|
447 |
-
outputs=vae_skip_iter
|
448 |
-
)
|
449 |
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
value="
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
label="
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
outputs=vae_lora_scale_str
|
471 |
)
|
472 |
-
|
473 |
-
lambda
|
474 |
-
inputs=
|
475 |
-
outputs=
|
476 |
)
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
488 |
with gr.Row():
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
497 |
with gr.Row():
|
498 |
-
|
499 |
-
|
500 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
501 |
|
502 |
-
|
503 |
-
|
504 |
-
seed = gr.Number(value=42, label="Seed", info="")
|
505 |
-
gen_btn = gr.Button("生成图像")
|
506 |
-
|
507 |
-
gr.Markdown("### Examples")
|
508 |
-
gen_btn.click(
|
509 |
-
generate_image,
|
510 |
-
inputs=[
|
511 |
-
prompt, cond_size, target_height, target_width, seed,
|
512 |
-
vae_skip_iter, weight_id_ip_str,
|
513 |
-
double_attention, single_attention,
|
514 |
-
db_latent_lora_scale_str, sb_latent_lora_scale_str, vae_lora_scale_str,
|
515 |
-
indexs_state, # 传递 indexs 状态
|
516 |
-
# *images,
|
517 |
-
# *captions,
|
518 |
-
# *idip_checkboxes,
|
519 |
-
],
|
520 |
-
outputs=output
|
521 |
-
)
|
522 |
-
|
523 |
-
# # 修改清空函数的输出参数
|
524 |
-
# clear_btn.click(clear_images, outputs=images)
|
525 |
-
|
526 |
-
face_btn_1.click(crop_face_img, inputs=[image_1], outputs=[image_1])
|
527 |
-
det_btn_1.click(det_seg_img, inputs=[image_1, caption_1], outputs=[image_1])
|
528 |
-
vlm_btn_1.click(vlm_img_caption, inputs=[image_1], outputs=[caption_1])
|
529 |
-
|
530 |
-
face_btn_2.click(crop_face_img, inputs=[image_2], outputs=[image_2])
|
531 |
-
det_btn_2.click(det_seg_img, inputs=[image_2, caption_2], outputs=[image_2])
|
532 |
-
vlm_btn_2.click(vlm_img_caption, inputs=[image_2], outputs=[caption_2])
|
533 |
-
|
534 |
-
|
535 |
-
demo.queue()
|
536 |
-
demo.launch(share=True)
|
|
|
390 |
print(indexs)
|
391 |
return indexs, is_open
|
392 |
|
393 |
+
if __name__ == "__main__":
|
394 |
+
with gr.Blocks() as demo:
|
|
|
395 |
|
396 |
+
indexs_state = gr.State([0, 1]) # 添加状态来存储 indexs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
397 |
|
398 |
+
gr.Markdown("### XVerse Demo")
|
399 |
+
with gr.Row():
|
400 |
+
with gr.Column():
|
401 |
+
prompt = gr.Textbox(label="Prompt", value="")
|
402 |
+
with gr.Accordion("Open for More!", open=False):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
403 |
|
404 |
+
with gr.Row():
|
405 |
+
target_height = gr.Slider(512, 1024, step=128, value=768, label="Generated Height", info="")
|
406 |
+
target_width = gr.Slider(512, 1024, step=128, value=768, label="Generated Width", info="")
|
407 |
+
cond_size = gr.Slider(256, 384, step=128, value=256, label="Condition Size", info="")
|
408 |
+
with gr.Row():
|
409 |
+
weight_id = gr.Slider(0.1, 5, step=0.1, value=3, label="weight_id")
|
410 |
+
weight_ip = gr.Slider(0.1, 5, step=0.1, value=5, label="weight_ip")
|
411 |
+
with gr.Row():
|
412 |
+
ip_scale_str = gr.Slider(0.5, 1.5, step=0.01, value=0.85, label="latent_lora_scale")
|
413 |
+
vae_lora_scale = gr.Slider(0.5, 1.5, step=0.01, value=1.3, label="vae_lora_scale")
|
414 |
+
with gr.Row():
|
415 |
+
vae_skip_iter_s1 = gr.Slider(0, 1, step=0.01, value=0.05, label="vae_skip_iter_before")
|
416 |
+
vae_skip_iter_s2 = gr.Slider(0, 1, step=0.01, value=0.8, label="vae_skip_iter_after")
|
417 |
+
|
418 |
+
|
419 |
+
with gr.Row():
|
420 |
+
weight_id_ip_str = gr.Textbox(
|
421 |
+
value="0-1:1/3/5",
|
422 |
+
label="weight_id_ip_str",
|
423 |
+
interactive=False, visible=False
|
|
|
424 |
)
|
425 |
+
weight_id.change(
|
426 |
+
lambda s1, s2: f"0-1:1/{s1}/{s2}",
|
427 |
+
inputs=[weight_id, weight_ip],
|
428 |
+
outputs=weight_id_ip_str
|
429 |
)
|
430 |
+
weight_ip.change(
|
431 |
+
lambda s1, s2: f"0-1:1/{s1}/{s2}",
|
432 |
+
inputs=[weight_id, weight_ip],
|
433 |
+
outputs=weight_id_ip_str
|
434 |
+
)
|
435 |
+
vae_skip_iter = gr.Textbox(
|
436 |
+
value="0-0.05:1,0.8-1:1",
|
437 |
+
label="vae_skip_iter",
|
438 |
+
interactive=False, visible=False
|
439 |
+
)
|
440 |
+
vae_skip_iter_s1.change(
|
441 |
+
lambda s1, s2: f"0-{s1}:1,{s2}-1:1",
|
442 |
+
inputs=[vae_skip_iter_s1, vae_skip_iter_s2],
|
443 |
+
outputs=vae_skip_iter
|
444 |
+
)
|
445 |
+
vae_skip_iter_s2.change(
|
446 |
+
lambda s1, s2: f"0-{s1}:1,{s2}-1:1",
|
447 |
+
inputs=[vae_skip_iter_s1, vae_skip_iter_s2],
|
448 |
+
outputs=vae_skip_iter
|
449 |
+
)
|
450 |
+
|
451 |
+
|
452 |
with gr.Row():
|
453 |
+
db_latent_lora_scale_str = gr.Textbox(
|
454 |
+
value="0-1:0.85",
|
455 |
+
label="db_latent_lora_scale_str",
|
456 |
+
interactive=False, visible=False
|
457 |
+
)
|
458 |
+
sb_latent_lora_scale_str = gr.Textbox(
|
459 |
+
value="0-1:0.85",
|
460 |
+
label="sb_latent_lora_scale_str",
|
461 |
+
interactive=False, visible=False
|
462 |
+
)
|
463 |
+
vae_lora_scale_str = gr.Textbox(
|
464 |
+
value="0-1:1.3",
|
465 |
+
label="vae_lora_scale_str",
|
466 |
+
interactive=False, visible=False
|
467 |
+
)
|
468 |
+
vae_lora_scale.change(
|
469 |
+
lambda s: f"0-1:{s}",
|
470 |
+
inputs=vae_lora_scale,
|
471 |
+
outputs=vae_lora_scale_str
|
472 |
+
)
|
473 |
+
ip_scale_str.change(
|
474 |
+
lambda s: [f"0-1:{s}", f"0-1:{s}"],
|
475 |
+
inputs=ip_scale_str,
|
476 |
+
outputs=[db_latent_lora_scale_str, sb_latent_lora_scale_str]
|
477 |
+
)
|
478 |
+
|
479 |
with gr.Row():
|
480 |
+
double_attention = gr.Checkbox(value=False, label="Double Attention", visible=False)
|
481 |
+
single_attention = gr.Checkbox(value=True, label="Single Attention", visible=False)
|
482 |
+
|
483 |
+
clear_btn = gr.Button("清空输入图像")
|
484 |
+
with gr.Row():
|
485 |
+
with gr.Column():
|
486 |
+
image_1 = gr.Image(type="filepath", label=f"Image 1")
|
487 |
+
caption_1 = gr.Textbox(label=f"Caption 1", value="")
|
488 |
+
id_ip_checkbox_1 = gr.Checkbox(value=False, label=f"ID or not 1", visible=True)
|
489 |
+
with gr.Row():
|
490 |
+
vlm_btn_1 = gr.Button("Auto Caption")
|
491 |
+
det_btn_1 = gr.Button("Det & Seg")
|
492 |
+
face_btn_1 = gr.Button("Crop Face")
|
493 |
+
|
494 |
+
with gr.Column():
|
495 |
+
image_2 = gr.Image(type="filepath", label=f"Image 2")
|
496 |
+
caption_2 = gr.Textbox(label=f"Caption 2", value="")
|
497 |
+
id_ip_checkbox_2 = gr.Checkbox(value=False, label=f"ID or not 2", visible=True)
|
498 |
+
with gr.Row():
|
499 |
+
vlm_btn_2 = gr.Button("Auto Caption")
|
500 |
+
det_btn_2 = gr.Button("Det & Seg")
|
501 |
+
face_btn_2 = gr.Button("Crop Face")
|
502 |
+
|
503 |
+
with gr.Column():
|
504 |
+
output = gr.Image(label="生成的图像")
|
505 |
+
seed = gr.Number(value=42, label="Seed", info="")
|
506 |
+
gen_btn = gr.Button("生成图像")
|
507 |
+
|
508 |
+
gr.Markdown("### Examples")
|
509 |
+
gen_btn.click(
|
510 |
+
generate_image,
|
511 |
+
inputs=[
|
512 |
+
prompt, cond_size, target_height, target_width, seed,
|
513 |
+
vae_skip_iter, weight_id_ip_str,
|
514 |
+
double_attention, single_attention,
|
515 |
+
db_latent_lora_scale_str, sb_latent_lora_scale_str, vae_lora_scale_str,
|
516 |
+
indexs_state, # 传递 indexs 状态
|
517 |
+
# *images,
|
518 |
+
# *captions,
|
519 |
+
# *idip_checkboxes,
|
520 |
+
],
|
521 |
+
outputs=output
|
522 |
+
)
|
523 |
+
|
524 |
+
# # 修改清空函数的输出参数
|
525 |
+
# clear_btn.click(clear_images, outputs=images)
|
526 |
+
|
527 |
+
face_btn_1.click(crop_face_img, inputs=[image_1], outputs=[image_1])
|
528 |
+
det_btn_1.click(det_seg_img, inputs=[image_1, caption_1], outputs=[image_1])
|
529 |
+
vlm_btn_1.click(vlm_img_caption, inputs=[image_1], outputs=[caption_1])
|
530 |
+
|
531 |
+
face_btn_2.click(crop_face_img, inputs=[image_2], outputs=[image_2])
|
532 |
+
det_btn_2.click(det_seg_img, inputs=[image_2, caption_2], outputs=[image_2])
|
533 |
+
vlm_btn_2.click(vlm_img_caption, inputs=[image_2], outputs=[caption_2])
|
534 |
+
|
535 |
+
|
536 |
|
537 |
+
demo.queue()
|
538 |
+
demo.launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|