rhea2809 commited on
Commit
7b9b78a
·
1 Parent(s): 4cedf6e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +78 -1
app.py CHANGED
@@ -1,6 +1,83 @@
1
  import gradio as gr
2
  from model_list import ModelList
3
- from data_list import DataList
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
 
6
  def main():
 
1
  import gradio as gr
2
  from model_list import ModelList
3
+
4
+ from __future__ import annotations
5
+
6
+ import numpy as np
7
+ import pandas as pd
8
+ import requests
9
+ from huggingface_hub.hf_api import SpaceInfo
10
+
11
+ SHEET_ID = '1BWKw2ygYQUUPcNdSJhW9OkXILWO5i-dCa5Uahn9dHNo'
12
+ SHEET_NAME = 'Datasets'
13
+ csv_url = f'https://docs.google.com/spreadsheets/d/{SHEET_ID}/gviz/tq?tqx=out:csv&sheet={SHEET_NAME}'
14
+
15
+ class DataList:
16
+ def __init__(self):
17
+ self.table = pd.read_csv(csv_url)
18
+ self.table = self.table.astype({'Year':'string'})
19
+ self._preprocess_table()
20
+
21
+ self.table_header = '''
22
+ <tr>
23
+ <td width="15%">Name</td>
24
+ <td width="10%">URL</td>
25
+ <td width="30%">About</td>
26
+ <td width="15%">Publisher</td>
27
+ <td width="10%">Year Updated</td>
28
+ <td width="10%">Type</td>
29
+ <td width="10%">Tag</td>
30
+ </tr>'''
31
+
32
+ def _preprocess_table(self) -> None:
33
+ self.table['name_lowercase'] = self.table['Name'].str.lower()
34
+
35
+ rows = []
36
+ for row in self.table.itertuples():
37
+ source = f'<a href="{row.URL}" target="_blank">Link</a>' if isinstance(
38
+ row.URL, str) else ''
39
+ row = f'''
40
+ <tr>
41
+ <td>{row.Name}</td>
42
+ <td>{source}</td>
43
+ <td>{row.About}</td>
44
+ <td>{row.Publisher}</td>
45
+ <td>{row.Year}</td>
46
+ <td>{row.Type}</td>
47
+ <td>{row.Tags}</td>
48
+ </tr>'''
49
+ rows.append(row)
50
+ self.table['html_table_content'] = rows
51
+
52
+ def render(self, search_query: str,
53
+ case_sensitive: bool,
54
+ filter_names: list[str],
55
+ data_types: list[str]) -> tuple[int, str]:
56
+ df = self.table
57
+ if search_query:
58
+ if case_sensitive:
59
+ df = df[df.name.str.contains(search_query)]
60
+ else:
61
+ df = df[df.name_lowercase.str.contains(search_query.lower())]
62
+ df = self.filter_table(df, filter_names, data_types)
63
+ result = self.to_html(df, self.table_header)
64
+ return result
65
+
66
+ @staticmethod
67
+ def filter_table(df: pd.DataFrame, filter_names: list[str], data_types: list[str]) -> pd.DataFrame:
68
+ df = df.loc[df.Type.isin(set(filter_names))]
69
+ df = df.loc[df.Tags.isin(set(data_types))]
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
  def main():