Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
louisbrulenaudet
commited on
Commit
•
ade24dd
1
Parent(s):
8cc38c3
Update documentation of the app.py
Browse filesDear Maintainers,
I hope this message finds you well. I wanted to inform you that I have recently added documentation to the codebase.
If you have any feedback or suggestions regarding the documentation or any other aspect of the codebase, please don't hesitate to reach out. Your input is always valued and appreciated.
Thank you for your attention to this matter.
Best regards,
Louis Brulé Naudet
app.py
CHANGED
@@ -42,10 +42,76 @@ from src.tools.plots import (
|
|
42 |
#enable_space_ci()
|
43 |
|
44 |
def restart_space():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
API.restart_space(repo_id=REPO_ID, token=H4_TOKEN)
|
46 |
|
47 |
|
48 |
def init_space():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
try:
|
50 |
print(EVAL_REQUESTS_PATH)
|
51 |
snapshot_download(
|
@@ -102,6 +168,51 @@ def update_table(
|
|
102 |
hide_models: list,
|
103 |
query: str,
|
104 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
filtered_df = filter_models(df=hidden_df, type_query=type_query, size_query=size_query, precision_query=precision_query, hide_models=hide_models)
|
106 |
filtered_df = filter_queries(query, filtered_df)
|
107 |
df = select_columns(filtered_df, columns)
|
@@ -109,15 +220,83 @@ def update_table(
|
|
109 |
|
110 |
|
111 |
def load_query(request: gr.Request): # triggered only once at startup => read query parameter if it exists
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
query = request.query_params.get("query") or ""
|
113 |
return query, query # return one for the "search_bar", one for a hidden component that triggers a reload only if value has changed
|
114 |
|
115 |
|
116 |
def search_table(df: pd.DataFrame, query: str) -> pd.DataFrame:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
return df[(df[AutoEvalColumn.dummy.name].str.contains(query, case=False))]
|
118 |
|
119 |
|
120 |
def select_columns(df: pd.DataFrame, columns: list) -> pd.DataFrame:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
always_here_cols = [c.name for c in fields(AutoEvalColumn) if c.never_hidden]
|
122 |
dummy_col = [AutoEvalColumn.dummy.name]
|
123 |
#AutoEvalColumn.model_type_symbol.name,
|
@@ -131,6 +310,31 @@ def select_columns(df: pd.DataFrame, columns: list) -> pd.DataFrame:
|
|
131 |
|
132 |
def filter_queries(query: str, filtered_df: pd.DataFrame):
|
133 |
"""Added by Abishek"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
final_df = []
|
135 |
if query != "":
|
136 |
queries = [q.strip() for q in query.split(";")]
|
@@ -152,6 +356,43 @@ def filter_queries(query: str, filtered_df: pd.DataFrame):
|
|
152 |
def filter_models(
|
153 |
df: pd.DataFrame, type_query: list, size_query: list, precision_query: list, hide_models: list
|
154 |
) -> pd.DataFrame:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
# Show all models
|
156 |
if "Private or deleted" in hide_models:
|
157 |
filtered_df = df[df[AutoEvalColumn.still_on_hub.name] == True]
|
|
|
42 |
#enable_space_ci()
|
43 |
|
44 |
def restart_space():
|
45 |
+
"""
|
46 |
+
Restarts a Space instance specified by its repository ID.
|
47 |
+
|
48 |
+
This function is used to restart a Space instance within the Hugging Face platform.
|
49 |
+
It requires the repository ID and a valid API token for authentication.
|
50 |
+
|
51 |
+
Parameters as env variables
|
52 |
+
---------------------------
|
53 |
+
repo_id : str
|
54 |
+
The ID of the repository associated with the Space instance to be restarted.
|
55 |
+
|
56 |
+
token : str
|
57 |
+
A valid API token with the necessary permissions to restart the Space.
|
58 |
+
|
59 |
+
Returns
|
60 |
+
-------
|
61 |
+
None
|
62 |
+
This function does not return any value. It simply restarts the specified Space instance.
|
63 |
+
|
64 |
+
Example
|
65 |
+
-------
|
66 |
+
>>> restart_space(repo_id="example_repo_id", token="example_token")
|
67 |
+
"""
|
68 |
API.restart_space(repo_id=REPO_ID, token=H4_TOKEN)
|
69 |
|
70 |
|
71 |
def init_space():
|
72 |
+
"""
|
73 |
+
Initializes the Hugging Face Space environment.
|
74 |
+
|
75 |
+
This function initializes the Hugging Face Space environment by performing the following steps:
|
76 |
+
1. Downloads evaluation requests, dynamic information, and evaluation results.
|
77 |
+
2. Processes the raw data into a leaderboard DataFrame.
|
78 |
+
3. Updates collections with the original DataFrame.
|
79 |
+
4. Creates a plot DataFrame for visualization.
|
80 |
+
5. Retrieves evaluation queue DataFrames.
|
81 |
+
|
82 |
+
Returns
|
83 |
+
-------
|
84 |
+
tuple
|
85 |
+
A tuple containing the following elements:
|
86 |
+
- leaderboard_df : pandas.DataFrame
|
87 |
+
DataFrame containing the leaderboard data.
|
88 |
+
|
89 |
+
- original_df : pandas.DataFrame
|
90 |
+
Original DataFrame obtained from the evaluation results.
|
91 |
+
|
92 |
+
- plot_df : pandas.DataFrame
|
93 |
+
DataFrame suitable for creating plots.
|
94 |
+
|
95 |
+
- finished_eval_queue_df : pandas.DataFrame
|
96 |
+
DataFrame containing finished evaluation queue data.
|
97 |
+
|
98 |
+
- running_eval_queue_df : pandas.DataFrame
|
99 |
+
DataFrame containing running evaluation queue data.
|
100 |
+
|
101 |
+
- pending_eval_queue_df : pandas.DataFrame
|
102 |
+
DataFrame containing pending evaluation queue data.
|
103 |
+
|
104 |
+
Example
|
105 |
+
-------
|
106 |
+
>>> (
|
107 |
+
... leaderboard_df,
|
108 |
+
... original_df,
|
109 |
+
... plot_df,
|
110 |
+
... finished_eval_queue_df,
|
111 |
+
... running_eval_queue_df,
|
112 |
+
... pending_eval_queue_df,
|
113 |
+
... ) = init_space()
|
114 |
+
"""
|
115 |
try:
|
116 |
print(EVAL_REQUESTS_PATH)
|
117 |
snapshot_download(
|
|
|
168 |
hide_models: list,
|
169 |
query: str,
|
170 |
):
|
171 |
+
"""
|
172 |
+
Updates a table DataFrame based on specified criteria.
|
173 |
+
|
174 |
+
This function filters the input DataFrame based on specified criteria and returns a new DataFrame with selected columns.
|
175 |
+
|
176 |
+
Parameters
|
177 |
+
----------
|
178 |
+
hidden_df : pandas.DataFrame
|
179 |
+
The DataFrame to be filtered and updated.
|
180 |
+
|
181 |
+
columns : list
|
182 |
+
List of column names to be included in the updated DataFrame.
|
183 |
+
|
184 |
+
type_query : list
|
185 |
+
List of types to filter models.
|
186 |
+
|
187 |
+
precision_query : str
|
188 |
+
Precision value to filter models.
|
189 |
+
|
190 |
+
size_query : list
|
191 |
+
List of sizes to filter models.
|
192 |
+
|
193 |
+
hide_models : list
|
194 |
+
List of models to be hidden.
|
195 |
+
|
196 |
+
query : str
|
197 |
+
Query string to filter rows in the DataFrame.
|
198 |
+
|
199 |
+
Returns
|
200 |
+
-------
|
201 |
+
updated_df : pandas.DataFrame
|
202 |
+
A DataFrame containing filtered and updated data based on the specified criteria.
|
203 |
+
|
204 |
+
Example
|
205 |
+
-------
|
206 |
+
>>> updated_df = update_table(
|
207 |
+
... hidden_df=original_df,
|
208 |
+
... columns=["Model", "Type", "Precision"],
|
209 |
+
... type_query=["type1", "type2"],
|
210 |
+
... precision_query="high",
|
211 |
+
... size_query=["large"],
|
212 |
+
... hide_models=["model1", "model2"],
|
213 |
+
... query="column1 > 0 and column2 == 'value'",
|
214 |
+
... )
|
215 |
+
"""
|
216 |
filtered_df = filter_models(df=hidden_df, type_query=type_query, size_query=size_query, precision_query=precision_query, hide_models=hide_models)
|
217 |
filtered_df = filter_queries(query, filtered_df)
|
218 |
df = select_columns(filtered_df, columns)
|
|
|
220 |
|
221 |
|
222 |
def load_query(request: gr.Request): # triggered only once at startup => read query parameter if it exists
|
223 |
+
"""
|
224 |
+
Loads a query parameter from a request object.
|
225 |
+
|
226 |
+
It returns the query parameter value for the "search_bar" component and for a hidden component that triggers a reload only if the value has changed.
|
227 |
+
|
228 |
+
Parameters
|
229 |
+
----------
|
230 |
+
request : gr.Request
|
231 |
+
The request object containing query parameters.
|
232 |
+
|
233 |
+
Returns
|
234 |
+
-------
|
235 |
+
tuple
|
236 |
+
A tuple containing two identical query parameter values:
|
237 |
+
- query_search_bar : str
|
238 |
+
The query parameter value for the "search_bar" component.
|
239 |
+
|
240 |
+
- query_hidden : str
|
241 |
+
The query parameter value for a hidden component that triggers a reload only if the value has changed.
|
242 |
+
|
243 |
+
Example
|
244 |
+
-------
|
245 |
+
>>> query_search_bar, query_hidden = load_query(request)
|
246 |
+
"""
|
247 |
query = request.query_params.get("query") or ""
|
248 |
return query, query # return one for the "search_bar", one for a hidden component that triggers a reload only if value has changed
|
249 |
|
250 |
|
251 |
def search_table(df: pd.DataFrame, query: str) -> pd.DataFrame:
|
252 |
+
"""
|
253 |
+
Searches a DataFrame for rows containing a specified query.
|
254 |
+
|
255 |
+
This function filters the input DataFrame based on a specified query and returns a new DataFrame containing rows where the query matches any part of the specified column.
|
256 |
+
|
257 |
+
Parameters
|
258 |
+
----------
|
259 |
+
df : pandas.DataFrame
|
260 |
+
The DataFrame to be searched.
|
261 |
+
|
262 |
+
query : str
|
263 |
+
The query string to search for within the DataFrame.
|
264 |
+
|
265 |
+
Returns
|
266 |
+
-------
|
267 |
+
filtered_df : pandas.DataFrame
|
268 |
+
A DataFrame containing rows where the query matches any part of the specified column.
|
269 |
+
|
270 |
+
Example
|
271 |
+
-------
|
272 |
+
>>> filtered_df = search_table(df=original_df, query="example_query")
|
273 |
+
"""
|
274 |
return df[(df[AutoEvalColumn.dummy.name].str.contains(query, case=False))]
|
275 |
|
276 |
|
277 |
def select_columns(df: pd.DataFrame, columns: list) -> pd.DataFrame:
|
278 |
+
"""
|
279 |
+
Selects specified columns from a DataFrame.
|
280 |
+
|
281 |
+
This function selects specified columns from the input DataFrame and returns a new DataFrame containing only those columns.
|
282 |
+
|
283 |
+
Parameters
|
284 |
+
----------
|
285 |
+
df : pandas.DataFrame
|
286 |
+
The DataFrame from which columns are to be selected.
|
287 |
+
|
288 |
+
columns : list
|
289 |
+
List of column names to be selected from the DataFrame.
|
290 |
+
|
291 |
+
Returns
|
292 |
+
-------
|
293 |
+
filtered_df : pandas.DataFrame
|
294 |
+
A DataFrame containing only the specified columns.
|
295 |
+
|
296 |
+
Example
|
297 |
+
-------
|
298 |
+
>>> filtered_df = select_columns(df=original_df, columns=["column1", "column2", "column3"])
|
299 |
+
"""
|
300 |
always_here_cols = [c.name for c in fields(AutoEvalColumn) if c.never_hidden]
|
301 |
dummy_col = [AutoEvalColumn.dummy.name]
|
302 |
#AutoEvalColumn.model_type_symbol.name,
|
|
|
310 |
|
311 |
def filter_queries(query: str, filtered_df: pd.DataFrame):
|
312 |
"""Added by Abishek"""
|
313 |
+
"""
|
314 |
+
Filters DataFrame rows based on specified query strings.
|
315 |
+
|
316 |
+
This function filters the input DataFrame based on specified query strings and returns a new DataFrame containing rows that match any of the queries.
|
317 |
+
|
318 |
+
Parameters
|
319 |
+
----------
|
320 |
+
query : str
|
321 |
+
The query string containing one or more search queries separated by semicolons (;).
|
322 |
+
|
323 |
+
filtered_df : pandas.DataFrame
|
324 |
+
The DataFrame to be filtered based on the queries.
|
325 |
+
|
326 |
+
Returns
|
327 |
+
-------
|
328 |
+
filtered_df : pandas.DataFrame
|
329 |
+
A DataFrame containing rows that match any of the specified queries.
|
330 |
+
|
331 |
+
Example
|
332 |
+
-------
|
333 |
+
>>> filtered_df = filter_queries(
|
334 |
+
... query="query1; query2; query3",
|
335 |
+
... filtered_df=original_df,
|
336 |
+
... )
|
337 |
+
"""
|
338 |
final_df = []
|
339 |
if query != "":
|
340 |
queries = [q.strip() for q in query.split(";")]
|
|
|
356 |
def filter_models(
|
357 |
df: pd.DataFrame, type_query: list, size_query: list, precision_query: list, hide_models: list
|
358 |
) -> pd.DataFrame:
|
359 |
+
"""
|
360 |
+
Filters DataFrame rows based on specified criteria.
|
361 |
+
|
362 |
+
This function filters the input DataFrame based on specified criteria such as model type, size, precision, and models to hide.
|
363 |
+
|
364 |
+
Parameters
|
365 |
+
----------
|
366 |
+
df : pandas.DataFrame
|
367 |
+
The DataFrame to be filtered.
|
368 |
+
|
369 |
+
type_query : list
|
370 |
+
List of tuples containing model types to include in the filtering. Each tuple consists of a model type abbreviation and its corresponding emoji.
|
371 |
+
|
372 |
+
size_query : list
|
373 |
+
List of size categories to include in the filtering.
|
374 |
+
|
375 |
+
precision_query : list
|
376 |
+
List of precision values to include in the filtering.
|
377 |
+
|
378 |
+
hide_models : list
|
379 |
+
List of model categories to hide from the DataFrame.
|
380 |
+
|
381 |
+
Returns
|
382 |
+
-------
|
383 |
+
filtered_df : pandas.DataFrame
|
384 |
+
A DataFrame containing rows that meet the specified filtering criteria.
|
385 |
+
|
386 |
+
Example
|
387 |
+
-------
|
388 |
+
>>> filtered_df = filter_models(
|
389 |
+
... df=original_df,
|
390 |
+
... type_query=[("Type1", "🔥"), ("Type2", "⭐")],
|
391 |
+
... size_query=["Large", "Medium"],
|
392 |
+
... precision_query=["High", "Medium"],
|
393 |
+
... hide_models=["Private or deleted", "Contains a merge/moerge", "MoE", "Flagged"],
|
394 |
+
... )
|
395 |
+
"""
|
396 |
# Show all models
|
397 |
if "Private or deleted" in hide_models:
|
398 |
filtered_df = df[df[AutoEvalColumn.still_on_hub.name] == True]
|