|
|
|
|
|
|
|
__all__ = ['block', 'make_clickable_model', 'make_clickable_user', 'get_submissions'] |
|
|
|
|
|
import gradio as gr |
|
import pandas as pd |
|
from huggingface_hub import list_models |
|
|
|
from diffusers import StableDiffusionPipeline |
|
|
|
submissions_list = list_models(filter=["dreambooth-hackathon", category], full=True) |
|
spaces_pipeline_load = [submission.id for submission in submissions_list ] |
|
for ids in spaces_pipeline_load: |
|
mydict[ids] = StableDiffusionPipeline.from_pretrained(ids) |
|
|
|
|
|
|
|
|
|
|
|
|
|
def filter_species(species): |
|
return gr.Dropdown.update(choices=species_map[species], value=species_map[species][1]), gr.update(visible=True) |
|
|
|
|
|
def make_clickable_demo(model_name, prompt): |
|
|
|
|
|
|
|
prompt = "a photo of " + ' '.join(model_name.split('/')[-1].split['-']) + str(prompt) |
|
|
|
return gr.Button.update() |
|
|
|
def make_clickable_model(model_name, link=None): |
|
if link is None: |
|
link = "https://huggingface.co/" + model_name |
|
|
|
|
|
prompt = "a photo of " + ' '.join(model_name.split('/')[-1].split['-']) + str(prompt) |
|
pipeline = StableDiffusionPipeline.from_pretrained(model_name) |
|
image_demo = pipeline().images[0] |
|
|
|
|
|
return image_out.Update(value=image_demo, label=model_name.split("/")[-1]) |
|
|
|
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 = list_models(filter=["dreambooth-hackathon", category], full=True) |
|
leaderboard_models = [] |
|
|
|
for submission in submissions: |
|
|
|
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", "Model", "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( |
|
"""# The DreamBooth Hackathon Leaderboard |
|
|
|
Welcome to the leaderboard for the DreamBooth Hackathon! This is a community event where particpants **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 (e.g. your pet or favourite dish) 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 5 _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! |
|
|
|
For details on how to participate, check out the hackathon's guide [here](https://github.com/huggingface/diffusion-models-class/blob/main/hackathon/README.md). |
|
""" |
|
) |
|
with gr.Row(): |
|
prompt_in = gr.Textbox(label="Type in a Prompt. This will be suffixed to 'a photo of <model name>', so prompt accordingly -") |
|
|
|
with gr.Tabs(): |
|
with gr.TabItem("Animal π¨"): |
|
with gr.Row(): |
|
animal_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("animal"), outputs=animal_data |
|
) |
|
|
|
|
|
with gr.TabItem("Science π¬"): |
|
with gr.Row(): |
|
science_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("science"), outputs=science_data |
|
) |
|
with gr.TabItem("Food π"): |
|
with gr.Row(): |
|
food_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("food"), outputs=food_data |
|
) |
|
with gr.TabItem("Landscape π"): |
|
with gr.Row(): |
|
landscape_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("landscape"), |
|
outputs=landscape_data, |
|
) |
|
with gr.TabItem("Wilcard π₯"): |
|
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, |
|
) |
|
|
|
with gr.Row() as your_model_demo : |
|
image_out = gr.Image() |
|
|
|
button_in.click(make_clickable_demo, prompt_in, your_model_demo) |
|
|
|
block.load(get_submissions, inputs=gr.Variable("animal"), outputs=animal_data) |
|
block.load(get_submissions, inputs=gr.Variable("science"), outputs=science_data) |
|
block.load(get_submissions, inputs=gr.Variable("food"), outputs=food_data) |
|
block.load(get_submissions, inputs=gr.Variable("landscape"), outputs=landscape_data) |
|
block.load(get_submissions, inputs=gr.Variable("wildcard"), outputs=wildcard_data) |
|
|
|
|
|
block.launch() |
|
|