Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,64 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
-
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from huggingface_hub import list_models, list_datasets, list_spaces
|
3 |
+
import pandas as pd
|
4 |
|
5 |
+
def get_user_stats():
|
6 |
+
users = {}
|
7 |
+
for k, fn in zip(['model', 'dataset', 'space'], [list_models, list_datasets, list_spaces]):
|
8 |
+
for repo in fn(full=True):
|
9 |
+
if repo.author is None:
|
10 |
+
continue
|
11 |
+
|
12 |
+
if repo.author not in users:
|
13 |
+
users[repo.author] = {
|
14 |
+
x: 0 for x in [
|
15 |
+
'model_likes',
|
16 |
+
'num_models',
|
17 |
+
'dataset_likes',
|
18 |
+
'num_datasets',
|
19 |
+
'space_likes',
|
20 |
+
'num_spaces',
|
21 |
+
'total_likes',
|
22 |
+
'total_repos'
|
23 |
+
]
|
24 |
+
}
|
25 |
+
users[repo.author][f"{k}_likes"] += repo.likes
|
26 |
+
users[repo.author][f"num_{k}s"] += 1
|
27 |
+
|
28 |
+
for username, user_stats in users.items():
|
29 |
+
users[username]['total_likes'] += sum([v for k, v in user_stats.items() if "likes" in k])
|
30 |
+
users[username]['total_repos'] += sum([v for k, v in user_stats.items() if "num_" in k])
|
31 |
+
|
32 |
+
for k, v in users.items():
|
33 |
+
users[k] = dict(users[k])
|
34 |
+
|
35 |
+
return users
|
36 |
+
|
37 |
+
def make_clickable_user(user_id):
|
38 |
+
link = "https://huggingface.co/" + user_id
|
39 |
+
return f'<a target="_blank" href="{link}">{user_id}</a>'
|
40 |
|
41 |
+
|
42 |
+
def get_user_stats_df(limit=1000):
|
43 |
+
users = get_user_stats()
|
44 |
+
df = pd.DataFrame([{'username': make_clickable_user(k), **v} for k, v in users.items()])
|
45 |
+
df.sort_values(by=["total_likes"], ascending=False, inplace=True)
|
46 |
+
df.insert(0, "rank", list(range(1, len(df) + 1)))
|
47 |
+
if limit:
|
48 |
+
df = df.head(limit)
|
49 |
+
return df
|
50 |
+
|
51 |
+
df = get_user_stats_df()
|
52 |
+
desc = """
|
53 |
+
# π€ Hugging Face User Stats
|
54 |
+
|
55 |
+
Here are some stats on the top 1000 users/organizations on the Hugging Face Hub.
|
56 |
+
"""
|
57 |
+
with gr.Blocks() as demo:
|
58 |
+
gr.Markdown(desc)
|
59 |
+
data = gr.components.Dataframe(
|
60 |
+
df,
|
61 |
+
type="pandas",
|
62 |
+
datatype=["number", "markdown", "number", "number", "number", "number", "number", "number", "number", "number"],
|
63 |
+
)
|
64 |
demo.launch()
|