Weyaxi commited on
Commit
b830cdb
β€’
1 Parent(s): fce74e2

Formatting

Browse files
Files changed (1) hide show
  1. app.py +113 -94
app.py CHANGED
@@ -9,40 +9,47 @@ import gradio as gr
9
 
10
  api = HfApi()
11
 
 
12
  def get_models(org_name, which_one):
13
- all_list = []
14
- if which_one == "models":
15
- things = api.list_models(author=org_name)
16
- elif which_one == "datasets":
17
- things = api.list_datasets(author=org_name)
18
- elif which_one == "spaces":
19
- things = api.list_spaces(author=org_name)
20
 
21
- for i in things:
22
- i = i.__dict__
23
- json_format_data = {"id": i['id'], "downloads": i['downloads'], "likes": i['likes']} if which_one != "spaces" else {"id": i['id'], "downloads": 0, "likes": i['likes']}
 
 
24
 
25
- all_list.append(json_format_data)
26
 
 
27
 
28
- df_all_list = (pd.DataFrame(all_list))
29
 
30
- return df_all_list
31
 
32
  def get_most(df_for_most_function):
33
- download_sorted_df = df_for_most_function.sort_values(by=['downloads'], ascending=False)
34
- most_downloaded = download_sorted_df.iloc[0]
35
 
36
- like_sorted_df = df_for_most_function.sort_values(by=['likes'], ascending=False)
37
- most_liked = like_sorted_df.iloc[0]
 
 
 
 
38
 
39
- return {"Most Download": {"id": most_downloaded['id'], "downloads": most_downloaded['downloads'], "likes": most_downloaded['likes']}, "Most Likes": {"id": most_liked['id'], "downloads": most_liked['downloads'], "likes": most_liked['likes']}}
40
 
41
  def get_sum(df_for_sum_function):
42
- sum_downloads = sum(df_for_sum_function['downloads'].tolist())
43
- sum_likes = sum(df_for_sum_function['likes'].tolist())
 
 
44
 
45
- return {"Downloads": sum_downloads, "Likes": sum_likes}
46
 
47
  def get_openllm_leaderboard():
48
  url = 'https://huggingfaceh4-open-llm-leaderboard.hf.space/'
@@ -67,12 +74,14 @@ def get_openllm_leaderboard():
67
  except (IndexError, AttributeError):
68
  return result_list
69
 
 
70
  def get_ranking(model_list, target_org):
71
  for index, model in enumerate(model_list):
72
- if model.split("/")[0].lower() == target_org.lower():
73
- return [index+1, model]
74
  return "Not Found"
75
 
 
76
  def make_leaderboard(orgs, which_one):
77
  data_rows = []
78
  open_llm_leaderboard = get_openllm_leaderboard() if which_one == "models" else None
@@ -80,64 +89,60 @@ def make_leaderboard(orgs, which_one):
80
  for org in tqdm(orgs, desc=f"Scraping Organizations ({which_one})", position=0, leave=True):
81
  df = get_models(org, which_one)
82
  if len(df) == 0:
83
- continue
84
  num_things = len(df)
85
  sum_info = get_sum(df)
86
  most_info = get_most(df)
87
 
88
  if which_one == "models":
89
- open_llm_leaderboard_get_org = get_ranking(open_llm_leaderboard, org)
90
- data_rows.append({
91
- "Organization Name": org,
92
- "Total Downloads": sum_info["Downloads"],
93
- "Total Likes": sum_info["Likes"],
94
- "Number of Models": num_things,
95
- "Best Model On Open LLM Leaderboard": open_llm_leaderboard_get_org[1] if open_llm_leaderboard_get_org != "Not Found" else open_llm_leaderboard_get_org,
96
- "Best Rank On Open LLM Leaderboard": open_llm_leaderboard_get_org[0] if open_llm_leaderboard_get_org != "Not Found" else open_llm_leaderboard_get_org,
97
- "Average Downloads per Model": int(sum_info["Downloads"] / num_things) if num_things != 0 else 0,
98
- "Average Likes per Model": int(sum_info["Likes"] / num_things) if num_things != 0 else 0,
99
- "Most Downloaded Model": most_info["Most Download"]["id"],
100
- "Most Download Count": most_info["Most Download"]["downloads"],
101
- "Most Liked Model": most_info["Most Likes"]["id"],
102
- "Most Like Count": most_info["Most Likes"]["likes"]
103
- })
104
  elif which_one == "datasets":
105
- data_rows.append({
106
- "Organization Name": org,
107
- "Total Downloads": sum_info["Downloads"],
108
- "Total Likes": sum_info["Likes"],
109
- "Number of Datasets": num_things,
110
- "Average Downloads per Dataset": int(sum_info["Downloads"] / num_things) if num_things != 0 else 0,
111
- "Average Likes per Dataset": int(sum_info["Likes"] / num_things) if num_things != 0 else 0,
112
- "Most Downloaded Dataset": most_info["Most Download"]["id"],
113
- "Most Download Count": most_info["Most Download"]["downloads"],
114
- "Most Liked Dataset": most_info["Most Likes"]["id"],
115
- "Most Like Count": most_info["Most Likes"]["likes"]
116
- })
117
 
118
  elif which_one == "spaces":
119
- data_rows.append({
120
- "Organization Name": org,
121
- "Total Likes": sum_info["Likes"],
122
- "Number of Spaces": num_things,
123
- "Average Likes per Space": int(sum_info["Likes"] / num_things) if num_things != 0 else 0,
124
- "Most Liked Space": most_info["Most Likes"]["id"],
125
- "Most Like Count": most_info["Most Likes"]["likes"]
126
- })
127
 
128
  leaderboard = pd.DataFrame(data_rows)
129
  leaderboard.insert(0, "Serial Number", range(1, len(leaderboard) + 1))
130
  return leaderboard
131
 
132
- """# Gradio başlasın
133
-
134
- """
135
 
136
  with open("org_names.txt", "r") as f:
137
- org_names_in_list = [i.rstrip("\n") for i in f.readlines()]
138
 
139
-
140
- INTRODUCTION_TEXT = f"""
141
  🎯 The Organization Leaderboard aims to track organizations ranking. This space is inspired by [Open LLM Leaderboard](https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard)
142
 
143
  ## Dataframes Available:
@@ -158,53 +163,67 @@ INTRODUCTION_TEXT = f"""
158
 
159
  """
160
 
 
161
  def clickable(x, which_one):
162
  if which_one == "models":
163
- if x != "Not Found":
164
- return f'<a target="_blank" href="https://huggingface.co/{x}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">{x}</a>'
165
- else:
166
- return "Not Found"
167
  else:
168
  return f'<a target="_blank" href="https://huggingface.co/{which_one}/{x}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">{x}</a>'
169
 
 
170
  def models_df_to_clickable(df, columns, which_one):
171
  for column in columns:
172
  if column == "Organization Name":
173
- df[column] = df[column].apply(lambda x: clickable(x, "models"))
174
- else:
175
- df[column] = df[column].apply(lambda x: clickable(x, which_one))
176
  return df
177
 
178
- demo = gr.Blocks()
179
 
180
  with gr.Blocks() as demo:
181
- gr.Markdown("""<h1 align="center" id="space-title">πŸ€— Organization Leaderboard</h1>""")
182
- gr.Markdown(INTRODUCTION_TEXT, elem_classes="markdown-text")
 
 
 
 
 
 
 
 
 
 
 
183
 
184
- with gr.TabItem("πŸ›οΈ Models", id=1):
 
 
185
 
186
- columns_to_convert = ["Organization Name", "Best Model On Open LLM Leaderboard", "Most Downloaded Model", "Most Liked Model"]
187
- models_df = make_leaderboard(org_names_in_list, "models")
188
- models_df = models_df_to_clickable(models_df, columns_to_convert, "models")
 
189
 
190
- headers = ["πŸ”’ Serial Number", "🏒 Organization Name", "πŸ“₯ Total Downloads", "πŸ‘ Total Likes", "πŸ€– Number of Models", "πŸ† Best Model On Open LLM Leaderboard", "πŸ₯‡ Best Rank On Open LLM Leaderboard", "πŸ“Š Average Downloads per Model", "πŸ“ˆ Average Likes per Model", "πŸš€ Most Downloaded Model", "πŸ“ˆ Most Download Count", "❀️ Most Liked Model", "πŸ‘ Most Like Count"]
191
- gr.Dataframe(models_df, headers=headers, interactive=True, datatype=["str", "markdown", "str", "str", "str", "markdown", "str", "str", "str", "markdown", "str", "markdown", "str"])
 
192
 
193
- with gr.TabItem("πŸ“Š Dataset", id=2):
194
- columns_to_convert = ["Organization Name", "Most Downloaded Dataset", "Most Liked Dataset"]
195
- dataset_df = make_leaderboard(org_names_in_list, "datasets")
196
- dataset_df = models_df_to_clickable(dataset_df, columns_to_convert, "datasets")
197
 
198
- headers = ["πŸ”’ Serial Number", "🏒 Organization Name", "πŸ“₯ Total Downloads", "πŸ‘ Total Likes", "πŸ“Š Number of Datasets", "πŸ“Š Average Downloads per Dataset", "πŸ“ˆ Average Likes per Dataset", "πŸš€ Most Downloaded Dataset", "πŸ“ˆ Most Download Count", "❀️ Most Liked Dataset", "πŸ‘ Most Like Count"]
199
- gr.Dataframe(dataset_df, headers=headers, interactive=False, datatype=["str", "markdown", "str", "str", "str", "str", "str", "markdown", "str", "markdown", "str"])
200
 
201
- with gr.TabItem("πŸš€ Spaces", id=3):
202
- columns_to_convert = ["Organization Name", "Most Liked Space"]
203
 
204
- spaces_df = make_leaderboard(org_names_in_list, "spaces")
205
- spaces_df = models_df_to_clickable(spaces_df, columns_to_convert, "spaces")
206
 
207
- headers = ["πŸ”’ Serial Number", "🏒 Organization Name", "πŸ‘ Total Likes", "πŸš€ Number of Spaces", "πŸ“ˆ Average Likes per Space", "❀️ Most Liked Space", "πŸ‘ Most Like Count"]
208
- gr.Dataframe(spaces_df, headers=headers, interactive=False, datatype=["str", "markdown", "str", "str", "str", "markdown", "str"])
209
 
210
- demo.launch()
 
9
 
10
  api = HfApi()
11
 
12
+
13
  def get_models(org_name, which_one):
14
+ all_list = []
15
+ if which_one == "models":
16
+ things = api.list_models(author=org_name)
17
+ elif which_one == "datasets":
18
+ things = api.list_datasets(author=org_name)
19
+ elif which_one == "spaces":
20
+ things = api.list_spaces(author=org_name)
21
 
22
+ for i in things:
23
+ i = i.__dict__
24
+ json_format_data = {"id": i['id'], "downloads": i['downloads'],
25
+ "likes": i['likes']} if which_one != "spaces" else {"id": i['id'], "downloads": 0,
26
+ "likes": i['likes']}
27
 
28
+ all_list.append(json_format_data)
29
 
30
+ df_all_list = (pd.DataFrame(all_list))
31
 
32
+ return df_all_list
33
 
 
34
 
35
  def get_most(df_for_most_function):
36
+ download_sorted_df = df_for_most_function.sort_values(by=['downloads'], ascending=False)
37
+ most_downloaded = download_sorted_df.iloc[0]
38
 
39
+ like_sorted_df = df_for_most_function.sort_values(by=['likes'], ascending=False)
40
+ most_liked = like_sorted_df.iloc[0]
41
+
42
+ return {"Most Download": {"id": most_downloaded['id'], "downloads": most_downloaded['downloads'],
43
+ "likes": most_downloaded['likes']},
44
+ "Most Likes": {"id": most_liked['id'], "downloads": most_liked['downloads'], "likes": most_liked['likes']}}
45
 
 
46
 
47
  def get_sum(df_for_sum_function):
48
+ sum_downloads = sum(df_for_sum_function['downloads'].tolist())
49
+ sum_likes = sum(df_for_sum_function['likes'].tolist())
50
+
51
+ return {"Downloads": sum_downloads, "Likes": sum_likes}
52
 
 
53
 
54
  def get_openllm_leaderboard():
55
  url = 'https://huggingfaceh4-open-llm-leaderboard.hf.space/'
 
74
  except (IndexError, AttributeError):
75
  return result_list
76
 
77
+
78
  def get_ranking(model_list, target_org):
79
  for index, model in enumerate(model_list):
80
+ if model.split("/")[0].lower() == target_org.lower():
81
+ return [index + 1, model]
82
  return "Not Found"
83
 
84
+
85
  def make_leaderboard(orgs, which_one):
86
  data_rows = []
87
  open_llm_leaderboard = get_openllm_leaderboard() if which_one == "models" else None
 
89
  for org in tqdm(orgs, desc=f"Scraping Organizations ({which_one})", position=0, leave=True):
90
  df = get_models(org, which_one)
91
  if len(df) == 0:
92
+ continue
93
  num_things = len(df)
94
  sum_info = get_sum(df)
95
  most_info = get_most(df)
96
 
97
  if which_one == "models":
98
+ open_llm_leaderboard_get_org = get_ranking(open_llm_leaderboard, org)
99
+ data_rows.append({
100
+ "Organization Name": org,
101
+ "Total Downloads": sum_info["Downloads"],
102
+ "Total Likes": sum_info["Likes"],
103
+ "Number of Models": num_things,
104
+ "Best Model On Open LLM Leaderboard": open_llm_leaderboard_get_org[1] if open_llm_leaderboard_get_org != "Not Found" else open_llm_leaderboard_get_org,
105
+ "Best Rank On Open LLM Leaderboard": open_llm_leaderboard_get_org[0] if open_llm_leaderboard_get_org != "Not Found" else open_llm_leaderboard_get_org,
106
+ "Average Downloads per Model": int(sum_info["Downloads"] / num_things) if num_things != 0 else 0,
107
+ "Average Likes per Model": int(sum_info["Likes"] / num_things) if num_things != 0 else 0,
108
+ "Most Downloaded Model": most_info["Most Download"]["id"],
109
+ "Most Download Count": most_info["Most Download"]["downloads"],
110
+ "Most Liked Model": most_info["Most Likes"]["id"],
111
+ "Most Like Count": most_info["Most Likes"]["likes"]
112
+ })
113
  elif which_one == "datasets":
114
+ data_rows.append({
115
+ "Organization Name": org,
116
+ "Total Downloads": sum_info["Downloads"],
117
+ "Total Likes": sum_info["Likes"],
118
+ "Number of Datasets": num_things,
119
+ "Average Downloads per Dataset": int(sum_info["Downloads"] / num_things) if num_things != 0 else 0,
120
+ "Average Likes per Dataset": int(sum_info["Likes"] / num_things) if num_things != 0 else 0,
121
+ "Most Downloaded Dataset": most_info["Most Download"]["id"],
122
+ "Most Download Count": most_info["Most Download"]["downloads"],
123
+ "Most Liked Dataset": most_info["Most Likes"]["id"],
124
+ "Most Like Count": most_info["Most Likes"]["likes"]
125
+ })
126
 
127
  elif which_one == "spaces":
128
+ data_rows.append({
129
+ "Organization Name": org,
130
+ "Total Likes": sum_info["Likes"],
131
+ "Number of Spaces": num_things,
132
+ "Average Likes per Space": int(sum_info["Likes"] / num_things) if num_things != 0 else 0,
133
+ "Most Liked Space": most_info["Most Likes"]["id"],
134
+ "Most Like Count": most_info["Most Likes"]["likes"]
135
+ })
136
 
137
  leaderboard = pd.DataFrame(data_rows)
138
  leaderboard.insert(0, "Serial Number", range(1, len(leaderboard) + 1))
139
  return leaderboard
140
 
 
 
 
141
 
142
  with open("org_names.txt", "r") as f:
143
+ org_names_in_list = [i.rstrip("\n") for i in f.readlines()]
144
 
145
+ markdown_main_text = f"""
 
146
  🎯 The Organization Leaderboard aims to track organizations ranking. This space is inspired by [Open LLM Leaderboard](https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard)
147
 
148
  ## Dataframes Available:
 
163
 
164
  """
165
 
166
+
167
  def clickable(x, which_one):
168
  if which_one == "models":
169
+ if x != "Not Found":
170
+ return f'<a target="_blank" href="https://huggingface.co/{x}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">{x}</a>'
171
+ else:
172
+ return "Not Found"
173
  else:
174
  return f'<a target="_blank" href="https://huggingface.co/{which_one}/{x}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">{x}</a>'
175
 
176
+
177
  def models_df_to_clickable(df, columns, which_one):
178
  for column in columns:
179
  if column == "Organization Name":
180
+ df[column] = df[column].apply(lambda x: clickable(x, "models"))
181
+ df[column] = df[column].apply(lambda x: clickable(x, which_one))
 
182
  return df
183
 
 
184
 
185
  with gr.Blocks() as demo:
186
+ gr.Markdown("""<h1 align="center" id="space-title">πŸ€— Organization Leaderboard</h1>""")
187
+ gr.Markdown(markdown_main_text, elem_classes="markdown-text")
188
+
189
+ with gr.TabItem("πŸ›οΈ Models", id=1):
190
+ columns_to_convert = ["Organization Name", "Best Model On Open LLM Leaderboard", "Most Downloaded Model", "Most Liked Model"]
191
+
192
+ models_df = make_leaderboard(org_names_in_list, "models")
193
+ models_df = models_df_to_clickable(models_df, columns_to_convert, "models")
194
+
195
+ headers = ["πŸ”’ Serial Number", "🏒 Organization Name", "πŸ“₯ Total Downloads", "πŸ‘ Total Likes", "πŸ€– Number of Models",
196
+ "πŸ† Best Model On Open LLM Leaderboard", "πŸ₯‡ Best Rank On Open LLM Leaderboard",
197
+ "πŸ“Š Average Downloads per Model", "πŸ“ˆ Average Likes per Model", "πŸš€ Most Downloaded Model",
198
+ "πŸ“ˆ Most Download Count", "❀ Most Liked Model", "πŸ‘ Most Like Count"]
199
 
200
+ gr.Dataframe(models_df, headers=headers, interactive=True,
201
+ datatype=["str", "markdown", "str", "str", "str", "markdown", "str", "str", "str", "markdown",
202
+ "str", "markdown", "str"])
203
 
204
+ with gr.TabItem("πŸ“Š Dataset", id=2):
205
+ columns_to_convert = ["Organization Name", "Most Downloaded Dataset", "Most Liked Dataset"]
206
+ dataset_df = make_leaderboard(org_names_in_list, "datasets")
207
+ dataset_df = models_df_to_clickable(dataset_df, columns_to_convert, "datasets")
208
 
209
+ headers = ["πŸ”’ Serial Number", "🏒 Organization Name", "πŸ“₯ Total Downloads", "πŸ‘ Total Likes",
210
+ "πŸ“Š Number of Datasets", "πŸ“Š Average Downloads per Dataset", "πŸ“ˆ Average Likes per Dataset",
211
+ "πŸš€ Most Downloaded Dataset", "πŸ“ˆ Most Download Count", "❀ Most Liked Dataset", "πŸ‘ Most Like Count"]
212
 
213
+ gr.Dataframe(dataset_df, headers=headers, interactive=False,
214
+ datatype=["str", "markdown", "str", "str", "str", "str", "str", "markdown", "str", "markdown",
215
+ "str"])
 
216
 
217
+ with gr.TabItem("πŸš€ Spaces", id=3):
218
+ columns_to_convert = ["Organization Name", "Most Liked Space"]
219
 
220
+ spaces_df = make_leaderboard(org_names_in_list, "spaces")
221
+ spaces_df = models_df_to_clickable(spaces_df, columns_to_convert, "spaces")
222
 
223
+ headers = ["πŸ”’ Serial Number", "🏒 Organization Name", "πŸ‘ Total Likes", "πŸš€ Number of Spaces",
224
+ "πŸ“ˆ Average Likes per Space", "❀ Most Liked Space", "πŸ‘ Most Like Count"]
225
 
226
+ gr.Dataframe(spaces_df, headers=headers, interactive=False,
227
+ datatype=["str", "markdown", "str", "str", "str", "markdown", "str"])
228
 
229
+ demo.launch()