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