rhea2809 commited on
Commit
158b090
1 Parent(s): 24fbcb9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +125 -0
app.py ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+
4
+
5
+ SHEET_ID = '1eaqWOSqNAY64E8jce5R8APAe12WFGga7f0xK3Ygt9HY'
6
+ SHEET_NAME = 'Sheet1'
7
+ csv_url = f'https://docs.google.com/spreadsheets/d/{SHEET_ID}/gviz/tq?tqx=out:csv&sheet={SHEET_NAME}'
8
+
9
+ class DataList:
10
+ def __init__(self):
11
+ self.table = pd.read_csv(csv_url)
12
+ self._preprocess_table()
13
+
14
+ self.table_header = '''
15
+ <tr>
16
+ <td width="12%">Name</td>
17
+ <td width="52%">Description</td>
18
+ <td width="12%">Module</td>
19
+ <td width="12%">Type</td>
20
+ <td width="12%">Alignment with Key Guidance</td>
21
+ </tr>'''
22
+
23
+ def _preprocess_table(self) -> None:
24
+ self.table['name_lowercase'] = self.table['Name'].str.lower()
25
+
26
+ rows = []
27
+ for row in self.table.itertuples():
28
+ source = f'<a href="{row.URL}" target="_parent">{row.Name}</a>' if isinstance(
29
+ row.URL, str) else '{row.Name}'
30
+ row = f'''
31
+ <tr>
32
+ <td>{source}</td>
33
+ <td>{row.Description}</td>
34
+ <td>{row.Module}</td>
35
+ <td>{row.Type}</td>
36
+ <td>{row.Alignment}</td>
37
+ </tr>'''
38
+ rows.append(row)
39
+ self.table['html_table_content'] = rows
40
+
41
+ def render(self, search_query: str,
42
+ filter_names: list[str],
43
+ filter_names2: list[str],
44
+ filter_names3: list[str]
45
+ ) -> tuple[int, str]:
46
+ self.table = pd.read_csv(csv_url)
47
+ self._preprocess_table()
48
+
49
+ self.table_header = '''
50
+ <tr>
51
+ <td width="12%">Name</td>
52
+ <td width="52%">Description</td>
53
+ <td width="12%">Module</td>
54
+ <td width="12%">Type</td>
55
+ <td width="12%">Alignment with Key Guidance</td>
56
+ </tr>'''
57
+ df = self.table
58
+ if search_query:
59
+ df = df[df.name_lowercase.str.contains(search_query.lower())]
60
+ df = self.filter_table(df, filter_names,filter_names2,filter_names3)
61
+ result = self.to_html(df, self.table_header)
62
+ return result
63
+
64
+ @staticmethod
65
+ def filter_table(df: pd.DataFrame, filter_names: list[str], filter_names2: list[str], filter_name3: list[str],) -> pd.DataFrame:
66
+ df = df.loc[df.Type.isin(set(filter_names))]
67
+ print(filter_name3)
68
+ vals= filter_names3
69
+ df = df.loc[df.Module.isin(vals)]
70
+ return df
71
+
72
+ @staticmethod
73
+ def to_html(df: pd.DataFrame, table_header: str) -> str:
74
+ table_data = ''.join(df.html_table_content)
75
+ html = f'''
76
+ <table>
77
+ {table_header}
78
+ {table_data}
79
+ </table>'''
80
+ return html
81
+
82
+
83
+ data_list = DataList()
84
+
85
+ css = """
86
+ button.svelte-kqij2n{font-weight: bold !important;
87
+ background-color: #ebecf0;
88
+ color: black;
89
+ margin-left: 5px;}
90
+ #tlsnlbs{}
91
+ #mtcs{}
92
+ #mdls{}
93
+ #dts{}
94
+ .svelte-kqij2n .selected {
95
+ background-color: black;
96
+ color: white;
97
+ }
98
+ .app.svelte-182fdeq.svelte-182fdeq {
99
+ padding: 0 !important;
100
+ }
101
+ span.svelte-s1r2yt{font-weight: bold !important;
102
+ }
103
+ """
104
+ with gr.Blocks(css=css) as demo:
105
+ with gr.Row():
106
+ 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)
107
+ with gr.Row():
108
+ with gr.Column(scale=1):
109
+ filter_names = gr.CheckboxGroup(choices=['Guidebook','Assessment Tool','Training and Education',], value=['Guidebook','Assessment Tool','Training and Education',], label='Type')
110
+ with gr.Column(scale=1):
111
+ 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')
112
+ with gr.Row():
113
+ 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)
114
+ with gr.Row():
115
+ search_button = gr.Button('Search', size = 'sm', scale =1)
116
+
117
+ with gr.Row():
118
+ table = gr.HTML(show_label=False)
119
+
120
+ demo.load(fn=data_list.render, inputs=[search_box, filter_names,filter_names2,filter_names3,],outputs=[table,])
121
+ search_box.submit(fn=data_list.render, inputs=[search_box, filter_names,filter_names2,filter_names3,], outputs=[table,])
122
+ search_button.click(fn=data_list.render, inputs=[search_box, filter_names,filter_names2,filter_names3,], outputs=[table,])
123
+
124
+ demo.queue()
125
+ demo.launch(share=False)