File size: 3,422 Bytes
4a02afe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# import gradio as gr
# from caption_store import get_all_collections

# def render_search():
#     with gr.Column(visible=False) as page:
#         gr.Markdown("# 🔍 AI Search")
#         with gr.Row():
#             search_query = gr.Textbox(
#                 placeholder="Describe what you're looking for... (e.g. 'moody forest portrait')",
#                 label="Search Query", scale=4
#             )
#             search_col_filter = gr.Dropdown(
#                 choices=["All"] + get_all_collections(), value="All", label="Filter by Collection", scale=1
#             )
#             search_btn = gr.Button("Search", variant="primary", scale=1)
        
#         search_status_msg = gr.Markdown("Enter a query to start searching.")
#         search_gallery = gr.Gallery(label="Search Results", columns=4, height="auto")
#     return page, search_query, search_col_filter, search_btn, search_status_msg, search_gallery
import gradio as gr
from caption_store import get_all_collections

def render_search():
    # Selection and path tracking states for search
    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;'>🔍 AI Search</h1>

            <p style='color: #94a3b8;'>Search your archive using natural language, select results, and bulk download.</p>

        </div>

        """)
        with gr.Row():
            search_query = gr.Textbox(
                placeholder="Describe what you're looking for... (e.g. 'moody forest portrait')",
                label="Search Query", scale=4
            )
            search_col_filter = gr.Dropdown(
                choices=["All"] + get_all_collections(), value="All", label="Filter by Collection", scale=1
            )
            search_btn = gr.Button("Search", variant="primary", scale=1)
        
        search_status_msg = gr.Markdown("Enter a query to start searching.")

        # 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 Results", 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")

        # Hidden file output for compilation download
        download_file = gr.File(label="Source Quality ZIP Archive", visible=False)
        
        search_gallery = gr.Gallery(
            label="Search Results", 
            columns=4, 
            height="auto", 
            elem_classes="custom-gallery",
            allow_preview=False
        )
        
    return (
        page, search_query, search_col_filter, search_btn, search_status_msg, search_gallery,
        selected_paths, loaded_original_paths, selection_status, download_btn,
        download_file, clear_selection_btn, select_all_btn
    )