{ "cells": [ { "cell_type": "code", "execution_count": 14, "id": "ae4232b9-fb9f-419a-9992-8481d1de6b61", "metadata": {}, "outputs": [], "source": [ "# |export\n", "import gradio as gr\n", "import pandas as pd\n", "from huggingface_hub import list_models" ] }, { "cell_type": "code", "execution_count": 107, "id": "51d7a652-f6d2-4cee-b787-88fc0fae0acd", "metadata": {}, "outputs": [], "source": [ "# |export\n", "def make_clickable_model(model_name, link=None):\n", " if link is None:\n", " link = \"https://huggingface.co/\" + model_name\n", " # Remove user from model name\n", " return f'{model_name.split(\"/\")[-1]}'\n", "\n", "\n", "def make_clickable_user(user_id):\n", " link = \"https://huggingface.co/\" + user_id\n", " return f'{user_id}'" ] }, { "cell_type": "code", "execution_count": 108, "id": "82d94a98-0e69-4400-9cb1-2e90ef6da519", "metadata": {}, "outputs": [], "source": [ "# |export\n", "def get_submissions(category):\n", " submissions = list_models(filter=[\"dreambooth-hackathon\", category], full=True)\n", " leaderboard_models = []\n", "\n", " for submission in submissions:\n", " # user, model, likes\n", " user_id = submission.id.split(\"/\")[0]\n", " leaderboard_models.append(\n", " (\n", " make_clickable_user(user_id),\n", " make_clickable_model(submission.id),\n", " submission.likes,\n", " )\n", " )\n", "\n", " df = pd.DataFrame(data=leaderboard_models, columns=[\"User\", \"Model\", \"Likes\"])\n", " df.sort_values(by=[\"Likes\"], ascending=False, inplace=True)\n", " df.insert(0, \"Rank\", list(range(1, len(df) + 1)))\n", " return df" ] }, { "cell_type": "code", "execution_count": 117, "id": "7579bfc6-ddf6-444d-ab7e-505734d86e4d", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Running on local URL: http://127.0.0.1:7894\n", "\n", "To create a public link, set `share=True` in `launch()`.\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [] }, "execution_count": 117, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# |export\n", "block = gr.Blocks()\n", "\n", "with block:\n", " gr.Markdown(\n", " \"\"\"# The DreamBooth Hackathon Leaderboard\n", " \n", " 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. \n", " \n", " 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!\n", " \n", " 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).\n", " \"\"\"\n", " )\n", " with gr.Tabs():\n", " with gr.TabItem(\"Animal 🐨\"):\n", " with gr.Row():\n", " animal_data = gr.components.Dataframe(\n", " type=\"pandas\", datatype=[\"number\", \"markdown\", \"markdown\", \"number\"]\n", " )\n", " with gr.Row():\n", " data_run = gr.Button(\"Refresh\")\n", " data_run.click(\n", " get_submissions, inputs=gr.Variable(\"animal\"), outputs=animal_data\n", " )\n", " with gr.TabItem(\"Science 🔬\"):\n", " with gr.Row():\n", " science_data = gr.components.Dataframe(\n", " type=\"pandas\", datatype=[\"number\", \"markdown\", \"markdown\", \"number\"]\n", " )\n", " with gr.Row():\n", " data_run = gr.Button(\"Refresh\")\n", " data_run.click(\n", " get_submissions, inputs=gr.Variable(\"science\"), outputs=science_data\n", " )\n", " with gr.TabItem(\"Food 🍔\"):\n", " with gr.Row():\n", " food_data = gr.components.Dataframe(\n", " type=\"pandas\", datatype=[\"number\", \"markdown\", \"markdown\", \"number\"]\n", " )\n", " with gr.Row():\n", " data_run = gr.Button(\"Refresh\")\n", " data_run.click(\n", " get_submissions, inputs=gr.Variable(\"food\"), outputs=food_data\n", " )\n", " with gr.TabItem(\"Landscape 🏔\"):\n", " with gr.Row():\n", " landscape_data = gr.components.Dataframe(\n", " type=\"pandas\", datatype=[\"number\", \"markdown\", \"markdown\", \"number\"]\n", " )\n", " with gr.Row():\n", " data_run = gr.Button(\"Refresh\")\n", " data_run.click(\n", " get_submissions,\n", " inputs=gr.Variable(\"landscape\"),\n", " outputs=landscape_data,\n", " )\n", " with gr.TabItem(\"Wilcard 🔥\"):\n", " with gr.Row():\n", " wildcard_data = gr.components.Dataframe(\n", " type=\"pandas\", datatype=[\"number\", \"markdown\", \"markdown\", \"number\"]\n", " )\n", " with gr.Row():\n", " data_run = gr.Button(\"Refresh\")\n", " data_run.click(\n", " get_submissions,\n", " inputs=gr.Variable(\"wildcard\"),\n", " outputs=wildcard_data,\n", " )\n", "\n", " block.load(get_submissions, inputs=gr.Variable(\"animal\"), outputs=animal_data)\n", " block.load(get_submissions, inputs=gr.Variable(\"science\"), outputs=science_data)\n", " block.load(get_submissions, inputs=gr.Variable(\"food\"), outputs=food_data)\n", " block.load(get_submissions, inputs=gr.Variable(\"landscape\"), outputs=landscape_data)\n", " block.load(get_submissions, inputs=gr.Variable(\"wildcard\"), outputs=wildcard_data)\n", "\n", "\n", "block.launch()" ] }, { "cell_type": "code", "execution_count": 118, "id": "17ff7d33-0c9a-4ca0-bb7b-ba1661063035", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Closing server running on port: 7894\n" ] } ], "source": [ "block.close()" ] }, { "cell_type": "code", "execution_count": 119, "id": "339fee32-8a83-435d-b882-55b5f0994774", "metadata": {}, "outputs": [], "source": [ "from nbdev.export import nb_export\n", "\n", "nb_export(\"app.ipynb\", lib_path=\".\", name=\"app\")" ] }, { "cell_type": "code", "execution_count": 77, "id": "29f6746e-fbc3-4087-b2d8-46cd1a55e16e", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Writing requirements.txt\n" ] } ], "source": [ "%%writefile requirements.txt\n", "pandas\n", "huggingface_hub" ] }, { "cell_type": "code", "execution_count": null, "id": "63e8d8ea-31cc-4ddc-a08c-d9cbf02a909d", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "hf", "language": "python", "name": "hf" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.13" } }, "nbformat": 4, "nbformat_minor": 5 }