rhea2809 commited on
Commit
22f310e
·
1 Parent(s): c6b3e7e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +95 -0
app.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+ import gradio as gr
3
+ import numpy as np
4
+ import pandas as pd
5
+ import requests
6
+ from huggingface_hub.hf_api import SpaceInfo
7
+
8
+ SHEET_ID = '1BWKw2ygYQUUPcNdSJhW9OkXILWO5i-dCa5Uahn9dHNo'
9
+ SHEET_NAME = 'Datasets'
10
+ csv_url = f'https://docs.google.com/spreadsheets/d/{SHEET_ID}/gviz/tq?tqx=out:csv&sheet={SHEET_NAME}'
11
+
12
+ class DataList:
13
+ def __init__(self):
14
+ self.table = pd.read_csv(csv_url)
15
+ self.table = self.table.astype({'Year':'string'})
16
+ self._preprocess_table()
17
+
18
+ self.table_header = '''
19
+ <tr>
20
+ <td width="15%">Name</td>
21
+ <td width="10%">URL</td>
22
+ <td width="30%">About</td>
23
+ <td width="15%">Publisher</td>
24
+ <td width="10%">Year Updated</td>
25
+ <td width="10%">Type</td>
26
+ <td width="10%">Tag</td>
27
+ </tr>'''
28
+
29
+ def _preprocess_table(self) -> None:
30
+ self.table['name_lowercase'] = self.table['Name'].str.lower()
31
+
32
+ rows = []
33
+ for row in self.table.itertuples():
34
+ source = f'<a href="{row.URL}" target="_blank">Link</a>' if isinstance(
35
+ row.URL, str) else ''
36
+ row = f'''
37
+ <tr>
38
+ <td>{row.Name}</td>
39
+ <td>{source}</td>
40
+ <td>{row.About}</td>
41
+ <td>{row.Publisher}</td>
42
+ <td>{row.Year}</td>
43
+ <td>{row.Type}</td>
44
+ <td>{row.Tags}</td>
45
+ </tr>'''
46
+ rows.append(row)
47
+ self.table['html_table_content'] = rows
48
+
49
+ def render(self, search_query: str,
50
+ case_sensitive: bool,
51
+ filter_names: list[str],
52
+ data_types: list[str]) -> tuple[int, str]:
53
+ df = self.table
54
+ if search_query:
55
+ if case_sensitive:
56
+ df = df[df.name.str.contains(search_query)]
57
+ else:
58
+ df = df[df.name_lowercase.str.contains(search_query.lower())]
59
+ df = self.filter_table(df, filter_names, data_types)
60
+ result = self.to_html(df, self.table_header)
61
+ return result
62
+
63
+ @staticmethod
64
+ def filter_table(df: pd.DataFrame, filter_names: list[str], data_types: list[str]) -> pd.DataFrame:
65
+ df = df.loc[df.Type.isin(set(filter_names))]
66
+ df = df.loc[df.Tags.isin(set(data_types))]
67
+ return df
68
+
69
+ @staticmethod
70
+ def to_html(df: pd.DataFrame, table_header: str) -> str:
71
+ table_data = ''.join(df.html_table_content)
72
+ html = f'''
73
+ <table>
74
+ {table_header}
75
+ {table_data}
76
+ </table>'''
77
+ return html
78
+
79
+ data_list = DataList()
80
+ with gr.Blocks() as demo:
81
+ with gr.Row():
82
+ gr.Image(value="RAII.svg",scale=1,show_download_button=False,show_share_button=False,show_label=False,height=100,container=False)
83
+ gr.Markdown("# Datasets for Healthcare Teams")
84
+ search_box = gr.Textbox( label='Search Name', placeholder='You can search for titles with regular expressions. e.g. (?<!sur)face',max_lines=1)
85
+ case_sensitive = gr.Checkbox(label='Case Sensitive')
86
+ filter_names = gr.CheckboxGroup(choices=['Real Data','Synthetic Data',], value=['Real Data','Synthetic Data',], label='Type')
87
+ data_type_names = ['Claims','Scientific','Corpus',]
88
+ data_types = gr.CheckboxGroup(choices=data_type_names, value=data_type_names, label='Tags')
89
+ search_button = gr.Button('Search')
90
+ table = gr.HTML(show_label=False)
91
+ demo.load(fn=data_list.render, inputs=[search_box, case_sensitive, filter_names, data_types,],outputs=[table,])
92
+ search_box.submit(fn=data_list.render, inputs=[search_box, case_sensitive, filter_names, data_types,], outputs=[table,])
93
+ search_button.click(fn=data_list.render, inputs=[search_box, case_sensitive, filter_names, data_types,], outputs=[table,])
94
+ demo.queue()
95
+ demo.launch(share=False)