nateraw commited on
Commit
96f798a
β€’
1 Parent(s): 07007aa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -62
app.py CHANGED
@@ -1,67 +1,8 @@
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=100):
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
-
52
- with gr.Blocks() as demo:
53
-
54
- with gr.Row():
55
- data = gr.components.Dataframe(
56
- type="pandas",
57
- datatype=["number", "markdown", "number", "number", "number", "number", "number", "number", "number", "number"],
58
- )
59
- # block.load(get_submissions, inputs=gr.Variable("nature"), outputs=nature_data)
60
- with gr.Row():
61
- btn = gr.Button("Refresh")
62
- btn.click(
63
- get_user_stats_df, inputs=gr.Variable("stats"), outputs=data
64
- )
65
-
66
- demo.load(get_user_stats_df, inputs=gr.Variable("stats"), outputs=data)
67
  demo.launch()
 
1
  import gradio as gr
 
 
2
 
3
+ demo = gr.Blocks()
 
 
 
 
 
4
 
5
+ with demo:
6
+ gr.Markdown("Hi")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  demo.launch()