File size: 3,804 Bytes
e51e8f8
 
 
 
 
 
85576c8
 
 
 
 
 
 
 
a7de579
e51e8f8
85576c8
e51e8f8
968af70
 
85576c8
968af70
85576c8
968af70
 
 
 
 
 
85576c8
968af70
85576c8
968af70
 
 
 
 
 
85576c8
968af70
85576c8
968af70
 
 
 
 
7360ecc
85576c8
7360ecc
85576c8
7360ecc
 
 
 
 
85576c8
a462e8a
85576c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cb08619
 
85576c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e51e8f8
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env python

from __future__ import annotations

import gradio as gr

from constants import (
    HARDWARE_CHOICES,
    OWNER_CHOICES,
    SDK_CHOICES,
    SLEEP_TIME_CHOICES,
    STATUS_CHOICES,
    VISIBILITY_CHOICES,
)
from demo_list import DemoList, get_df_from_yaml

demo_list = DemoList(get_df_from_yaml("list.yaml"))


def update_status_checkboxes(choices: list[str]) -> list[str]:
    if "(ALL)" in choices:
        return STATUS_CHOICES
    elif "(NONE)" in choices:
        return []
    else:
        return choices


def update_hardware_checkboxes(choices: list[str]) -> list[str]:
    if "(ALL)" in choices:
        return HARDWARE_CHOICES
    elif "(NONE)" in choices:
        return []
    else:
        return choices


def update_sdk_checkboxes(choices: list[str]) -> list[str]:
    if "(ALL)" in choices:
        return SDK_CHOICES
    elif "(NONE)" in choices:
        return []
    else:
        return choices


def update_sleep_time_checkboxes(choices: list[str]) -> list[str]:
    if "(ALL)" in choices:
        return SLEEP_TIME_CHOICES
    elif "(NONE)" in choices:
        return []
    else:
        return choices


with gr.Blocks(css="style.css") as demo:
    with gr.Accordion(label="Filter", open=True):
        status = gr.CheckboxGroup(
            label="Status",
            choices=["(ALL)", "(NONE)"] + STATUS_CHOICES,
            value=STATUS_CHOICES,
            type="value",
        )
        hardware = gr.CheckboxGroup(
            label="Hardware",
            choices=["(ALL)", "(NONE)"] + HARDWARE_CHOICES,
            value=HARDWARE_CHOICES,
            type="value",
        )
        sleep_time = gr.CheckboxGroup(
            label="Sleep time",
            choices=["(ALL)", "(NONE)"] + SLEEP_TIME_CHOICES,
            value=SLEEP_TIME_CHOICES,
            type="value",
        )
        multiple_replicas = gr.Checkbox(label="Multiple replicas", value=False)
        sdk = gr.CheckboxGroup(
            label="SDK",
            choices=["(ALL)", "(NONE)"] + SDK_CHOICES,
            value=SDK_CHOICES,
            type="value",
        )
        visibility = gr.CheckboxGroup(
            label="Visibility",
            choices=VISIBILITY_CHOICES,
            value=VISIBILITY_CHOICES,
            type="value",
        )
        owner = gr.CheckboxGroup(
            label="Owner",
            choices=OWNER_CHOICES,
            value=OWNER_CHOICES,
            type="value",
        )
        apply_button = gr.Button("Apply")
    df = gr.Dataframe(
        value=demo_list.df_prettified,
        datatype=demo_list.column_datatype,
        type="pandas",
        interactive=False,
        row_count=(0, "dynamic"),
        height=1000,
        elem_id="table",
    )

    status.change(
        fn=update_status_checkboxes,
        inputs=status,
        outputs=status,
        queue=False,
        show_progress=False,
        api_name=False,
    )
    hardware.change(
        fn=update_hardware_checkboxes,
        inputs=hardware,
        outputs=hardware,
        queue=False,
        show_progress=False,
        api_name=False,
    )
    sdk.change(
        fn=update_sdk_checkboxes,
        inputs=sdk,
        outputs=sdk,
        queue=False,
        show_progress=False,
        api_name=False,
    )
    sleep_time.change(
        fn=update_sleep_time_checkboxes,
        inputs=sleep_time,
        outputs=sleep_time,
        queue=False,
        show_progress=False,
        api_name=False,
    )
    apply_button.click(
        fn=demo_list.filter,
        inputs=[
            status,
            hardware,
            sleep_time,
            multiple_replicas,
            sdk,
            visibility,
            owner,
        ],
        outputs=df,
        api_name=False,
    )
demo.queue(api_open=False).launch()