File size: 1,428 Bytes
016bf62
 
7842fd7
016bf62
7842fd7
f09650f
016bf62
 
 
7a92a2d
016bf62
 
 
 
 
 
 
da5c16c
016bf62
 
 
ee9d83b
016bf62
 
 
 
 
25d9ef3
097559a
016bf62
ba1db5f
016bf62
 
cdde3f1
016bf62
 
0e5a64e
5a5bea3
3723a1e
434d30e
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
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_blocks_party_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] == 'Gradio-Blocks' and hasattr(spaces[i], 'likes') and spaces[i].id != 'Gradio-Blocks/Leaderboard' and spaces[i].id != 'Gradio-Blocks/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 for the most popular Blocks Event Spaces. To learn more and join, see <a href="https://huggingface.co/Gradio-Blocks" target="_blank" style="text-decoration: underline">Blocks Party Event</a>""")
    with gr.Tabs():
        with gr.TabItem("Blocks Party Leaderboard"):
            with gr.Row():
                data = gr.outputs.Dataframe(type="pandas")
            with gr.Row():
                data_run = gr.Button("Refresh")
                data_run.click(get_blocks_party_spaces, inputs=None, outputs=data)

    block.load(get_blocks_party_spaces, inputs=None, outputs=data)                
block.launch()