throaway2854 commited on
Commit
efa182c
·
verified ·
1 Parent(s): 82722a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -35
app.py CHANGED
@@ -90,6 +90,30 @@ def load_labels(df: pd.DataFrame):
90
  return tag_names, rating_indexes, general_indexes, character_indexes
91
 
92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  class VideoTagger:
94
  """
95
  Wraps a WD-style ONNX model and tag metadata,
@@ -499,46 +523,61 @@ with gr.Blocks(title=TITLE) as demo:
499
  combined_tags = gr.Textbox(
500
  label="Combined Unique Tags (All Frames)",
501
  lines=6,
502
- buttons=list['copy'],
503
  )
504
  debug_info = gr.JSON(
505
  label="Details / Debug Info",
506
  )
507
 
508
- # ---------------- TAB 2: TAG CONTROL ----------------
509
- with gr.Tab("Tag Control"):
510
- gr.Markdown("### Tag Substitutes")
511
- gr.Markdown(
512
- "Add rows where **Original Tag** will be replaced by **Substitute Tag** "
513
- "in the final combined output (after all frames are processed)."
514
- )
515
-
516
- tag_substitutes_df = gr.Dataframe(
517
- headers=["Original Tag", "Substitute Tag"],
518
- datatype=["str", "str"],
519
- row_count=1,
520
- row_limits=(1, None),
521
- column_count=2,
522
- type="array",
523
- label="Tag Substitutes",
524
- interactive=True,
525
- )
526
-
527
- gr.Markdown("### Tag Exclusions")
528
- gr.Markdown(
529
- "Add tags that should be **removed entirely** from the final combined output."
530
- )
531
-
532
- tag_exclusions_df = gr.Dataframe(
533
- headers=["Tag to Exclude"],
534
- datatype=["str"],
535
- row_count=1,
536
- row_limits=(1, None),
537
- column_count=1,
538
- type="array",
539
- label="Tag Exclusions",
540
- interactive=True,
541
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
542
 
543
  # Wiring the button AFTER all components are defined
544
  run_button.click(
 
90
  return tag_names, rating_indexes, general_indexes, character_indexes
91
 
92
 
93
+ def add_substitute_row(current):
94
+ """
95
+ Append an empty [original, substitute] row to the substitutes dataframe.
96
+ Works with type='array' (list of lists).
97
+ """
98
+ if current is None:
99
+ current = []
100
+ # Make sure we have a plain list of lists
101
+ current = list(current)
102
+ current.append(["", ""])
103
+ return current
104
+
105
+
106
+ def add_exclusion_row(current):
107
+ """
108
+ Append an empty [tag] row to the exclusions dataframe.
109
+ """
110
+ if current is None:
111
+ current = []
112
+ current = list(current)
113
+ current.append([""])
114
+ return current
115
+
116
+
117
  class VideoTagger:
118
  """
119
  Wraps a WD-style ONNX model and tag metadata,
 
523
  combined_tags = gr.Textbox(
524
  label="Combined Unique Tags (All Frames)",
525
  lines=6,
526
+ buttons=["copy"],
527
  )
528
  debug_info = gr.JSON(
529
  label="Details / Debug Info",
530
  )
531
 
532
+ # ---------------- TAB 2: TAG CONTROL ----------------
533
+ with gr.Tab("Tag Control"):
534
+ gr.Markdown("### Tag Substitutes")
535
+ gr.Markdown(
536
+ "Add rows where **Original Tag** will be replaced by **Substitute Tag** "
537
+ "in the final combined output (after all frames are processed)."
538
+ )
539
+
540
+ with gr.Row():
541
+ tag_substitutes_df = gr.Dataframe(
542
+ headers=["Original Tag", "Substitute Tag"],
543
+ datatype=["str", "str"],
544
+ row_count=1, # just start with 1 empty row
545
+ column_count=2,
546
+ type="array",
547
+ label="Tag Substitutes",
548
+ interactive=True,
549
+ )
550
+ add_sub_row_btn = gr.Button("➕ Add substitute", scale=0)
551
+
552
+ gr.Markdown("### Tag Exclusions")
553
+ gr.Markdown(
554
+ "Add tags that should be **removed entirely** from the final combined output."
555
+ )
556
+
557
+ with gr.Row():
558
+ tag_exclusions_df = gr.Dataframe(
559
+ headers=["Tag to Exclude"],
560
+ datatype=["str"],
561
+ row_count=1, # start with 1 row
562
+ column_count=1,
563
+ type="array",
564
+ label="Tag Exclusions",
565
+ interactive=True,
566
+ )
567
+ add_ex_row_btn = gr.Button("➕ Add exclusion", scale=0)
568
+
569
+ add_sub_row_btn.click(
570
+ fn=add_substitute_row,
571
+ inputs=tag_substitutes_df,
572
+ outputs=tag_substitutes_df,
573
+ )
574
+
575
+ add_ex_row_btn.click(
576
+ fn=add_exclusion_row,
577
+ inputs=tag_exclusions_df,
578
+ outputs=tag_exclusions_df,
579
+ )
580
+
581
 
582
  # Wiring the button AFTER all components are defined
583
  run_button.click(