Spaces:
Runtime error
Runtime error
Update
Browse files- demo_list.py +14 -37
- style.css +31 -6
demo_list.py
CHANGED
@@ -24,7 +24,7 @@ class DemoList:
|
|
24 |
['created', 'str'],
|
25 |
['sdk', 'markdown'],
|
26 |
['sdk_version', 'str'],
|
27 |
-
['suggested_hardware', '
|
28 |
]
|
29 |
|
30 |
def __init__(self):
|
@@ -45,7 +45,7 @@ class DemoList:
|
|
45 |
card = space_info.cardData
|
46 |
info = data[url]
|
47 |
info['title'] = card['title']
|
48 |
-
info['sdk'] = self.
|
49 |
info['sdk_version'] = card.get('sdk_version', '')
|
50 |
info['likes'] = space_info.likes
|
51 |
last_modified = datetime.datetime.strptime(
|
@@ -54,11 +54,14 @@ class DemoList:
|
|
54 |
created = datetime.datetime.strptime(info['created'],
|
55 |
'%Y-%m-%d-%H-%M-%S')
|
56 |
info['created'] = created.strftime('%Y/%m/%d %H:%M:%S')
|
57 |
-
info['status'] = self.
|
58 |
-
|
59 |
-
info['
|
|
|
|
|
|
|
60 |
space_info.runtime['hardware']['current'],
|
61 |
-
|
62 |
return data
|
63 |
|
64 |
@staticmethod
|
@@ -91,37 +94,11 @@ class DemoList:
|
|
91 |
def column_datatype(self):
|
92 |
return list(map(operator.itemgetter(1), self.COLUMN_INFO))
|
93 |
|
94 |
-
def
|
95 |
-
if
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
elif status in ['RUNTIME_ERROR', 'BUILD_ERROR']:
|
100 |
-
color = 'red'
|
101 |
-
else:
|
102 |
-
color = ''
|
103 |
-
return f'<div class="{color}">{status}</div>'
|
104 |
-
|
105 |
-
def colorize_sdk(self, sdk: str) -> str:
|
106 |
-
if sdk == 'gradio':
|
107 |
-
color = 'orange'
|
108 |
-
elif sdk == 'docker':
|
109 |
-
color = 'deepskyblue'
|
110 |
-
else:
|
111 |
-
color = ''
|
112 |
-
return f'<div class="{color}">{sdk}</div>'
|
113 |
-
|
114 |
-
def colorize_hardware(self, hardware: str | None,
|
115 |
-
suggested_hardware: str) -> str:
|
116 |
-
if hardware is None:
|
117 |
-
return ''
|
118 |
-
if 't4' in hardware or 'a10g' in hardware or 'a100' in hardware:
|
119 |
-
color = 'red'
|
120 |
-
elif suggested_hardware and 'cpu' not in suggested_hardware:
|
121 |
-
color = 'deepskyblue'
|
122 |
-
else:
|
123 |
-
return hardware
|
124 |
-
return f'<div class="{color}">{hardware}</div>'
|
125 |
|
126 |
def to_df(self) -> pd.DataFrame:
|
127 |
data = copy.deepcopy(self.data)
|
|
|
24 |
['created', 'str'],
|
25 |
['sdk', 'markdown'],
|
26 |
['sdk_version', 'str'],
|
27 |
+
['suggested_hardware', 'markdown'],
|
28 |
]
|
29 |
|
30 |
def __init__(self):
|
|
|
45 |
card = space_info.cardData
|
46 |
info = data[url]
|
47 |
info['title'] = card['title']
|
48 |
+
info['sdk'] = self.to_div(card['sdk'], category_name='sdk')
|
49 |
info['sdk_version'] = card.get('sdk_version', '')
|
50 |
info['likes'] = space_info.likes
|
51 |
last_modified = datetime.datetime.strptime(
|
|
|
54 |
created = datetime.datetime.strptime(info['created'],
|
55 |
'%Y-%m-%d-%H-%M-%S')
|
56 |
info['created'] = created.strftime('%Y/%m/%d %H:%M:%S')
|
57 |
+
info['status'] = self.to_div(space_info.runtime['stage'],
|
58 |
+
category_name='status')
|
59 |
+
info['suggested_hardware'] = self.to_div(card.get(
|
60 |
+
'suggested_hardware', ''),
|
61 |
+
category_name='hardware')
|
62 |
+
info['hardware'] = self.to_div(
|
63 |
space_info.runtime['hardware']['current'],
|
64 |
+
category_name='hardware')
|
65 |
return data
|
66 |
|
67 |
@staticmethod
|
|
|
94 |
def column_datatype(self):
|
95 |
return list(map(operator.itemgetter(1), self.COLUMN_INFO))
|
96 |
|
97 |
+
def to_div(self, text: str | None, category_name: str) -> str:
|
98 |
+
if text is None:
|
99 |
+
text = ''
|
100 |
+
class_name = f'{category_name}-{text.lower()}'
|
101 |
+
return f'<div class="{class_name}">{text}</div>'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
|
103 |
def to_df(self) -> pd.DataFrame:
|
104 |
data = copy.deepcopy(self.data)
|
style.css
CHANGED
@@ -18,22 +18,47 @@ body a:hover {
|
|
18 |
text-decoration: underline;
|
19 |
}
|
20 |
|
21 |
-
|
|
|
22 |
color: green;
|
23 |
}
|
24 |
|
25 |
-
div.
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
color: red;
|
27 |
}
|
28 |
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
30 |
color: deepskyblue;
|
31 |
}
|
32 |
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
color: orange;
|
35 |
}
|
36 |
|
37 |
-
div.
|
38 |
-
color:
|
|
|
|
|
|
|
|
|
39 |
}
|
|
|
18 |
text-decoration: underline;
|
19 |
}
|
20 |
|
21 |
+
/* set colors for statuses */
|
22 |
+
div.status-running {
|
23 |
color: green;
|
24 |
}
|
25 |
|
26 |
+
div.status-stopped,
|
27 |
+
div.status-paused {
|
28 |
+
color: orange;
|
29 |
+
}
|
30 |
+
|
31 |
+
div.status-runtime_error,
|
32 |
+
div.status-build_error {
|
33 |
color: red;
|
34 |
}
|
35 |
|
36 |
+
/* set colors for sdks */
|
37 |
+
div.sdk-gradio {
|
38 |
+
color: orange;
|
39 |
+
}
|
40 |
+
|
41 |
+
div.sdk-docker {
|
42 |
color: deepskyblue;
|
43 |
}
|
44 |
|
45 |
+
/* set colors for hardware types */
|
46 |
+
div.hardware-a100-large,
|
47 |
+
div.hardware-zero-a10g,
|
48 |
+
div.hardware-a10g-large,
|
49 |
+
div.hardware-a10g-small {
|
50 |
+
color: red;
|
51 |
+
}
|
52 |
+
|
53 |
+
div.hardware-t4-medium,
|
54 |
+
div.hardware-t4-small {
|
55 |
color: orange;
|
56 |
}
|
57 |
|
58 |
+
div.hardware-cpu-upgrade {
|
59 |
+
color: green;
|
60 |
+
}
|
61 |
+
|
62 |
+
div.hardware-cpu-basic {
|
63 |
+
color: deepskyblue;
|
64 |
}
|