Load Gradio space only once at build
The Gradio space below currently reloads everytime it is opened:huggingface.coleaderboard - a Hugging Face Space by gradioDiscover amazing ML apps made by the communityWhat would be the simplest modification to the space to load the leaderboard only once when building the space (& then the Refresh button already there could be used to refresh, but it loads instantly when opened)?
2022-09-30T13:35:36Z
Ah I figured it out below! Just gotta figure out how to leaveblock.load(get_blocks_party_spaces, inputs=None, outputs=data)in the code but hide the progress now? Such that it preloads an old state but then updates behind the scenesimport gradio as gr
import requests
import pandas as pd
from huggingface_hub.REDACTED_TOKEN 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


DATA = get_blocks_party_spaces()

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.components.Dataframe(DATA, type="pandas")
            with gr.Row():
                data_run = gr.Button("Refresh")
                data_run.click(get_blocks_party_spaces, inputs=None, outputs=data)
    # running the function on page load in addition to when the button is clicked
    #block.load(get_blocks_party_spaces, inputs=None, outputs=data)               

block.launch()
2022-10-01T05:24:46Z
Ah can you try settingshow_progress=Falseinblock.load()?
2022-10-02T07:25:40Z
Hmm it does still show the progress bar when doingblock.load(..., show_progress=False). Also it doesn’t seem like it’s a supported kwarg:Gradio Docsgradio/blocks.py at e5a0a5e849e02607a2d5c8ad00e6dd10b550a5b3 · gradio-app/gradio · GitHub
2022-10-07T01:19:53Z
Looks like a bug, then. It should be a quick fix, but would you be able to file an issue here:Sign in to GitHub · GitHub