File size: 4,135 Bytes
20671d6
7b9b78a
fd436d1
7b9b78a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36b272f
c1b1ef1
fd436d1
 
 
c1b1ef1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fd436d1
a7133ac
 
 
 
 
 
 
 
 
 
 
 
 
c1b1ef1
fd436d1
 
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
import gradio as gr
import pandas as pd


SHEET_ID = '1BWKw2ygYQUUPcNdSJhW9OkXILWO5i-dCa5Uahn9dHNo'
SHEET_NAME = 'Datasets'
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.table = self.table.astype({'Year':'string'})
        self._preprocess_table()

        self.table_header = '''
            <tr>
                <td width="15%">Name</td>
                <td width="10%">URL</td>
                <td width="30%">About</td>
                <td width="15%">Publisher</td>
                <td width="10%">Year Updated</td>
                <td width="10%">Type</td>
                <td width="10%">Tag</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="_blank">Link</a>' if isinstance(
                row.URL, str) else ''
            row = f'''
                <tr>
                    <td>{row.Name}</td>
                    <td>{source}</td>
                    <td>{row.About}</td>
                    <td>{row.Publisher}</td>
                    <td>{row.Year}</td>
                    <td>{row.Type}</td>
                    <td>{row.Tags}</td>
                </tr>'''
            rows.append(row)
        self.table['html_table_content'] = rows

    def render(self, search_query: str, 
            case_sensitive: bool,
            filter_names: list[str],
            data_types: list[str]) -> tuple[int, str]:
        df = self.table
        if search_query:
            if case_sensitive:
                df = df[df.name.str.contains(search_query)]
            else:
                df = df[df.name_lowercase.str.contains(search_query.lower())]
        df = self.filter_table(df, filter_names, data_types)
        result = self.to_html(df, self.table_header)
        return result

    @staticmethod
    def filter_table(df: pd.DataFrame, filter_names: list[str], data_types: list[str]) -> pd.DataFrame:
        df = df.loc[df.Type.isin(set(filter_names))]
        df = df.loc[df.Tags.isin(set(data_types))]
        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;
}
span.svelte-s1r2yt{font-weight: bold !important;
}
"""
with gr.Blocks(css=css) as demo:
        with gr.Row():
            gr.Image(value="RAII.svg",scale=1,show_download_button=False,show_share_button=False,show_label=False,height=100,container=False) 
            gr.Markdown("# Datasets for Healthcare Teams")
        search_box = gr.Textbox( label='Search Name', placeholder='You can search for titles with regular expressions. e.g. (?<!sur)face',max_lines=1)
        case_sensitive = gr.Checkbox(label='Case Sensitive')
        filter_names = gr.CheckboxGroup(choices=['Real Data','Synthetic Data',], value=['Real Data','Synthetic Data',], label='Type')
        data_type_names = ['Claims','Scientific','Corpus',]
        data_types = gr.CheckboxGroup(choices=data_type_names, value=data_type_names, label='Tags')
        search_button = gr.Button('Search')
        table = gr.HTML(show_label=False)
        demo.load(fn=data_list.render, inputs=[search_box, case_sensitive, filter_names, data_types,],outputs=[table,])
        search_box.submit(fn=data_list.render, inputs=[search_box, case_sensitive, filter_names, data_types,], outputs=[table,])
        search_button.click(fn=data_list.render, inputs=[search_box, case_sensitive, filter_names, data_types,], outputs=[table,])    

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