Spaces:
Runtime error
Runtime error
Update
Browse files- app.py +1 -29
- demo_list.py +63 -16
- style.css +24 -0
app.py
CHANGED
@@ -7,35 +7,8 @@ import pandas as pd
|
|
7 |
|
8 |
from demo_list import DemoList
|
9 |
|
10 |
-
TITLE = "# List of hysts' Spaces"
|
11 |
-
|
12 |
demo_list = DemoList()
|
13 |
|
14 |
-
COLUMN_NAMES = [
|
15 |
-
'title',
|
16 |
-
'arxiv',
|
17 |
-
'likes',
|
18 |
-
'tags',
|
19 |
-
'last_modified',
|
20 |
-
'created',
|
21 |
-
'sdk',
|
22 |
-
'sdk_version',
|
23 |
-
'status',
|
24 |
-
'hardware',
|
25 |
-
]
|
26 |
-
COLUMN_DATATYPES = [
|
27 |
-
'markdown',
|
28 |
-
'markdown',
|
29 |
-
'markdown',
|
30 |
-
'number',
|
31 |
-
'str',
|
32 |
-
'str',
|
33 |
-
'str',
|
34 |
-
'str',
|
35 |
-
'str',
|
36 |
-
'str',
|
37 |
-
'str',
|
38 |
-
]
|
39 |
DEFAULT_COLUMNS = [
|
40 |
'title',
|
41 |
'arxiv',
|
@@ -52,9 +25,8 @@ def update_df() -> pd.DataFrame:
|
|
52 |
|
53 |
|
54 |
with gr.Blocks(css='style.css') as demo:
|
55 |
-
gr.Markdown(TITLE)
|
56 |
df = gr.Dataframe(value=demo_list.df,
|
57 |
-
datatype=
|
58 |
type='pandas')
|
59 |
refresh_button = gr.Button('Refresh')
|
60 |
refresh_button.click(fn=update_df, outputs=df)
|
|
|
7 |
|
8 |
from demo_list import DemoList
|
9 |
|
|
|
|
|
10 |
demo_list = DemoList()
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
DEFAULT_COLUMNS = [
|
13 |
'title',
|
14 |
'arxiv',
|
|
|
25 |
|
26 |
|
27 |
with gr.Blocks(css='style.css') as demo:
|
|
|
28 |
df = gr.Dataframe(value=demo_list.df,
|
29 |
+
datatype=demo_list.column_datatype,
|
30 |
type='pandas')
|
31 |
refresh_button = gr.Button('Refresh')
|
32 |
refresh_button.click(fn=update_df, outputs=df)
|
demo_list.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import copy
|
2 |
import datetime
|
|
|
3 |
import os
|
4 |
import pathlib
|
5 |
|
@@ -14,6 +15,21 @@ HF_TOKEN = os.getenv('HF_TOKEN')
|
|
14 |
|
15 |
|
16 |
class DemoList:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
def __init__(self):
|
18 |
self.api = HfApi(token=HF_TOKEN)
|
19 |
self.data = self.load_data()
|
@@ -32,7 +48,7 @@ class DemoList:
|
|
32 |
card = space_info.cardData
|
33 |
info = data[url]
|
34 |
info['title'] = card['title']
|
35 |
-
info['sdk'] = card['sdk']
|
36 |
info['sdk_version'] = card.get('sdk_version', '')
|
37 |
info['likes'] = space_info.likes
|
38 |
last_modified = datetime.datetime.strptime(
|
@@ -41,8 +57,11 @@ class DemoList:
|
|
41 |
created = datetime.datetime.strptime(info['created'],
|
42 |
'%Y-%m-%d-%H-%M-%S')
|
43 |
info['created'] = created.strftime('%Y/%m/%d %H:%M:%S')
|
44 |
-
info['status'] = space_info.runtime['stage']
|
45 |
-
info['
|
|
|
|
|
|
|
46 |
return data
|
47 |
|
48 |
@staticmethod
|
@@ -67,6 +86,46 @@ class DemoList:
|
|
67 |
tags = sorted(self.data[url].get('tags', []))
|
68 |
return ', '.join(tags)
|
69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
def to_df(self) -> pd.DataFrame:
|
71 |
data = copy.deepcopy(self.data)
|
72 |
for url in list(data):
|
@@ -75,17 +134,5 @@ class DemoList:
|
|
75 |
info['arxiv'] = self.get_arxiv_link(url)
|
76 |
info['github'] = self.get_github_link(url)
|
77 |
info['tags'] = self.get_tag_list(url)
|
78 |
-
df = pd.DataFrame(data).T.loc[:,
|
79 |
-
'title',
|
80 |
-
'arxiv',
|
81 |
-
'github',
|
82 |
-
'likes',
|
83 |
-
'tags',
|
84 |
-
'last_modified',
|
85 |
-
'created',
|
86 |
-
'sdk',
|
87 |
-
'sdk_version',
|
88 |
-
'status',
|
89 |
-
'hardware',
|
90 |
-
]]
|
91 |
return df
|
|
|
1 |
import copy
|
2 |
import datetime
|
3 |
+
import operator
|
4 |
import os
|
5 |
import pathlib
|
6 |
|
|
|
15 |
|
16 |
|
17 |
class DemoList:
|
18 |
+
COLUMN_INFO = [
|
19 |
+
['status', 'markdown'],
|
20 |
+
['title', 'markdown'],
|
21 |
+
['arxiv', 'markdown'],
|
22 |
+
['github', 'markdown'],
|
23 |
+
['likes', 'number'],
|
24 |
+
['tags', 'str'],
|
25 |
+
['last_modified', 'str'],
|
26 |
+
['created', 'str'],
|
27 |
+
['sdk', 'markdown'],
|
28 |
+
['sdk_version', 'str'],
|
29 |
+
['hardware', 'markdown'],
|
30 |
+
['suggested_hardware', 'str'],
|
31 |
+
]
|
32 |
+
|
33 |
def __init__(self):
|
34 |
self.api = HfApi(token=HF_TOKEN)
|
35 |
self.data = self.load_data()
|
|
|
48 |
card = space_info.cardData
|
49 |
info = data[url]
|
50 |
info['title'] = card['title']
|
51 |
+
info['sdk'] = self.colorize_sdk(card['sdk'])
|
52 |
info['sdk_version'] = card.get('sdk_version', '')
|
53 |
info['likes'] = space_info.likes
|
54 |
last_modified = datetime.datetime.strptime(
|
|
|
57 |
created = datetime.datetime.strptime(info['created'],
|
58 |
'%Y-%m-%d-%H-%M-%S')
|
59 |
info['created'] = created.strftime('%Y/%m/%d %H:%M:%S')
|
60 |
+
info['status'] = self.colorize_status(space_info.runtime['stage'])
|
61 |
+
info['suggested_hardware'] = card.get('suggested_hardware', '')
|
62 |
+
info['hardware'] = self.colorize_hardware(
|
63 |
+
space_info.runtime['hardware']['current'],
|
64 |
+
info['suggested_hardware'])
|
65 |
return data
|
66 |
|
67 |
@staticmethod
|
|
|
86 |
tags = sorted(self.data[url].get('tags', []))
|
87 |
return ', '.join(tags)
|
88 |
|
89 |
+
@property
|
90 |
+
def column_names(self):
|
91 |
+
return list(map(operator.itemgetter(0), self.COLUMN_INFO))
|
92 |
+
|
93 |
+
@property
|
94 |
+
def column_datatype(self):
|
95 |
+
return list(map(operator.itemgetter(1), self.COLUMN_INFO))
|
96 |
+
|
97 |
+
def colorize_status(self, status: str) -> str:
|
98 |
+
if status == 'RUNNING':
|
99 |
+
color = 'green'
|
100 |
+
elif status in ['STOPPED', 'PAUSED']:
|
101 |
+
color = 'yellow'
|
102 |
+
elif status in ['RUNTIME_ERROR', 'BUILD_ERROR']:
|
103 |
+
color = 'red'
|
104 |
+
else:
|
105 |
+
color = ''
|
106 |
+
return f'<div class="{color}">{status}</div>'
|
107 |
+
|
108 |
+
def colorize_sdk(self, sdk: str) -> str:
|
109 |
+
if sdk == 'gradio':
|
110 |
+
color = 'orange'
|
111 |
+
elif sdk == 'docker':
|
112 |
+
color = 'cyan'
|
113 |
+
else:
|
114 |
+
color = ''
|
115 |
+
return f'<div class="{color}">{sdk}</div>'
|
116 |
+
|
117 |
+
def colorize_hardware(self, hardware: str | None,
|
118 |
+
suggested_hardware: str) -> str:
|
119 |
+
if hardware is None:
|
120 |
+
return ''
|
121 |
+
if 't4' in hardware or 'a10g' in hardware or 'a100' in hardware:
|
122 |
+
color = 'red'
|
123 |
+
elif suggested_hardware and 'cpu' not in suggested_hardware:
|
124 |
+
color = 'blue'
|
125 |
+
else:
|
126 |
+
return hardware
|
127 |
+
return f'<div class="{color}">{hardware}</div>'
|
128 |
+
|
129 |
def to_df(self) -> pd.DataFrame:
|
130 |
data = copy.deepcopy(self.data)
|
131 |
for url in list(data):
|
|
|
134 |
info['arxiv'] = self.get_arxiv_link(url)
|
135 |
info['github'] = self.get_github_link(url)
|
136 |
info['tags'] = self.get_tag_list(url)
|
137 |
+
df = pd.DataFrame(data).T.loc[:, self.column_names]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
return df
|
style.css
CHANGED
@@ -17,3 +17,27 @@ body a:hover {
|
|
17 |
body a:hover {
|
18 |
text-decoration: underline;
|
19 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
body a:hover {
|
18 |
text-decoration: underline;
|
19 |
}
|
20 |
+
|
21 |
+
div.green {
|
22 |
+
color: green;
|
23 |
+
}
|
24 |
+
|
25 |
+
div.yellow {
|
26 |
+
color: yellow;
|
27 |
+
}
|
28 |
+
|
29 |
+
div.red {
|
30 |
+
color: red;
|
31 |
+
}
|
32 |
+
|
33 |
+
div.blue {
|
34 |
+
color: blue;
|
35 |
+
}
|
36 |
+
|
37 |
+
div.orange {
|
38 |
+
color: orange;
|
39 |
+
}
|
40 |
+
|
41 |
+
div.cyan {
|
42 |
+
color: cyan;
|
43 |
+
}
|