File size: 2,724 Bytes
2303139
c960e8b
2303139
c960e8b
2303139
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c960e8b
2303139
 
 
 
 
c960e8b
2303139
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
import spaces
import gradio as gr
from hfsearch import HFSearchResult, search, update_filter, update_df

with gr.Blocks(fill_width=True) as demo:
    with gr.Column():
        search_result = gr.State(value=HFSearchResult())
        with gr.Group():
            with gr.Row(equal_height=True):
                infer_status = gr.Radio(label="Inference status", choices=["warm", "cold", "frozen", "all"], value="warm")
                gated_status = gr.Radio(label="Gated status", choices=["gated", "non-gated", "all"], value="non-gated")
                appr_status = gr.CheckboxGroup(label="Approval method", choices=["auto", "manual"], value=["auto", "manual"])
            with gr.Accordion("Advanced", open=False):
                with gr.Row(equal_height=True):
                    filter = gr.Textbox(label="Query", value="")
                    author = gr.Textbox(label="Author", value="")
                    sort = gr.Radio(label="Sort", choices=["last_modified", "likes", "downloads"], value="likes")
                    sort_method = gr.Radio(label="Sort method", choices=["ascending order", "descending order"], value="ascending order")
                    limit = gr.Number(label="Limit", info="If 0, fetches all models", value=1000, step=1, minimum=0, maximum=10000000)
        run_button = gr.Button("Search", variant="primary")
        with gr.Group():
            with gr.Accordion("Filter", open=False):
                hide_item = gr.CheckboxGroup(label="Hide items", choices=[], value=[], visible=False)
                with gr.Row(equal_height=True):
                    filter_item1 = gr.Dropdown(label="Filter item", choices=[""], value="", visible=False)
                    filter1 = gr.Dropdown(label="Filter", choices=[""], value="", allow_custom_value=True, visible=False)
                    filter_btn = gr.Button("Apply filter", variant="secondary", visible=False)
            result_df = gr.DataFrame(label="Results", type="array", value=[[]], interactive=False)

    run_button.click(search, [sort, sort_method, filter, author, infer_status, gated_status, appr_status, limit, search_result], [result_df, hide_item, search_result])\
    .success(update_filter, [filter_item1, search_result], [filter_item1, filter1, filter_btn, search_result], queue=False)
    gr.on(triggers=[hide_item.change, filter_btn.click], fn=update_df, inputs=[hide_item, filter_item1, filter1, search_result],
          outputs=[result_df, search_result], trigger_mode="once", queue=False, show_api=False)
    filter_item1.change(update_filter, [filter_item1, search_result], [filter_item1, filter1, filter_btn, search_result], queue=False, show_api=False)

demo.queue().launch()