Spaces:
Runtime error
Runtime error
| # import gradio as gr | |
| # from caption_store import get_all_collections | |
| # def render_collections(): | |
| # with gr.Column(visible=False) as page: | |
| # gr.Markdown("# π Collections") | |
| # with gr.Row(): | |
| # # Dynamically determine valid initial choices | |
| # choices = get_all_collections() | |
| # if not choices: | |
| # choices = ["General"] | |
| # val = "General" if "General" in choices else choices[0] | |
| # view_coll_selector = gr.Dropdown( | |
| # choices=choices, | |
| # value=val, | |
| # label="Select Collection to Browse", | |
| # scale=4 | |
| # ) | |
| # refresh_coll_btn = gr.Button("π Refresh", scale=1) | |
| # coll_status = gr.Markdown("Browse your organized photos.") | |
| # coll_gallery = gr.Gallery(label="Collection Photos", columns=5, height="auto") | |
| # return page, view_coll_selector, refresh_coll_btn, coll_status, coll_gallery | |
| import os | |
| import gradio as gr | |
| from caption_store import get_all_collections | |
| def render_collections(): | |
| # Gradio selection tracking states | |
| selected_paths = gr.State([]) | |
| loaded_original_paths = gr.State([]) | |
| with gr.Column(visible=False, elem_classes="page-container") as page: | |
| gr.HTML(""" | |
| <div style='margin-bottom: 20px;'> | |
| <h1 style='font-size: 2rem; font-weight: 700; color: #f8fafc;'>π Browse Collections</h1> | |
| <p style='color: #94a3b8;'>Select images by clicking them in the gallery to package and download.</p> | |
| </div> | |
| """) | |
| with gr.Row(): | |
| choices = get_all_collections() | |
| if not choices: | |
| choices = ["General"] | |
| val = "General" if "General" in choices else choices[0] | |
| view_coll_selector = gr.Dropdown( | |
| choices=choices, | |
| value=val, | |
| label="Select Collection to Browse", | |
| scale=4 | |
| ) | |
| refresh_coll_btn = gr.Button("π Refresh list", scale=1) | |
| coll_status = gr.Markdown("Browse your organized photos.") | |
| # Full-width panel for selected files output | |
| selection_status = gr.Markdown( | |
| value="**0** image(s) selected for download packaging.\n\n*No files currently selected.*", | |
| elem_classes="selection-status-box" | |
| ) | |
| # Standalone row for action buttons | |
| with gr.Row(elem_classes="selection-buttons-row"): | |
| select_all_btn = gr.Button("β Select All", size="sm", variant="secondary") | |
| clear_selection_btn = gr.Button("π§Ή Clear Selection", size="sm", variant="secondary") | |
| download_btn = gr.Button("π¦ Zip & Download Selected", variant="primary", size="sm") | |
| # Dynamic hidden archive download trigger | |
| download_file = gr.File(label="Source Quality ZIP Archive", visible=False) | |
| coll_gallery = gr.Gallery( | |
| label="Collection Photos", | |
| columns=5, | |
| height="auto", | |
| elem_classes="custom-gallery", | |
| allow_preview=False | |
| ) | |
| return ( | |
| page, view_coll_selector, refresh_coll_btn, coll_status, coll_gallery, | |
| selected_paths, loaded_original_paths, selection_status, download_btn, | |
| download_file, clear_selection_btn, select_all_btn | |
| ) |