Spaces:
Sleeping
Sleeping
File size: 3,164 Bytes
080c006 ba99d85 080c006 ba99d85 080c006 ba99d85 250f62b 080c006 250f62b a0c78b9 250f62b a0c78b9 250f62b a0c78b9 250f62b 080c006 250f62b f43dd6a 250f62b 080c006 250f62b 080c006 798e27e 080c006 250f62b 080c006 10716ba 080c006 8744612 250f62b 080c006 8744612 080c006 250f62b 080c006 8744612 250f62b 080c006 8744612 080c006 250f62b 080c006 8744612 250f62b 080c006 8744612 080c006 250f62b 080c006 78ec837 |
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 81 82 83 84 85 86 87 88 89 90 |
__all__ = ['block', 'make_clickable_repo', 'get_submissions']
import gradio as gr
import pandas as pd
from huggingface_hub import HfApi
def make_clickable_repo(name, repo_type):
if repo_type == "spaces":
link = "https://huggingface.co/" + "spaces/" + name
elif repo_type == "models":
link = "https://huggingface.co/" + name
else:
link = "https://huggingface.co/" + "datasets/" + name
return f'<a target="_blank" href="{link}">{name.split("/")[-1]}</a>'
def get_repo_ids(repo_type):
api = HfApi()
if repo_type == "spaces":
repos = api.list_spaces(author="hackathon-somos-nlp-2023")
repos = [s for s in repos if s.id not in ["hackathon-somos-nlp-2023/README", "hackathon-somos-nlp-2023/leaderboard"]]
elif repo_type == "models":
repos = api.list_models(author="hackathon-somos-nlp-2023")
else:
repos = api.list_datasets(author="hackathon-somos-nlp-2023")
return repos
def get_submissions(repo_type):
submissions = get_repo_ids(repo_type)
leaderboard = []
for submission in submissions:
leaderboard.append(
(
make_clickable_repo(submission.id, repo_type),
submission.likes,
)
)
df = pd.DataFrame(data=leaderboard, columns=["Repo", "Likes"])
df.sort_values(by=["Likes"], ascending=False, inplace=True)
df.insert(0, "Rank", list(range(1, len(df) + 1)))
return df
block = gr.Blocks()
with block:
gr.Markdown(
"""# Hackathon Somos NLP 2023 Leaderboard
"""
)
with gr.Tabs():
with gr.TabItem("Spaces (ML apps)"):
with gr.Row():
spaces_data = gr.components.Dataframe(
type="pandas", datatype=["number", "markdown", "number"]
)
with gr.Row():
data_run = gr.Button("Refresh")
data_run.click(
get_submissions, inputs=gr.Variable("spaces"), outputs=spaces_data
)
with gr.TabItem("Models"):
with gr.Row():
models_data = gr.components.Dataframe(
type="pandas", datatype=["number", "markdown", "number"]
)
with gr.Row():
data_run = gr.Button("Refresh")
data_run.click(
get_submissions, inputs=gr.Variable("models"), outputs=models_data
)
with gr.TabItem("Datasets"):
with gr.Row():
datasets_data = gr.components.Dataframe(
type="pandas", datatype=["number", "markdown", "number"]
)
with gr.Row():
data_run = gr.Button("Refresh")
data_run.click(
get_submissions, inputs=gr.Variable("datasets"), outputs=datasets_data
)
block.load(get_submissions, inputs=gr.Variable("spaces"), outputs=spaces_data)
block.load(get_submissions, inputs=gr.Variable("models"), outputs=models_data)
block.load(get_submissions, inputs=gr.Variable("datasets"), outputs=datasets_data)
block.launch(debug=True) |