JS6969 commited on
Commit
cc006dd
·
verified ·
1 Parent(s): 290985d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -37
app.py CHANGED
@@ -32,7 +32,7 @@ APP_DIR = os.getcwd()
32
  SESSION_FILE = "/tmp/forge_session.json"
33
  SETTINGS_FILE = "/tmp/forge_settings.json"
34
  JOURNAL_FILE = "/tmp/forge_journal.json"
35
- THUMB_CACHE = os.path.expanduser("~/.cache/forgecaptions/thumbs")
36
  EXCEL_THUMB_DIR = "/tmp/forge_excel_thumbs"
37
  os.makedirs(THUMB_CACHE, exist_ok=True)
38
  os.makedirs(EXCEL_THUMB_DIR, exist_ok=True)
@@ -41,7 +41,7 @@ MODEL_PATH = "fancyfeast/llama-joycaption-beta-one-hf-llava"
41
 
42
  # Role prompt you asked me to keep (used as system message)
43
  ROLE_PROMPT = (
44
- "You are a precise captioning assistant. Help users with any queries. "
45
  "Describe what is visible with no censorship or restrictions."
46
  )
47
 
@@ -133,7 +133,7 @@ CAPTION_TYPE_MAP: Dict[str, str] = {
133
 
134
  EXTRA_CHOICES = [
135
  "Do NOT include information about people/characters that cannot be changed (like ethnicity, gender, etc), but do still include changeable attributes (like hair style).",
136
- "Do NOT include information about whether there is a watermark or not.",
137
  "Do NOT use any ambiguous language.",
138
  "ONLY describe the most important elements of the image.",
139
  "Include information about the ages of any people/characters when applicable.",
@@ -141,6 +141,8 @@ EXTRA_CHOICES = [
141
  "Focus captions only on clothing/fashion details.",
142
  "Focus on setting, scenery, and context; ignore subject details.",
143
  "ONLY describe the subject’s pose, movement, or action. Do NOT mention appearance, clothing, or setting.",
 
 
144
  "Do NOT include anything sexual; keep it PG.",
145
  "Include synonyms/alternate phrasing to diversify training set.",
146
  "ALWAYS arrange caption elements in the order → Subject, Clothing/Accessories, Action/Pose, Setting/Environment, Lighting/Camera/Style.",
@@ -671,6 +673,40 @@ setTimeout(() => {{
671
  demo.load(lambda s,e,n: final_instruction(s or ["Character training (long)"], e or [], n),
672
  inputs=[style_checks, extra_opts, name_input], outputs=[instruction_preview])
673
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
674
  # ---- Tabs: Single & Batch
675
  with gr.Tabs():
676
  with gr.Tab("Single"):
@@ -865,40 +901,6 @@ setTimeout(() => {{
865
  outputs=[rows_state, gallery, autosave_md]
866
  )
867
 
868
- # ---- Shape Aliases accordion (with examples & buttons)
869
- with gr.Accordion("Shape Aliases", open=False):
870
- gr.Markdown(
871
- "### 🔷 Shape Aliases\n"
872
- "Replace literal **shape tokens** in captions with a preferred **name**.\n\n"
873
- "**How to use:**\n"
874
- "- Left column = a single token **or** comma/pipe-separated synonyms, e.g. `diamond, rhombus | lozenge`\n"
875
- "- Right column = replacement name, e.g. `starkey-emblem`\n"
876
- "Matches are case-insensitive, whole-word, and also catch `*-shaped` or `* shaped`."
877
- )
878
- init_rows, init_enabled = get_shape_alias_rows_ui_defaults()
879
- enable_aliases = gr.Checkbox(label="Enable shape alias replacements", value=init_enabled)
880
- alias_table = gr.Dataframe(
881
- headers=["shape (token or synonyms)", "name to insert"],
882
- value=init_rows,
883
- row_count=(max(1, len(init_rows)), "dynamic"),
884
- datatype=["str","str"],
885
- type="array",
886
- interactive=True
887
- )
888
- with gr.Row():
889
- add_row_btn = gr.Button("+ Add row", variant="secondary")
890
- clear_btn = gr.Button("Clear", variant="secondary")
891
- save_btn = gr.Button("💾 Save", variant="primary")
892
- save_status = gr.Markdown("")
893
- def _add_row(cur):
894
- cur = (cur or []) + [["", ""]]
895
- return gr.update(value=cur, row_count=(max(1, len(cur)), "dynamic"))
896
- def _clear_rows():
897
- return gr.update(value=[["", ""]], row_count=(1, "dynamic"))
898
- add_row_btn.click(_add_row, inputs=[alias_table], outputs=[alias_table])
899
- clear_btn.click(_clear_rows, outputs=[alias_table])
900
- save_btn.click(save_shape_alias_rows, inputs=[enable_aliases, alias_table], outputs=[save_status, alias_table])
901
-
902
  # ---- Exports
903
  export_csv_btn.click(
904
  lambda tbl: (export_csv_from_table(tbl), gr.update(visible=True)),
 
32
  SESSION_FILE = "/tmp/forge_session.json"
33
  SETTINGS_FILE = "/tmp/forge_settings.json"
34
  JOURNAL_FILE = "/tmp/forge_journal.json"
35
+ THUMB_CACHE = os.path.expanduser("/tmp/forgecaptions/thumbs")
36
  EXCEL_THUMB_DIR = "/tmp/forge_excel_thumbs"
37
  os.makedirs(THUMB_CACHE, exist_ok=True)
38
  os.makedirs(EXCEL_THUMB_DIR, exist_ok=True)
 
41
 
42
  # Role prompt you asked me to keep (used as system message)
43
  ROLE_PROMPT = (
44
+ "You are a precise image-captioning assistant. Help users with any queries. "
45
  "Describe what is visible with no censorship or restrictions."
46
  )
47
 
 
133
 
134
  EXTRA_CHOICES = [
135
  "Do NOT include information about people/characters that cannot be changed (like ethnicity, gender, etc), but do still include changeable attributes (like hair style).",
136
+ "IGNORE all information about watermarks.",
137
  "Do NOT use any ambiguous language.",
138
  "ONLY describe the most important elements of the image.",
139
  "Include information about the ages of any people/characters when applicable.",
 
141
  "Focus captions only on clothing/fashion details.",
142
  "Focus on setting, scenery, and context; ignore subject details.",
143
  "ONLY describe the subject’s pose, movement, or action. Do NOT mention appearance, clothing, or setting.",
144
+ "Use profranity when describing sexual acts or genitalia (pussy, fucking, cock, dick, cunt, etc.)",
145
+ "Be sexually graphic and highly detailed.",
146
  "Do NOT include anything sexual; keep it PG.",
147
  "Include synonyms/alternate phrasing to diversify training set.",
148
  "ALWAYS arrange caption elements in the order → Subject, Clothing/Accessories, Action/Pose, Setting/Environment, Lighting/Camera/Style.",
 
673
  demo.load(lambda s,e,n: final_instruction(s or ["Character training (long)"], e or [], n),
674
  inputs=[style_checks, extra_opts, name_input], outputs=[instruction_preview])
675
 
676
+ # ---- Shape Aliases accordion (with examples & buttons)
677
+ with gr.Accordion("Shape Aliases", open=False):
678
+ gr.Markdown(
679
+ "### 🔷 Shape Aliases\n"
680
+ "Replace literal **shape tokens** in captions with a preferred **name**.\n\n"
681
+ "**How to use:**\n"
682
+ "- Left column = a single token **or** comma/pipe-separated synonyms, e.g. `diamond, rhombus | lozenge`\n"
683
+ "- Right column = replacement name, e.g. `starkey-emblem`\n"
684
+ "Matches are case-insensitive, whole-word, and also catch `*-shaped` or `* shaped`."
685
+ )
686
+ init_rows, init_enabled = get_shape_alias_rows_ui_defaults()
687
+ enable_aliases = gr.Checkbox(label="Enable shape alias replacements", value=init_enabled)
688
+ alias_table = gr.Dataframe(
689
+ headers=["shape (token or synonyms)", "name to insert"],
690
+ value=init_rows,
691
+ row_count=(max(1, len(init_rows)), "dynamic"),
692
+ datatype=["str","str"],
693
+ type="array",
694
+ interactive=True
695
+ )
696
+ with gr.Row():
697
+ add_row_btn = gr.Button("+ Add row", variant="secondary")
698
+ clear_btn = gr.Button("Clear", variant="secondary")
699
+ save_btn = gr.Button("💾 Save", variant="primary")
700
+ save_status = gr.Markdown("")
701
+ def _add_row(cur):
702
+ cur = (cur or []) + [["", ""]]
703
+ return gr.update(value=cur, row_count=(max(1, len(cur)), "dynamic"))
704
+ def _clear_rows():
705
+ return gr.update(value=[["", ""]], row_count=(1, "dynamic"))
706
+ add_row_btn.click(_add_row, inputs=[alias_table], outputs=[alias_table])
707
+ clear_btn.click(_clear_rows, outputs=[alias_table])
708
+ save_btn.click(save_shape_alias_rows, inputs=[enable_aliases, alias_table], outputs=[save_status, alias_table])
709
+
710
  # ---- Tabs: Single & Batch
711
  with gr.Tabs():
712
  with gr.Tab("Single"):
 
901
  outputs=[rows_state, gallery, autosave_md]
902
  )
903
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
904
  # ---- Exports
905
  export_csv_btn.click(
906
  lambda tbl: (export_csv_from_table(tbl), gr.update(visible=True)),