File size: 4,816 Bytes
cfd2070
 
 
 
3bd6bb0
f3801a9
cfd2070
 
 
 
 
 
 
 
 
3bd6bb0
 
 
 
 
cfd2070
 
 
 
 
 
 
2b5f693
446cd90
cfd2070
 
 
4908e9a
3bd6bb0
cfd2070
3bd6bb0
cfd2070
 
 
 
4908e9a
3bd6bb0
332149a
 
69a0dea
ec6e07d
 
 
 
 
3bd6bb0
 
 
 
 
ec6e07d
cfd2070
 
 
332149a
cfd2070
 
 
 
3908e29
300a04e
1036d9b
36510e6
7d6d977
96260cf
cfd2070
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1c31d51
 
 
cfd2070
 
 
1a97f68
b163168
23d1540
b163168
23d1540
300a04e
23d1540
 
b163168
027413d
b163168
23d1540
fdf0953
 
cfd2070
fdf0953
332149a
 
 
cfd2070
 
 
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
import gradio as gr
import pandas as pd


SHEET_ID = '1eaqWOSqNAY64E8jce5R8APAe12WFGga7f0xK3Ygt9HY'
SHEET_NAME = 'Sheet1'
csv_url = f'https://docs.google.com/spreadsheets/d/{SHEET_ID}/gviz/tq?tqx=out:csv&sheet={SHEET_NAME}'

class DataList:
    def __init__(self):
        self.table = pd.read_csv(csv_url)
        self._preprocess_table()

        self.table_header = '''
            <tr>
                <td width="12%">Name</td>
                <td width="52%">Description</td>
                <td width="12%">Module</td>
                <td width="12%">Type</td>
                <td width="12%">Alignment with Key Guidance</td>
            </tr>'''

    def _preprocess_table(self) -> None:
        self.table['name_lowercase'] = self.table['Name'].str.lower()

        rows = []
        for row in self.table.itertuples():
            source = f'<a href="{row.URL}" target="_parent">{row.Name}</a>' if isinstance(
                row.URL, str) else '{row.Name}'
            row = f'''
                <tr>
                    <td>{source}</td>
                    <td>{row.Description}</td>
                    <td>{row.Module}</td>
                    <td>{row.Type}</td>
                    <td>{row.Alignment}</td>
                </tr>'''
            rows.append(row)
        self.table['html_table_content'] = rows

    def render(self, search_query: str,
            filter_names: list[str],
            filter_names2: list[str],
            filter_names3: list[str]
            ) -> tuple[int, str]:
        self.table = pd.read_csv(csv_url)
        self._preprocess_table()

        self.table_header = '''
            <tr>
                <td width="12%">Name</td>
                <td width="52%">Description</td>
                <td width="12%">Module</td>
                <td width="12%">Type</td>
                <td width="12%">Alignment with Key Guidance</td>
            </tr>'''
        df = self.table
        if search_query:
                df = df[df.name_lowercase.str.contains(search_query.lower())]
        df = self.filter_table(df, filter_names,filter_names2,filter_names3)
        result = self.to_html(df, self.table_header)
        return result

    @staticmethod
    def filter_table(df: pd.DataFrame, filter_names: list[str], filter_names2: list[str], filter_name3: list[str],) -> pd.DataFrame:
        df = df.loc[df.Module.isin(set(filter_names))]
        print(filter_name3)
        vals= filter_names3
        df = df.loc[df.Module.isin(vals)]
        return df

    @staticmethod
    def to_html(df: pd.DataFrame, table_header: str) -> str:
        table_data = ''.join(df.html_table_content)
        html = f'''
        <table>
            {table_header}
            {table_data}
        </table>'''
        return html


data_list = DataList()

css = """
button.svelte-kqij2n{font-weight: bold !important;
background-color: #ebecf0;
color: black;
margin-left: 5px;}
#tlsnlbs{}
#mtcs{}

#mdls{}
#dts{}
.svelte-kqij2n .selected {
    background-color: black;
    color: white;
}
.app.svelte-182fdeq.svelte-182fdeq {
padding: 0 !important;
}
span.svelte-s1r2yt{font-weight: bold !important;
}
"""
with gr.Blocks(css=css) as demo:
    with gr.Row():
        search_box = gr.Textbox( label='Search Name', placeholder='You can search for titles with regular expressions. e.g. (?<!sur)face',max_lines=1, scale = 5)  
    with gr.Row():
        with gr.Column(scale=1):
            filter_names = gr.CheckboxGroup(choices=['Compliance and Regulatory Guidance','Generative AI','Training and Education',], value=['Guidebook','Assessment Tool','Training and Education',], label='Type')
        with gr.Column(scale=1):
            filter_names2 = gr.CheckboxGroup(choices=['NIST AI RMF MAP','NIST AI RMF GOVERN','ISO 42001 A.8',], value=['NIST AI RMF MAP','NIST AI RMF GOVERN','ISO 42001 A.8',], label='Alignment with Key Guidance')
    with gr.Row():
        filter_names3 = gr.CheckboxGroup(choices=['Compliance and Regulatory Guidance', 'Generative AI', 'Suppliers and Procurement', 'Policy and Governance', 'Assessing AI Systems',], value=['Compliance and Regulatory Guidance', 'Generative AI', 'Suppliers and Procurement', 'Policy and Governance', 'Assessing AI Systems',], label='Modules', interactive = True)
    with gr.Row():
        search_button = gr.Button('Search', size = 'sm', scale =1)

    with gr.Row():
        table = gr.HTML(show_label=False)
        
    demo.load(fn=data_list.render, inputs=[search_box, filter_names,filter_names2,filter_names3,],outputs=[table,])
    search_box.submit(fn=data_list.render, inputs=[search_box, filter_names,filter_names2,filter_names3,], outputs=[table,])
    search_button.click(fn=data_list.render, inputs=[search_box, filter_names,filter_names2,filter_names3,], outputs=[table,])    

demo.queue()
demo.launch(share=False)