Spaces:
Running
Running
__all__ = ['block', 'make_clickable_model', 'make_clickable_user', 'get_submissions'] | |
import gradio as gr | |
import pandas as pd | |
from huggingface_hub import HfApi, repocard | |
def is_duplicated(space_id:str)->None: | |
card = repocard.RepoCard.load(space_id, repo_type="space") | |
return getattr(card.data, "duplicated_from", None) is not None | |
def make_clickable_model(model_name, link=None): | |
if link is None: | |
link = "https://huggingface.co/" + "spaces/" + model_name | |
return f'<a target="_blank" href="{link}">{model_name.split("/")[-1]}</a>' | |
def get_space_ids(category): | |
api = HfApi() | |
spaces = api.list_spaces(filter=["keras-dreambooth", category]) | |
print(spaces) | |
space_ids = [x for x in spaces] | |
return space_ids | |
def make_clickable_user(user_id): | |
link = "https://huggingface.co/" + user_id | |
return f'<a target="_blank" href="{link}">{user_id}</a>' | |
def get_submissions(category): | |
submissions = get_space_ids(category) | |
leaderboard_models = [] | |
for submission in submissions: | |
# user, model, likes | |
if not is_duplicated(submission.id): | |
user_id = submission.id.split("/")[0] | |
leaderboard_models.append( | |
( | |
make_clickable_user(user_id), | |
make_clickable_model(submission.id), | |
submission.likes, | |
) | |
) | |
df = pd.DataFrame(data=leaderboard_models, columns=["User", "Space", "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( | |
"""# Keras DreamBooth Leaderboard | |
Welcome to the leaderboard for the Keras DreamBooth Event! This is a community event where participants **personalise a Stable Diffusion model** by fine-tuning it with a powerful technique called [_DreamBooth_](https://arxiv.org/abs/2208.12242). This technique allows one to implant a subject into the output domain of the model such that it can be synthesized with a _unique identifier_ in the prompt. | |
This competition is composed of 4 _themes_, where each theme will collect models belong to one of the categories shown in the tabs below. We'll be **giving out prizes to the top 3 most liked models per theme**, and you're encouraged to submit as many models as you want! | |
""" | |
) | |
with gr.Tabs(): | |
with gr.TabItem("Nature π¨ π³ "): | |
with gr.Row(): | |
nature_data = gr.components.Dataframe( | |
type="pandas", datatype=["number", "markdown", "markdown", "number"] | |
) | |
with gr.Row(): | |
data_run = gr.Button("Refresh") | |
data_run.click( | |
get_submissions, inputs=gr.Variable("nature"), outputs=nature_data | |
) | |
with gr.TabItem("Science Fiction & Fantasy π§ββοΈ π§ββοΈ π€ "): | |
with gr.Row(): | |
scifi_data = gr.components.Dataframe( | |
type="pandas", datatype=["number", "markdown", "markdown", "number"] | |
) | |
with gr.Row(): | |
data_run = gr.Button("Refresh") | |
data_run.click( | |
get_submissions, inputs=gr.Variable("scifi"), outputs=scifi_data | |
) | |
with gr.TabItem("Consentful πΌοΈ π¨ "): | |
with gr.Row(): | |
consentful_data = gr.components.Dataframe( | |
type="pandas", datatype=["number", "markdown", "markdown", "number"] | |
) | |
with gr.Row(): | |
data_run = gr.Button("Refresh") | |
data_run.click( | |
get_submissions, inputs=gr.Variable("consentful"), outputs=consentful_data | |
) | |
with gr.TabItem("Wild Card π"): | |
with gr.Row(): | |
wildcard_data = gr.components.Dataframe( | |
type="pandas", datatype=["number", "markdown", "markdown", "number"] | |
) | |
with gr.Row(): | |
data_run = gr.Button("Refresh") | |
data_run.click( | |
get_submissions, | |
inputs=gr.Variable("wildcard"), | |
outputs=wildcard_data, | |
) | |
block.load(get_submissions, inputs=gr.Variable("nature"), outputs=nature_data) | |
block.load(get_submissions, inputs=gr.Variable("scifi"), outputs=scifi_data) | |
block.load(get_submissions, inputs=gr.Variable("consentful"), outputs=consentful_data) | |
block.load(get_submissions, inputs=gr.Variable("wildcard"), outputs=wildcard_data) | |
block.launch() |