Spaces:
Running
Running
fix(tagger): caption checkbox is the single source of truth for NL; auto re-run no longer reads chip outputs (Gradio 6 stale-choice crash)
Browse files
app.py
CHANGED
|
@@ -1865,9 +1865,9 @@ with gr.Blocks(**_blocks_kw) as demo:
|
|
| 1865 |
) else "ensemble"
|
| 1866 |
effective_fmt = f"{fmt}|{mode_key}" if mode_key != "ensemble" else fmt
|
| 1867 |
skip_pose = not bool(pose_toggle)
|
| 1868 |
-
#
|
| 1869 |
-
# the
|
| 1870 |
-
with_caption = bool(caption_toggle)
|
| 1871 |
return on_tag_image(image, gen_threshold, char_threshold, effective_fmt, lang, progress=progress, skip_pose=skip_pose, with_caption=with_caption)
|
| 1872 |
|
| 1873 |
tagger_outputs = [
|
|
@@ -1882,12 +1882,8 @@ with gr.Blocks(**_blocks_kw) as demo:
|
|
| 1882 |
)
|
| 1883 |
|
| 1884 |
# The "Florence NL Caption" radio item ⇔ the caption checkbox are synced:
|
| 1885 |
-
# picking the radio item checks the box
|
| 1886 |
-
|
| 1887 |
-
fn=lambda mode: gr.update(value=True) if mode == "nl" else gr.update(),
|
| 1888 |
-
inputs=[tagger_mode],
|
| 1889 |
-
outputs=[tagger_caption_toggle],
|
| 1890 |
-
)
|
| 1891 |
tagger_caption_toggle.change(
|
| 1892 |
fn=lambda checked: gr.update(value="ensemble") if not checked else gr.update(),
|
| 1893 |
inputs=[tagger_caption_toggle],
|
|
@@ -1895,25 +1891,33 @@ with gr.Blocks(**_blocks_kw) as demo:
|
|
| 1895 |
)
|
| 1896 |
|
| 1897 |
# Auto re-run when the model or the pose toggle changes (never for the
|
| 1898 |
-
# caption checkbox — captioning is opt-in and slow). No-op without an
|
| 1899 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1900 |
if image is None:
|
| 1901 |
-
return
|
| 1902 |
-
return on_tag_image_with_mode(image, gen_threshold, char_threshold, fmt, lang, mode, pose_toggle,
|
| 1903 |
|
| 1904 |
rerun_inputs = [
|
| 1905 |
tagger_image, tagger_gen_threshold, tagger_char_threshold, tagger_format,
|
| 1906 |
tagger_mode, tagger_pose_toggle, tagger_caption_toggle, lang_state,
|
| 1907 |
-
]
|
| 1908 |
tagger_mode.change(
|
| 1909 |
fn=on_tag_rerun,
|
| 1910 |
inputs=rerun_inputs,
|
| 1911 |
-
outputs=tagger_outputs,
|
| 1912 |
)
|
| 1913 |
tagger_pose_toggle.change(
|
| 1914 |
fn=on_tag_rerun,
|
| 1915 |
inputs=rerun_inputs,
|
| 1916 |
-
outputs=tagger_outputs,
|
| 1917 |
)
|
| 1918 |
tagger_chips.change(
|
| 1919 |
fn=on_tagger_selection_change,
|
|
|
|
| 1865 |
) else "ensemble"
|
| 1866 |
effective_fmt = f"{fmt}|{mode_key}" if mode_key != "ensemble" else fmt
|
| 1867 |
skip_pose = not bool(pose_toggle)
|
| 1868 |
+
# The caption checkbox is the single source of truth for the NL
|
| 1869 |
+
# caption; the "nl" radio item only checks the box (see on_tag_rerun).
|
| 1870 |
+
with_caption = bool(caption_toggle)
|
| 1871 |
return on_tag_image(image, gen_threshold, char_threshold, effective_fmt, lang, progress=progress, skip_pose=skip_pose, with_caption=with_caption)
|
| 1872 |
|
| 1873 |
tagger_outputs = [
|
|
|
|
| 1882 |
)
|
| 1883 |
|
| 1884 |
# The "Florence NL Caption" radio item ⇔ the caption checkbox are synced:
|
| 1885 |
+
# picking the radio item checks the box (inside on_tag_rerun below, in
|
| 1886 |
+
# the same event as the caption run); unchecking snaps back to Smart.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1887 |
tagger_caption_toggle.change(
|
| 1888 |
fn=lambda checked: gr.update(value="ensemble") if not checked else gr.update(),
|
| 1889 |
inputs=[tagger_caption_toggle],
|
|
|
|
| 1891 |
)
|
| 1892 |
|
| 1893 |
# Auto re-run when the model or the pose toggle changes (never for the
|
| 1894 |
+
# caption checkbox — captioning is opt-in and slow). No-op without an
|
| 1895 |
+
# image. Selecting the "nl" radio item checks the caption box and runs
|
| 1896 |
+
# the caption in the same event, so the checkbox stays the visible source
|
| 1897 |
+
# of truth. The component outputs are deliberately NOT read back as
|
| 1898 |
+
# inputs here: in Gradio 6, CheckboxGroup.preprocess validates the value
|
| 1899 |
+
# against the current choices and raises on stale selections, which
|
| 1900 |
+
# crashed re-runs ("Value: ... is not in the list of choices").
|
| 1901 |
+
def on_tag_rerun(image, gen_threshold, char_threshold, fmt, lang, mode, pose_toggle, caption_toggle, progress=gr.Progress()):
|
| 1902 |
+
with_caption = bool(caption_toggle) or mode == "nl"
|
| 1903 |
+
caption_update = gr.update(value=True) if mode == "nl" else gr.skip()
|
| 1904 |
if image is None:
|
| 1905 |
+
return (gr.skip(),) * 8 + (caption_update,)
|
| 1906 |
+
return tuple(on_tag_image_with_mode(image, gen_threshold, char_threshold, fmt, lang, mode, pose_toggle, with_caption, progress=progress)) + (caption_update,)
|
| 1907 |
|
| 1908 |
rerun_inputs = [
|
| 1909 |
tagger_image, tagger_gen_threshold, tagger_char_threshold, tagger_format,
|
| 1910 |
tagger_mode, tagger_pose_toggle, tagger_caption_toggle, lang_state,
|
| 1911 |
+
]
|
| 1912 |
tagger_mode.change(
|
| 1913 |
fn=on_tag_rerun,
|
| 1914 |
inputs=rerun_inputs,
|
| 1915 |
+
outputs=tagger_outputs + [tagger_caption_toggle],
|
| 1916 |
)
|
| 1917 |
tagger_pose_toggle.change(
|
| 1918 |
fn=on_tag_rerun,
|
| 1919 |
inputs=rerun_inputs,
|
| 1920 |
+
outputs=tagger_outputs + [tagger_caption_toggle],
|
| 1921 |
)
|
| 1922 |
tagger_chips.change(
|
| 1923 |
fn=on_tagger_selection_change,
|