in gemini/sample-apps/accelerating_product_innovation/app/pages_utils/product_features.py [0:0]
def render_features(features: st.delta_generator.DeltaGenerator) -> None:
"""Renders draft ideas in a grid format, allowing for selection.
Args:
features: A list of draft ideas to display.
"""
if st.session_state.generated_points is None:
st.session_state.generated_points = get_features(
st.session_state.generated_response
)
with features:
col1, col2, col3 = st.columns(3)
for i, point in enumerate(st.session_state.generated_points):
box = (
col1 if i % 3 == 0 else col2 if i % 3 == 1 else col3
) # Inline conditionals
box_id = f"box_{i}"
# Split point into two parts based on a colon (':') delimiter
parts = point.split(":", 1) # Split at most once
if len(parts) == 2:
# Extract and clean up the parts
first_part = parts[0].strip()
second_part = parts[1].strip()
parts = [first_part, second_part]
# No colon found, part assigned as the whole sentence
else:
parts = [point]
# Trim title to only the heading
title = parts[0]
try:
title_parts = title.split(".")
title = title_parts[1].strip()
except IndexError:
logging.debug("Unable to trim title")
with box:
checkbox_key = f"{title} {i}"
# Checkbox logic for idea selection
checkbox = st.checkbox(
"Select Idea",
key=checkbox_key,
value=title in st.session_state.selected_titles,
)
if checkbox:
_add_title_to_selection(title)
else:
_remove_title_from_selection(title)
# Rendering with appropriate styles
if title in st.session_state.selected_titles:
_render_box(box_id, title, parts, "box-clicked")
else:
_render_box(box_id, title, parts, "box-default")