Formatting
Browse files
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 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
24 |
|
25 |
-
|
26 |
|
|
|
27 |
|
28 |
-
|
29 |
|
30 |
-
return df_all_list
|
31 |
|
32 |
def get_most(df_for_most_function):
|
33 |
-
|
34 |
-
|
35 |
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
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 |
-
|
43 |
-
|
|
|
|
|
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 |
-
|
73 |
-
|
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 |
-
|
84 |
num_things = len(df)
|
85 |
sum_info = get_sum(df)
|
86 |
most_info = get_most(df)
|
87 |
|
88 |
if which_one == "models":
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
elif which_one == "datasets":
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
|
118 |
elif which_one == "spaces":
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
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 |
-
|
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 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
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 |
-
|
174 |
-
|
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 |
-
|
182 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
183 |
|
184 |
-
|
|
|
|
|
185 |
|
186 |
-
|
187 |
-
|
188 |
-
|
|
|
189 |
|
190 |
-
|
191 |
-
|
|
|
192 |
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
dataset_df = models_df_to_clickable(dataset_df, columns_to_convert, "datasets")
|
197 |
|
198 |
-
|
199 |
-
|
200 |
|
201 |
-
|
202 |
-
|
203 |
|
204 |
-
|
205 |
-
|
206 |
|
207 |
-
|
208 |
-
|
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()
|