espejelomar's picture
Update app.py
057de0c
import requests
import pandas as pd
import gradio as gr
from huggingface_hub.hf_api import SpaceInfo
path = f"https://huggingface.co/api/spaces"
def get_hugging_learners_spaces():
r = requests.get(path)
d = r.json()
spaces = [SpaceInfo(**x) for x in d]
blocks_spaces = {}
for i in range(0,len(spaces)):
if spaces[i].id.split('/')[0] == 'hugginglearners' and hasattr(spaces[i], 'likes') and spaces[i].id != 'hugginglearners/Hearts_Leaderboard' and spaces[i].id != 'hugginglearners/README':
blocks_spaces[spaces[i].id]=spaces[i].likes
df = pd.DataFrame(
[{"Spaces_Name": Spaces, "likes": likes} for Spaces,likes in blocks_spaces.items()])
df = df.sort_values(by=['likes'],ascending=False)
return df
block = gr.Blocks()
with block:
gr.Markdown("""### Leaderboard of the most popular **fastai X Hugging Face Group** (the Hugging Learners) Spaces""")
gr.Markdown("""Learn more, join and become a Hugging Learner. The instructions are <a href="https://huggingface.co/hugginglearners" target="_blank" style="text-decoration: underline">here.</a>""")
with gr.Tabs():
with gr.TabItem("Leaderboard of spaces with the most hearts"):
with gr.Row():
data = gr.outputs.Dataframe(type="pandas")
with gr.Row():
data_run = gr.Button("Refresh")
data_run.click(get_hugging_learners_spaces, inputs=None, outputs=data)
block.load(get_hugging_learners_spaces, inputs=None, outputs=data)
block.launch()