xinchen9 commited on
Commit
ecc41de
1 Parent(s): 0138b9d

[Update]Add line 69-112

Browse files
Files changed (1) hide show
  1. app.py +44 -70
app.py CHANGED
@@ -66,76 +66,50 @@ raw_data = dummydf()
66
  methods = list(set(raw_data['Method']))
67
  metrics = ["Chruch","Parachute","Tench","Garbage Turch","Van Gogh","Violence","Illegal Activity","Nudity"]
68
 
69
- # Searching and filtering
70
- # def update_table(
71
- # hidden_df: pd.DataFrame,
72
- # columns: list,
73
- # type_query: list,
74
- # precision_query: str,
75
- # size_query: list,
76
- # show_deleted: bool,
77
- # query: str,
78
- # ):
79
- # filtered_df = filter_models(hidden_df, type_query, size_query, precision_query, show_deleted)
80
- # filtered_df = filter_queries(query, filtered_df)
81
- # df = select_columns(filtered_df, columns)
82
- # return df
83
-
84
-
85
- # def search_table(df: pd.DataFrame, query: str) -> pd.DataFrame:
86
- # return df[(df[AutoEvalColumn.model.name].str.contains(query, case=False))]
87
-
88
-
89
- # def select_columns(df: pd.DataFrame, columns: list) -> pd.DataFrame:
90
- # always_here_cols = [
91
- # AutoEvalColumn.model_type_symbol.name,
92
- # AutoEvalColumn.model.name,
93
- # ]
94
- # # We use COLS to maintain sorting
95
- # filtered_df = df[
96
- # always_here_cols + [c for c in COLS if c in df.columns and c in columns]
97
- # ]
98
- # return filtered_df
99
-
100
-
101
- # def filter_queries(query: str, filtered_df: pd.DataFrame) -> pd.DataFrame:
102
- # final_df = []
103
- # if query != "":
104
- # queries = [q.strip() for q in query.split(";")]
105
- # for _q in queries:
106
- # _q = _q.strip()
107
- # if _q != "":
108
- # temp_filtered_df = search_table(filtered_df, _q)
109
- # if len(temp_filtered_df) > 0:
110
- # final_df.append(temp_filtered_df)
111
- # if len(final_df) > 0:
112
- # filtered_df = pd.concat(final_df)
113
- # filtered_df = filtered_df.drop_duplicates(
114
- # subset=[AutoEvalColumn.model.name, AutoEvalColumn.precision.name, AutoEvalColumn.revision.name]
115
- # )
116
-
117
- # return filtered_df
118
-
119
-
120
- # def filter_models(
121
- # df: pd.DataFrame, type_query: list, size_query: list, precision_query: list, show_deleted: bool
122
- # ) -> pd.DataFrame:
123
- # # Show all models
124
- # if show_deleted:
125
- # filtered_df = df
126
- # else: # Show only still on the hub models
127
- # filtered_df = df[df[AutoEvalColumn.still_on_hub.name] == True]
128
-
129
- # type_emoji = [t[0] for t in type_query]
130
- # filtered_df = filtered_df.loc[df[AutoEvalColumn.model_type_symbol.name].isin(type_emoji)]
131
- # filtered_df = filtered_df.loc[df[AutoEvalColumn.precision.name].isin(precision_query + ["None"])]
132
-
133
- # numeric_interval = pd.IntervalIndex(sorted([NUMERIC_INTERVALS[s] for s in size_query]))
134
- # params_column = pd.to_numeric(df[AutoEvalColumn.params.name], errors="coerce")
135
- # mask = params_column.apply(lambda x: any(numeric_interval.contains(x)))
136
- # filtered_df = filtered_df.loc[mask]
137
-
138
- # return filtered_df
139
 
140
 
141
  demo = gr.Blocks(css=custom_css)
 
66
  methods = list(set(raw_data['Method']))
67
  metrics = ["Chruch","Parachute","Tench","Garbage Turch","Van Gogh","Violence","Illegal Activity","Nudity"]
68
 
69
+ def update_table(
70
+ hidden_df: pd.DataFrame,
71
+ columns_1: list,
72
+ columns_2: list,
73
+ columns_3: list,
74
+ model1: list,
75
+ ):
76
+
77
+ filtered_df = select_columns(hidden_df, columns_1, columns_2, columns_3)
78
+
79
+ filtered_df = filter_model1(filtered_df, model1)
80
+
81
+ return filtered_df
82
+
83
+
84
+ def select_columns(df: pd.DataFrame, columns_1: list, columns_2: list, columns_3: list) -> pd.DataFrame:
85
+ always_here_cols = ["Method"]
86
+
87
+ # We use COLS to maintain sorting
88
+ all_columns = metrics
89
+
90
+ if (len(columns_1)+len(columns_2) + len(columns_3)) == 0:
91
+ filtered_df = df[
92
+ always_here_cols +
93
+ [c for c in all_columns if c in df.columns]
94
+ ]
95
+
96
+ else:
97
+ filtered_df = df[
98
+ always_here_cols +
99
+ [c for c in all_columns if c in df.columns and (c in columns_1 or c in columns_2 or c in columns_3 ) ]
100
+ ]
101
+
102
+ return filtered_df
103
+
104
+
105
+ def filter_model1(df: pd.DataFrame, model_query: list) -> pd.DataFrame:
106
+ # Show all models
107
+ if len(model_query) == 0:
108
+ return df
109
+
110
+ filtered_df = df
111
+ filtered_df = filtered_df[filtered_df["Method"].isin(model_query)]
112
+ return filtered_df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
 
114
 
115
  demo = gr.Blocks(css=custom_css)