# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb. # %% auto 0 __all__ = ['block', 'make_clickable_model', 'make_clickable_user', 'get_submissions'] # %% app.ipynb 0 import gradio as gr import pandas as pd from huggingface_hub import list_models from diffusers import StableDiffusionPipeline # %% app.ipynb 1 def get_model_list(category): submissions_list = list_models(filter=["dreambooth-hackathon", category], full=True) spaces_pipeline_load = [submission.id for submission in submissions_list ] return gr.Dropdown.update(choices=spaces_pipeline_load , value=spaces_pipeline_load[5]) def get_initial_prompt(model_nm): #a photo of peterj/shbrcky-dog user_model_nm = model_nm.split('/')[-1] if '-' in user_model_nm: prompt = " ".join(user_model_nm.split('-')) else: prompt = user_model_nm return gr.Textbox.update(value="a photo of " + prompt + " ") def make_demo(model_name, prompt): #link=None): #prompt = "a photo of " + ' '.join(model_name.split('/')[-1].split['-']) + str(prompt) pipeline = StableDiffusionPipeline.from_pretrained(model_name) #("ashiqabdulkhader/shiba-dog") #('pharma/sugar-glider') image_demo = pipeline(prompt).images[0] return image_demo #gr.Button.update() def make_clickable_model(model_name, link=None): if link is None: link = "https://huggingface.co/" + model_name # Remove user from model name return f'{model_name.split("/")[-1]}' def make_clickable_user(user_id): link = "https://huggingface.co/" + user_id return f'{user_id}' # %% app.ipynb 2 def get_submissions(category, prompt): submissions = list_models(filter=["dreambooth-hackathon", category], full=True) leaderboard_models = [] for submission in submissions: # user, model, likes user_id = submission.id.split("/")[0] model_nm = submission.id.split("/")[-1] if '-' in model_nm: model_nm = " ".join(model_nm.split('-')) #button_html = get_button() leaderboard_models.append( ( make_clickable_user(user_id), make_clickable_model(submission.id, prompt), submission.likes, #button_html #'a photo of ' + model_nm + " " ) ) 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 # %% app.ipynb 3 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 ', so prompt accordingly -", value="") with gr.Column(): gr.Dropdown(label="Choose a dreamboooth model", value) button_in = gr.Button(label = "Generate Image using this model") image_out = gr.Image() with gr.Tabs(): with gr.TabItem("Animal 🐨"): with gr.Row(): animal_data = gr.components.Dataframe( type="pandas", datatype=["number", "markdown", "markdown", "number","str"], interactive = True ) with gr.Row(): data_run = gr.Button("Refresh") data_run.click( get_submissions, inputs=[gr.Variable("animal"), prompt_in], outputs=animal_data ) with gr.TabItem("Science 🔬"): with gr.Row(): science_data = gr.components.Dataframe( type="pandas", datatype=["number", "markdown", "markdown", "number", "str"], interactive = True ) with gr.Row(): data_run = gr.Button("Refresh") data_run.click( get_submissions, inputs=[gr.Variable("science"), prompt_in], outputs=science_data ) with gr.TabItem("Food 🍔"): with gr.Row(): food_data = gr.components.Dataframe( type="pandas", datatype=["number", "markdown", "markdown", "number", "str"], interactive = True ) with gr.Row(): data_run = gr.Button("Refresh") data_run.click( get_submissions, inputs=[gr.Variable("food"), prompt_in], outputs=food_data ) with gr.TabItem("Landscape 🏔"): with gr.Row(): landscape_data = gr.components.Dataframe( type="pandas", datatype=["number", "markdown", "markdown", "number", "str"], interactive = True ) with gr.Row(): data_run = gr.Button("Refresh") data_run.click( get_submissions, inputs=[gr.Variable("landscape"),prompt_in], outputs=landscape_data, ) with gr.TabItem("Wilcard 🔥"): with gr.Row(): wildcard_data = gr.components.Dataframe( type="pandas", datatype=["number", "markdown", "markdown", "number", "str"], interactive = True ) with gr.Row(): data_run = gr.Button("Refresh") data_run.click( get_submissions, inputs=[gr.Variable("wildcard"),prompt_in], outputs=wildcard_data, ) theme.change(get_model_list, theme, model_list ) model_list.change(get_initial_prompt, model_list, prompt_in ) button_in.click(make_demo, [model_list, prompt_in], image_out) block.load(get_submissions, inputs=[gr.Variable("animal"), prompt_in], outputs=animal_data) block.load(get_submissions, inputs=[gr.Variable("science"), prompt_in], outputs=science_data) block.load(get_submissions, inputs=[gr.Variable("food"), prompt_in], outputs=food_data) block.load(get_submissions, inputs=[gr.Variable("landscape"), prompt_in], outputs=landscape_data) block.load(get_submissions, inputs=[gr.Variable("wildcard"), prompt_in], outputs=wildcard_data) block.launch()