Spaces:
Build error
Build error
| __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", full=True) | |
| 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) |