Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,35 +3,48 @@ __all__ = ['block', 'make_clickable_model', 'make_clickable_user', 'get_submissi
|
|
3 |
|
4 |
import gradio as gr
|
5 |
import pandas as pd
|
6 |
-
from huggingface_hub import
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
def make_clickable_model(model_name, link=None):
|
9 |
if link is None:
|
10 |
-
link = "https://huggingface.co/" + model_name
|
11 |
-
# Remove user from model name
|
12 |
return f'<a target="_blank" href="{link}">{model_name.split("/")[-1]}</a>'
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
def make_clickable_user(user_id):
|
16 |
link = "https://huggingface.co/" + user_id
|
17 |
return f'<a target="_blank" href="{link}">{user_id}</a>'
|
18 |
|
19 |
-
def get_submissions(
|
20 |
-
submissions =
|
21 |
leaderboard_models = []
|
22 |
|
23 |
for submission in submissions:
|
24 |
# user, model, likes
|
25 |
-
|
26 |
-
|
27 |
-
(
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
31 |
)
|
32 |
-
)
|
33 |
|
34 |
-
df = pd.DataFrame(data=leaderboard_models, columns=["User", "
|
35 |
df.sort_values(by=["Likes"], ascending=False, inplace=True)
|
36 |
df.insert(0, "Rank", list(range(1, len(df) + 1)))
|
37 |
return df
|
|
|
3 |
|
4 |
import gradio as gr
|
5 |
import pandas as pd
|
6 |
+
from huggingface_hub import HfApi, repocard
|
7 |
+
|
8 |
+
def is_duplicated(space_id:str)->None:
|
9 |
+
card = repocard.RepoCard.load(space_id, repo_type="space")
|
10 |
+
return getattr(card.data, "duplicated_from", None) is not None
|
11 |
+
|
12 |
+
|
13 |
|
14 |
def make_clickable_model(model_name, link=None):
|
15 |
if link is None:
|
16 |
+
link = "https://huggingface.co/" + "spaces/" + model_name
|
|
|
17 |
return f'<a target="_blank" href="{link}">{model_name.split("/")[-1]}</a>'
|
18 |
|
19 |
+
def get_space_ids(category):
|
20 |
+
api = HfApi()
|
21 |
+
spaces = api.list_spaces(filter=["keras-dreambooth", category])
|
22 |
+
print(spaces)
|
23 |
+
space_ids = [x for x in spaces]
|
24 |
+
return space_ids
|
25 |
+
|
26 |
|
27 |
def make_clickable_user(user_id):
|
28 |
link = "https://huggingface.co/" + user_id
|
29 |
return f'<a target="_blank" href="{link}">{user_id}</a>'
|
30 |
|
31 |
+
def get_submissions():
|
32 |
+
submissions = get_space_ids(category)
|
33 |
leaderboard_models = []
|
34 |
|
35 |
for submission in submissions:
|
36 |
# user, model, likes
|
37 |
+
if not is_duplicated(submission.id):
|
38 |
+
user_id = submission.id.split("/")[0]
|
39 |
+
leaderboard_models.append(
|
40 |
+
(
|
41 |
+
make_clickable_user(user_id),
|
42 |
+
make_clickable_model(submission.id),
|
43 |
+
submission.likes,
|
44 |
+
)
|
45 |
)
|
|
|
46 |
|
47 |
+
df = pd.DataFrame(data=leaderboard_models, columns=["User", "Space", "Likes"])
|
48 |
df.sort_values(by=["Likes"], ascending=False, inplace=True)
|
49 |
df.insert(0, "Rank", list(range(1, len(df) + 1)))
|
50 |
return df
|