Option to replace underscores with spaces.
Browse files- app/app.py +34 -8
app/app.py
CHANGED
@@ -523,7 +523,6 @@ def image_tagger_app():
|
|
523 |
windows_system = is_windows()
|
524 |
flash_attn_installed = check_flash_attention()
|
525 |
|
526 |
-
# Initialize session state settings
|
527 |
if 'settings' not in st.session_state:
|
528 |
st.session_state.settings = {
|
529 |
'show_all_tags': False,
|
@@ -532,7 +531,8 @@ def image_tagger_app():
|
|
532 |
'threshold_profile': "Balanced",
|
533 |
'active_threshold': 0.35,
|
534 |
'active_category_thresholds': None,
|
535 |
-
'selected_categories': {}
|
|
|
536 |
}
|
537 |
# Initialize show_profile_help state
|
538 |
st.session_state.show_profile_help = False
|
@@ -1687,6 +1687,10 @@ def image_tagger_app():
|
|
1687 |
value=st.session_state.settings['show_all_tags'])
|
1688 |
compact_view = st.checkbox("Compact view (hide progress bars)",
|
1689 |
value=st.session_state.settings['compact_view'])
|
|
|
|
|
|
|
|
|
1690 |
|
1691 |
with col2:
|
1692 |
min_confidence = st.slider("Minimum confidence to display", 0.0, 0.5,
|
@@ -1696,6 +1700,7 @@ def image_tagger_app():
|
|
1696 |
st.session_state.settings['show_all_tags'] = show_all_tags
|
1697 |
st.session_state.settings['compact_view'] = compact_view
|
1698 |
st.session_state.settings['min_confidence'] = min_confidence
|
|
|
1699 |
|
1700 |
# Category selection for the "All Tags" section
|
1701 |
st.write("Categories to include in 'All Tags' section:")
|
@@ -1931,26 +1936,38 @@ def image_tagger_app():
|
|
1931 |
if compact_view:
|
1932 |
# Compact view - show tags in a comma-separated list with %
|
1933 |
tag_list = []
|
|
|
|
|
1934 |
for tag, prob in limited_tags_to_display:
|
1935 |
# Format: tag (percent%)
|
1936 |
percentage = int(prob * 100)
|
1937 |
-
|
|
|
|
|
|
|
1938 |
|
1939 |
# Add tag to all_tags list if it passes threshold and category is selected
|
|
|
1940 |
if prob >= threshold and selected_categories.get(category, True):
|
1941 |
all_tags.append(tag)
|
1942 |
-
|
1943 |
# Join with commas and display
|
1944 |
st.markdown(", ".join(tag_list))
|
1945 |
else:
|
1946 |
# Expanded view with progress bars
|
1947 |
for tag, prob in limited_tags_to_display:
|
|
|
|
|
|
|
|
|
|
|
|
|
1948 |
# Add tag to all_tags list if it passes threshold and category is selected
|
1949 |
if prob >= threshold and selected_categories.get(category, True):
|
1950 |
-
all_tags.append(tag)
|
1951 |
-
tag_display = f"**{
|
1952 |
else:
|
1953 |
-
tag_display =
|
1954 |
|
1955 |
# Display tag with progress bar
|
1956 |
st.write(tag_display)
|
@@ -1964,7 +1981,16 @@ def image_tagger_app():
|
|
1964 |
st.markdown("---")
|
1965 |
st.subheader(f"All Tags ({len(all_tags)} total)")
|
1966 |
if all_tags:
|
1967 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1968 |
else:
|
1969 |
st.info("No tags detected above the threshold.")
|
1970 |
|
|
|
523 |
windows_system = is_windows()
|
524 |
flash_attn_installed = check_flash_attention()
|
525 |
|
|
|
526 |
if 'settings' not in st.session_state:
|
527 |
st.session_state.settings = {
|
528 |
'show_all_tags': False,
|
|
|
531 |
'threshold_profile': "Balanced",
|
532 |
'active_threshold': 0.35,
|
533 |
'active_category_thresholds': None,
|
534 |
+
'selected_categories': {},
|
535 |
+
'replace_underscores': False # Added new setting
|
536 |
}
|
537 |
# Initialize show_profile_help state
|
538 |
st.session_state.show_profile_help = False
|
|
|
1687 |
value=st.session_state.settings['show_all_tags'])
|
1688 |
compact_view = st.checkbox("Compact view (hide progress bars)",
|
1689 |
value=st.session_state.settings['compact_view'])
|
1690 |
+
|
1691 |
+
# Add the new checkbox for replacing underscores with spaces
|
1692 |
+
replace_underscores = st.checkbox("Replace underscores with spaces",
|
1693 |
+
value=st.session_state.settings.get('replace_underscores', False))
|
1694 |
|
1695 |
with col2:
|
1696 |
min_confidence = st.slider("Minimum confidence to display", 0.0, 0.5,
|
|
|
1700 |
st.session_state.settings['show_all_tags'] = show_all_tags
|
1701 |
st.session_state.settings['compact_view'] = compact_view
|
1702 |
st.session_state.settings['min_confidence'] = min_confidence
|
1703 |
+
st.session_state.settings['replace_underscores'] = replace_underscores
|
1704 |
|
1705 |
# Category selection for the "All Tags" section
|
1706 |
st.write("Categories to include in 'All Tags' section:")
|
|
|
1936 |
if compact_view:
|
1937 |
# Compact view - show tags in a comma-separated list with %
|
1938 |
tag_list = []
|
1939 |
+
|
1940 |
+
replace_underscores = st.session_state.settings.get('replace_underscores', False)
|
1941 |
for tag, prob in limited_tags_to_display:
|
1942 |
# Format: tag (percent%)
|
1943 |
percentage = int(prob * 100)
|
1944 |
+
|
1945 |
+
# Apply underscore replacement for display if enabled
|
1946 |
+
display_tag = tag.replace('_', ' ') if replace_underscores else tag
|
1947 |
+
tag_list.append(f"{display_tag} ({percentage}%)")
|
1948 |
|
1949 |
# Add tag to all_tags list if it passes threshold and category is selected
|
1950 |
+
# Note: always use original tag (with underscores) for all_tags collection
|
1951 |
if prob >= threshold and selected_categories.get(category, True):
|
1952 |
all_tags.append(tag)
|
1953 |
+
|
1954 |
# Join with commas and display
|
1955 |
st.markdown(", ".join(tag_list))
|
1956 |
else:
|
1957 |
# Expanded view with progress bars
|
1958 |
for tag, prob in limited_tags_to_display:
|
1959 |
+
# Get the replacement setting
|
1960 |
+
replace_underscores = st.session_state.settings.get('replace_underscores', False)
|
1961 |
+
|
1962 |
+
# Apply underscore replacement for display if enabled
|
1963 |
+
display_tag = tag.replace('_', ' ') if replace_underscores else tag
|
1964 |
+
|
1965 |
# Add tag to all_tags list if it passes threshold and category is selected
|
1966 |
if prob >= threshold and selected_categories.get(category, True):
|
1967 |
+
all_tags.append(tag) # Add original tag to all_tags
|
1968 |
+
tag_display = f"**{display_tag}**" # Bold for tags above threshold
|
1969 |
else:
|
1970 |
+
tag_display = display_tag # Regular for tags below threshold
|
1971 |
|
1972 |
# Display tag with progress bar
|
1973 |
st.write(tag_display)
|
|
|
1981 |
st.markdown("---")
|
1982 |
st.subheader(f"All Tags ({len(all_tags)} total)")
|
1983 |
if all_tags:
|
1984 |
+
# Check if underscore replacement is enabled
|
1985 |
+
replace_underscores = st.session_state.settings.get('replace_underscores', False)
|
1986 |
+
|
1987 |
+
if replace_underscores:
|
1988 |
+
# Create a new list with underscores replaced by spaces for display only
|
1989 |
+
display_tags = [tag.replace('_', ' ') for tag in all_tags]
|
1990 |
+
st.write(", ".join(display_tags))
|
1991 |
+
else:
|
1992 |
+
# Display original tags
|
1993 |
+
st.write(", ".join(all_tags))
|
1994 |
else:
|
1995 |
st.info("No tags detected above the threshold.")
|
1996 |
|