Spaces:
Running
on
Zero
Running
on
Zero
Refactor UI in app.py to enhance layout and styling of sections, improving organization and accessibility. Adjust padding and margins for better visual consistency, and update accordion titles for clarity on prefix/suffix functionality in image uploads.
Browse files
app.py
CHANGED
|
@@ -664,25 +664,32 @@ def run_training(
|
|
| 664 |
def build_ui() -> gr.Blocks:
|
| 665 |
css = """
|
| 666 |
.pad-section {
|
| 667 |
-
padding:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 668 |
margin-bottom: 12px;
|
| 669 |
border: 1px solid var(--color-border, #e5e7eb);
|
| 670 |
border-radius: 8px;
|
| 671 |
background: var(--color-background-secondary, #fafafa);
|
| 672 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 673 |
"""
|
| 674 |
with gr.Blocks(title="Qwen-Image-Edit: Trainer", css=css) as demo:
|
| 675 |
gr.Markdown("""
|
| 676 |
# Qwen-Image-Edit Trainer
|
| 677 |
-
|
| 678 |
自動でデータセットを作成し学習を開始します。難しい操作は不要です。
|
| 679 |
-
|
| 680 |
-
画像と名前の対応づけ
|
| 681 |
-
- prefix/suffix: ファイルの同名判定のため、画像のファイル名から共通の先頭/末尾文字を取り除く指定(例: IMG_ や _v2)
|
| 682 |
-
- まずターゲット画像のファイル名(拡張子なし)から、指定した Target prefix/suffix を取り除いたものを key とします。
|
| 683 |
-
- 各コントロールは「付加」規則で、期待名 = control_prefix_i + key + control_suffix_i + ".png" を探して対応付けます。
|
| 684 |
-
- アップロード時に画像は自動で .png に変換して保存します(元のファイル名のベースは維持)。
|
| 685 |
-
- Control 0 は必須、Control 1〜7 は任意。コントロール画像が1枚だけのときは、すべてのターゲット画像に適用します。
|
| 686 |
""")
|
| 687 |
|
| 688 |
with gr.Accordion("Settings", elem_classes=["pad-section"]):
|
|
@@ -698,7 +705,16 @@ def build_ui() -> gr.Blocks:
|
|
| 698 |
max_epochs = gr.Number(label="Max epochs", value=100, precision=0)
|
| 699 |
save_every = gr.Number(label="Save every N epochs", value=10, precision=0)
|
| 700 |
|
| 701 |
-
with gr.Accordion("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 702 |
with gr.Group():
|
| 703 |
with gr.Column():
|
| 704 |
with gr.Row():
|
|
@@ -709,7 +725,7 @@ def build_ui() -> gr.Blocks:
|
|
| 709 |
main_gallery = gr.Gallery(label="Target preview", columns=4, height=220, object_fit='contain', preview=True)
|
| 710 |
|
| 711 |
# control_0 is required and shown outside the accordion
|
| 712 |
-
with gr.Accordion("Control 0", elem_classes=["pad-
|
| 713 |
with gr.Group():
|
| 714 |
with gr.Column():
|
| 715 |
with gr.Row():
|
|
@@ -720,7 +736,7 @@ def build_ui() -> gr.Blocks:
|
|
| 720 |
ctrl0_gallery = gr.Gallery(label="control_0 preview", columns=4, height=220, object_fit='contain', preview=True)
|
| 721 |
|
| 722 |
# Optional controls start from 1, accordion closed by default
|
| 723 |
-
with gr.Accordion("Control 1", open=False, elem_classes=["pad-
|
| 724 |
with gr.Group():
|
| 725 |
with gr.Column():
|
| 726 |
with gr.Row():
|
|
@@ -729,7 +745,7 @@ def build_ui() -> gr.Blocks:
|
|
| 729 |
with gr.Row():
|
| 730 |
ctrl1_files = gr.File(label="Upload control_1 images", file_count="multiple", type="filepath", height=220)
|
| 731 |
ctrl1_gallery = gr.Gallery(label="control_1 preview", columns=4, height=220, object_fit='contain', preview=True)
|
| 732 |
-
with gr.Accordion("Control 2", open=False, elem_classes=["pad-
|
| 733 |
with gr.Group():
|
| 734 |
with gr.Column():
|
| 735 |
with gr.Row():
|
|
@@ -738,7 +754,7 @@ def build_ui() -> gr.Blocks:
|
|
| 738 |
with gr.Row():
|
| 739 |
ctrl2_files = gr.File(label="Upload control_2 images", file_count="multiple", type="filepath", height=220)
|
| 740 |
ctrl2_gallery = gr.Gallery(label="control_2 preview", columns=4, height=220, object_fit='contain', preview=True)
|
| 741 |
-
with gr.Accordion("Control 3", open=False, elem_classes=["pad-
|
| 742 |
with gr.Group():
|
| 743 |
with gr.Column():
|
| 744 |
with gr.Row():
|
|
@@ -747,7 +763,7 @@ def build_ui() -> gr.Blocks:
|
|
| 747 |
with gr.Row():
|
| 748 |
ctrl3_files = gr.File(label="Upload control_3 images", file_count="multiple", type="filepath", height=220)
|
| 749 |
ctrl3_gallery = gr.Gallery(label="control_3 preview", columns=4, height=220, object_fit='contain', preview=True)
|
| 750 |
-
with gr.Accordion("Control 4", open=False, elem_classes=["pad-
|
| 751 |
with gr.Group():
|
| 752 |
with gr.Column():
|
| 753 |
with gr.Row():
|
|
@@ -756,7 +772,7 @@ def build_ui() -> gr.Blocks:
|
|
| 756 |
with gr.Row():
|
| 757 |
ctrl4_files = gr.File(label="Upload control_4 images", file_count="multiple", type="filepath", height=220)
|
| 758 |
ctrl4_gallery = gr.Gallery(label="control_4 preview", columns=4, height=220, object_fit='contain', preview=True)
|
| 759 |
-
with gr.Accordion("Control 5", open=False, elem_classes=["pad-
|
| 760 |
with gr.Group():
|
| 761 |
with gr.Column():
|
| 762 |
with gr.Row():
|
|
@@ -765,7 +781,7 @@ def build_ui() -> gr.Blocks:
|
|
| 765 |
with gr.Row():
|
| 766 |
ctrl5_files = gr.File(label="Upload control_5 images", file_count="multiple", type="filepath", height=220)
|
| 767 |
ctrl5_gallery = gr.Gallery(label="control_5 preview", columns=4, height=220, object_fit='contain', preview=True)
|
| 768 |
-
with gr.Accordion("Control 6", open=False, elem_classes=["pad-
|
| 769 |
with gr.Group():
|
| 770 |
with gr.Column():
|
| 771 |
with gr.Row():
|
|
@@ -774,7 +790,7 @@ def build_ui() -> gr.Blocks:
|
|
| 774 |
with gr.Row():
|
| 775 |
ctrl6_files = gr.File(label="Upload control_6 images", file_count="multiple", type="filepath", height=220)
|
| 776 |
ctrl6_gallery = gr.Gallery(label="control_6 preview", columns=4, height=220, object_fit='contain', preview=True)
|
| 777 |
-
with gr.Accordion("Control 7", open=False, elem_classes=["pad-
|
| 778 |
with gr.Group():
|
| 779 |
with gr.Column():
|
| 780 |
with gr.Row():
|
|
|
|
| 664 |
def build_ui() -> gr.Blocks:
|
| 665 |
css = """
|
| 666 |
.pad-section {
|
| 667 |
+
padding: 6px;
|
| 668 |
+
margin-bottom: 12px;
|
| 669 |
+
border: 1px solid var(--color-border, #e5e7eb);
|
| 670 |
+
border-radius: 8px;
|
| 671 |
+
background: var(--color-background-secondary, #ffffff);
|
| 672 |
+
}
|
| 673 |
+
.pad-section_0 {
|
| 674 |
+
padding: 6px;
|
| 675 |
margin-bottom: 12px;
|
| 676 |
border: 1px solid var(--color-border, #e5e7eb);
|
| 677 |
border-radius: 8px;
|
| 678 |
background: var(--color-background-secondary, #fafafa);
|
| 679 |
}
|
| 680 |
+
.pad-section_1 {
|
| 681 |
+
padding: 6px;
|
| 682 |
+
margin-bottom: 12px;
|
| 683 |
+
border: 1px solid var(--color-border, #e5e7eb);
|
| 684 |
+
border-radius: 8px;
|
| 685 |
+
background: var(--color-background-secondary, #eaeaea);
|
| 686 |
+
}
|
| 687 |
"""
|
| 688 |
with gr.Blocks(title="Qwen-Image-Edit: Trainer", css=css) as demo:
|
| 689 |
gr.Markdown("""
|
| 690 |
# Qwen-Image-Edit Trainer
|
| 691 |
+
学習に使う画像をアップロードし、必要ならファイル名の前後にある共通の文字(prefix/suffix)を指定して、
|
| 692 |
自動でデータセットを作成し学習を開始します。難しい操作は不要です。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 693 |
""")
|
| 694 |
|
| 695 |
with gr.Accordion("Settings", elem_classes=["pad-section"]):
|
|
|
|
| 705 |
max_epochs = gr.Number(label="Max epochs", value=100, precision=0)
|
| 706 |
save_every = gr.Number(label="Save every N epochs", value=10, precision=0)
|
| 707 |
|
| 708 |
+
with gr.Accordion("prefix/sufixについて", open=False):
|
| 709 |
+
gr.Markdown("""
|
| 710 |
+
ファイルの同名判定のため、画像のファイル名から共通の先頭/末尾文字を取り除く指定(例: IMG_ や _v2)
|
| 711 |
+
- まずターゲット画像のファイル名(拡張子なし)から、指定した Target prefix/suffix を取り除いたものを key とします。
|
| 712 |
+
- 各コントロールは「付加」規則で、期待名 = control_prefix_i + key + control_suffix_i + ".png" を探して対応付けます。
|
| 713 |
+
- アップロード時に画像は自動で .png に変換して保存します(元のファイル名のベースは維持)。
|
| 714 |
+
- Control 0 は必須、Control 1〜7 は任意。コントロール画像が1枚だけのときは、すべてのターゲット画像に適用します。
|
| 715 |
+
""")
|
| 716 |
+
|
| 717 |
+
with gr.Accordion("Target Image", elem_classes=["pad-section_0"]):
|
| 718 |
with gr.Group():
|
| 719 |
with gr.Column():
|
| 720 |
with gr.Row():
|
|
|
|
| 725 |
main_gallery = gr.Gallery(label="Target preview", columns=4, height=220, object_fit='contain', preview=True)
|
| 726 |
|
| 727 |
# control_0 is required and shown outside the accordion
|
| 728 |
+
with gr.Accordion("Control 0", elem_classes=["pad-section_1"]):
|
| 729 |
with gr.Group():
|
| 730 |
with gr.Column():
|
| 731 |
with gr.Row():
|
|
|
|
| 736 |
ctrl0_gallery = gr.Gallery(label="control_0 preview", columns=4, height=220, object_fit='contain', preview=True)
|
| 737 |
|
| 738 |
# Optional controls start from 1, accordion closed by default
|
| 739 |
+
with gr.Accordion("Control 1", open=False, elem_classes=["pad-section_0"]):
|
| 740 |
with gr.Group():
|
| 741 |
with gr.Column():
|
| 742 |
with gr.Row():
|
|
|
|
| 745 |
with gr.Row():
|
| 746 |
ctrl1_files = gr.File(label="Upload control_1 images", file_count="multiple", type="filepath", height=220)
|
| 747 |
ctrl1_gallery = gr.Gallery(label="control_1 preview", columns=4, height=220, object_fit='contain', preview=True)
|
| 748 |
+
with gr.Accordion("Control 2", open=False, elem_classes=["pad-section_1"]):
|
| 749 |
with gr.Group():
|
| 750 |
with gr.Column():
|
| 751 |
with gr.Row():
|
|
|
|
| 754 |
with gr.Row():
|
| 755 |
ctrl2_files = gr.File(label="Upload control_2 images", file_count="multiple", type="filepath", height=220)
|
| 756 |
ctrl2_gallery = gr.Gallery(label="control_2 preview", columns=4, height=220, object_fit='contain', preview=True)
|
| 757 |
+
with gr.Accordion("Control 3", open=False, elem_classes=["pad-section_0"]):
|
| 758 |
with gr.Group():
|
| 759 |
with gr.Column():
|
| 760 |
with gr.Row():
|
|
|
|
| 763 |
with gr.Row():
|
| 764 |
ctrl3_files = gr.File(label="Upload control_3 images", file_count="multiple", type="filepath", height=220)
|
| 765 |
ctrl3_gallery = gr.Gallery(label="control_3 preview", columns=4, height=220, object_fit='contain', preview=True)
|
| 766 |
+
with gr.Accordion("Control 4", open=False, elem_classes=["pad-section_1"]):
|
| 767 |
with gr.Group():
|
| 768 |
with gr.Column():
|
| 769 |
with gr.Row():
|
|
|
|
| 772 |
with gr.Row():
|
| 773 |
ctrl4_files = gr.File(label="Upload control_4 images", file_count="multiple", type="filepath", height=220)
|
| 774 |
ctrl4_gallery = gr.Gallery(label="control_4 preview", columns=4, height=220, object_fit='contain', preview=True)
|
| 775 |
+
with gr.Accordion("Control 5", open=False, elem_classes=["pad-section_0"]):
|
| 776 |
with gr.Group():
|
| 777 |
with gr.Column():
|
| 778 |
with gr.Row():
|
|
|
|
| 781 |
with gr.Row():
|
| 782 |
ctrl5_files = gr.File(label="Upload control_5 images", file_count="multiple", type="filepath", height=220)
|
| 783 |
ctrl5_gallery = gr.Gallery(label="control_5 preview", columns=4, height=220, object_fit='contain', preview=True)
|
| 784 |
+
with gr.Accordion("Control 6", open=False, elem_classes=["pad-section_1"]):
|
| 785 |
with gr.Group():
|
| 786 |
with gr.Column():
|
| 787 |
with gr.Row():
|
|
|
|
| 790 |
with gr.Row():
|
| 791 |
ctrl6_files = gr.File(label="Upload control_6 images", file_count="multiple", type="filepath", height=220)
|
| 792 |
ctrl6_gallery = gr.Gallery(label="control_6 preview", columns=4, height=220, object_fit='contain', preview=True)
|
| 793 |
+
with gr.Accordion("Control 7", open=False, elem_classes=["pad-section_0"]):
|
| 794 |
with gr.Group():
|
| 795 |
with gr.Column():
|
| 796 |
with gr.Row():
|