Spaces:
Runtime error
Runtime error
Commit
β’
a4a37cc
1
Parent(s):
11c9032
add ranking section
Browse files- app.py +63 -6
- requirements.in +2 -1
- requirements.txt +2 -0
app.py
CHANGED
@@ -2,11 +2,25 @@ import gradio as gr
|
|
2 |
from huggingface_hub import list_spaces
|
3 |
from cachetools import TTLCache, cached
|
4 |
from toolz import groupby, valmap
|
|
|
|
|
5 |
|
|
|
6 |
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
def get_spaces():
|
9 |
-
return list(list_spaces(full=True
|
10 |
|
11 |
|
12 |
get_spaces() # to warm up the cache
|
@@ -54,6 +68,7 @@ def relative_rank_for_org(org_id, filter_zero=False):
|
|
54 |
org_to_like_dict = create_org_to_like_dict()
|
55 |
return relative_rank(org_to_like_dict, org_id, filter_zero=filter_zero)
|
56 |
|
|
|
57 |
@cached(cache=TTLCache(maxsize=100, ttl=60 * 3))
|
58 |
def rank_space(space_id):
|
59 |
return relative_rank_for_space(space_id)
|
@@ -72,6 +87,36 @@ def rank_space_and_org(space_or_org_id, filter_zero):
|
|
72 |
with {org_rank['num_higher']:,} orgs/users above and {org_rank['num_lower']:,} orgs/users below in the raking of Space likes"""
|
73 |
|
74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
with gr.Blocks() as demo:
|
76 |
gr.HTML("<h1 style='text-align: center;'> 🏆 HuggyRanker 🏆 </h1>")
|
77 |
gr.HTML(
|
@@ -81,17 +126,29 @@ with gr.Blocks() as demo:
|
|
81 |
"""<p style="text-align: center;"><i>Remember likes aren't everything!</i></p>"""
|
82 |
)
|
83 |
gr.Markdown(
|
84 |
-
|
85 |
-
Provide this app with a Space ID or a Username/Organization name to rank by likes."""
|
|
|
86 |
with gr.Row():
|
87 |
-
space_id = gr.Textbox(
|
|
|
|
|
88 |
filter_zero = gr.Radio(
|
89 |
choices=["no", "yes"],
|
90 |
label="Filter out spaces with 0 likes in the ranking?",
|
91 |
value="yes",
|
92 |
)
|
93 |
-
run_btn = gr.Button("
|
94 |
result = gr.Markdown()
|
95 |
run_btn.click(rank_space_and_org, inputs=[space_id, filter_zero], outputs=result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
|
97 |
demo.launch()
|
|
|
2 |
from huggingface_hub import list_spaces
|
3 |
from cachetools import TTLCache, cached
|
4 |
from toolz import groupby, valmap
|
5 |
+
from diskcache import Cache
|
6 |
+
import platform
|
7 |
|
8 |
+
is_macos = platform.system() == "Darwin"
|
9 |
|
10 |
+
if is_macos:
|
11 |
+
cache = Cache("cache")
|
12 |
+
|
13 |
+
def cached_decorator(func):
|
14 |
+
return cache.memoize(typed=True, expire=1)(func)
|
15 |
+
|
16 |
+
else:
|
17 |
+
ttl_cache = TTLCache(maxsize=100, ttl=60 * 10)
|
18 |
+
cached_decorator = cached(cache=ttl_cache)
|
19 |
+
|
20 |
+
|
21 |
+
@cached_decorator
|
22 |
def get_spaces():
|
23 |
+
return list(list_spaces(full=True))
|
24 |
|
25 |
|
26 |
get_spaces() # to warm up the cache
|
|
|
68 |
org_to_like_dict = create_org_to_like_dict()
|
69 |
return relative_rank(org_to_like_dict, org_id, filter_zero=filter_zero)
|
70 |
|
71 |
+
|
72 |
@cached(cache=TTLCache(maxsize=100, ttl=60 * 3))
|
73 |
def rank_space(space_id):
|
74 |
return relative_rank_for_space(space_id)
|
|
|
87 |
with {org_rank['num_higher']:,} orgs/users above and {org_rank['num_lower']:,} orgs/users below in the raking of Space likes"""
|
88 |
|
89 |
|
90 |
+
def get_top_n_orgs_and_users(top_n=100):
|
91 |
+
orgs_to_likes = create_org_to_like_dict()
|
92 |
+
sorted_items = sorted(orgs_to_likes.items(), key=lambda item: item[1], reverse=True)
|
93 |
+
sorted_items = sorted_items[:top_n]
|
94 |
+
return sorted_items
|
95 |
+
|
96 |
+
|
97 |
+
def plot_top_n_orgs_and_users(top_n=100):
|
98 |
+
top_n = get_top_n_orgs_and_users(top_n)
|
99 |
+
return "".join(
|
100 |
+
f"\n- [{org}](https://huggingface.co/{org}) with {likes:,} likes"
|
101 |
+
for org, likes in top_n
|
102 |
+
)
|
103 |
+
|
104 |
+
|
105 |
+
def get_top_n_spaces(top_n=100):
|
106 |
+
orgs_to_likes = create_space_to_like_dict()
|
107 |
+
sorted_items = sorted(orgs_to_likes.items(), key=lambda item: item[1], reverse=True)
|
108 |
+
sorted_items = sorted_items[:top_n]
|
109 |
+
return sorted_items
|
110 |
+
|
111 |
+
|
112 |
+
def plot_top_n_spaces(top_n=100):
|
113 |
+
top_n = get_top_n_spaces(top_n)
|
114 |
+
return "".join(
|
115 |
+
f"\n- [{space}](https://huggingface.co/spaces/{space}) with {likes:,} likes"
|
116 |
+
for space, likes in top_n
|
117 |
+
)
|
118 |
+
|
119 |
+
|
120 |
with gr.Blocks() as demo:
|
121 |
gr.HTML("<h1 style='text-align: center;'> 🏆 HuggyRanker 🏆 </h1>")
|
122 |
gr.HTML(
|
|
|
126 |
"""<p style="text-align: center;"><i>Remember likes aren't everything!</i></p>"""
|
127 |
)
|
128 |
gr.Markdown(
|
129 |
+
"""## Rank Specific Spaces or Orgs
|
130 |
+
Provide this app with a Space ID or a Username/Organization name to rank by likes."""
|
131 |
+
)
|
132 |
with gr.Row():
|
133 |
+
space_id = gr.Textbox(
|
134 |
+
"librarian-bots", max_lines=1, label="Space or user/organization ID"
|
135 |
+
)
|
136 |
filter_zero = gr.Radio(
|
137 |
choices=["no", "yes"],
|
138 |
label="Filter out spaces with 0 likes in the ranking?",
|
139 |
value="yes",
|
140 |
)
|
141 |
+
run_btn = gr.Button("Show ranking for this Space org org/user!", label="Rank Space")
|
142 |
result = gr.Markdown()
|
143 |
run_btn.click(rank_space_and_org, inputs=[space_id, filter_zero], outputs=result)
|
144 |
+
gr.Markdown("## Leaderboard of Top 100 Spaces and Orgs/Users by Likes")
|
145 |
+
with gr.Row():
|
146 |
+
with gr.Accordion("Show rankings for Orgs and Users", open=False):
|
147 |
+
gr.Markdown("""## π₯ Top 100 Orgs and Users by Likes π₯""")
|
148 |
+
ranking_board = gr.Markdown(plot_top_n_orgs_and_users())
|
149 |
+
with gr.Accordion("Show rankings for Spaces", open=False):
|
150 |
+
gr.Markdown("""## π
Top 100 Spaces by Likes π
""")
|
151 |
+
ranking_board = gr.Markdown(plot_top_n_spaces())
|
152 |
+
|
153 |
|
154 |
demo.launch()
|
requirements.in
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
cachetools
|
2 |
gradio
|
3 |
huggingface_hub
|
4 |
-
toolz
|
|
|
|
1 |
cachetools
|
2 |
gradio
|
3 |
huggingface_hub
|
4 |
+
toolz
|
5 |
+
diskcache
|
requirements.txt
CHANGED
@@ -34,6 +34,8 @@ contourpy==1.1.0
|
|
34 |
# via matplotlib
|
35 |
cycler==0.11.0
|
36 |
# via matplotlib
|
|
|
|
|
37 |
fastapi==0.103.1
|
38 |
# via gradio
|
39 |
ffmpy==0.3.1
|
|
|
34 |
# via matplotlib
|
35 |
cycler==0.11.0
|
36 |
# via matplotlib
|
37 |
+
diskcache==5.6.3
|
38 |
+
# via -r requirements.in
|
39 |
fastapi==0.103.1
|
40 |
# via gradio
|
41 |
ffmpy==0.3.1
|