hysts HF staff commited on
Commit
7271587
1 Parent(s): bbf76cb

Change the model search behavior

Browse files
Files changed (1) hide show
  1. app.py +12 -23
app.py CHANGED
@@ -141,27 +141,16 @@ def filter_models(
141
  return filtered_df
142
 
143
 
144
- def search_table(df: pd.DataFrame, query: str) -> pd.DataFrame:
145
- return df[df[AutoEvalColumn.dummy.name].str.contains(query, case=False)]
146
-
147
-
148
- def filter_queries(query: str, filtered_df: pd.DataFrame) -> pd.DataFrame:
149
- """Added by Abishek"""
150
- if not query:
151
- return filtered_df
152
-
153
- final_df = []
154
- queries = [q.strip() for q in query.split(";")]
155
- for _q in queries:
156
- _q = _q.strip()
157
- if _q != "":
158
- temp_filtered_df = search_table(filtered_df, _q)
159
- if len(temp_filtered_df) > 0:
160
- final_df.append(temp_filtered_df)
161
- if len(final_df) > 0:
162
- filtered_df = pd.concat(final_df)
163
- filtered_df = filtered_df.drop_duplicates(subset=AutoEvalColumn.row_id.name)
164
- return filtered_df
165
 
166
 
167
  def select_columns(df: pd.DataFrame, columns: list) -> pd.DataFrame:
@@ -217,8 +206,8 @@ def update_table(
217
  )
218
  print(f"filtered_df shape after filter_models: {filtered_df.shape}")
219
 
220
- filtered_df = filter_queries(query, filtered_df)
221
- print(f"filtered_df shape after filter_queries: {filtered_df.shape}")
222
 
223
  print(
224
  f"Filter applied: query={query}, columns={columns}, type_query={type_query}, precision_query={precision_query}"
 
141
  return filtered_df
142
 
143
 
144
+ def search_model_by_name(df: pd.DataFrame, model_name: str) -> pd.DataFrame:
145
+ return df[df[AutoEvalColumn.dummy.name].str.contains(model_name, case=False)]
146
+
147
+
148
+ def search_models_by_multiple_names(df: pd.DataFrame, search_text: str) -> pd.DataFrame:
149
+ if not search_text:
150
+ return df
151
+ model_names = [name.strip() for name in search_text.split(";")]
152
+ dfs = [search_model_by_name(df, name) for name in model_names if name]
153
+ return pd.concat(dfs).drop_duplicates(subset=AutoEvalColumn.row_id.name)
 
 
 
 
 
 
 
 
 
 
 
154
 
155
 
156
  def select_columns(df: pd.DataFrame, columns: list) -> pd.DataFrame:
 
206
  )
207
  print(f"filtered_df shape after filter_models: {filtered_df.shape}")
208
 
209
+ filtered_df = search_models_by_multiple_names(filtered_df, query)
210
+ print(f"filtered_df shape after search_models_by_multiple_names: {filtered_df.shape}")
211
 
212
  print(
213
  f"Filter applied: query={query}, columns={columns}, type_query={type_query}, precision_query={precision_query}"