File size: 9,080 Bytes
460fdc7
 
 
 
 
 
 
 
 
7786ff5
460fdc7
 
 
 
 
 
 
7786ff5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
460fdc7
 
 
 
7786ff5
460fdc7
 
 
 
 
 
7786ff5
460fdc7
 
7786ff5
 
460fdc7
 
 
 
 
 
 
 
 
 
 
 
65c5de1
460fdc7
 
 
 
 
 
 
65c5de1
460fdc7
 
 
 
 
 
 
65c5de1
460fdc7
 
 
 
 
 
 
 
 
 
 
 
65c5de1
460fdc7
 
 
 
 
7786ff5
460fdc7
 
 
7786ff5
 
 
f7d481d
 
65c5de1
f7d481d
65c5de1
7786ff5
 
460fdc7
7786ff5
460fdc7
7786ff5
 
 
460fdc7
 
 
75534b8
460fdc7
7786ff5
460fdc7
7786ff5
 
 
460fdc7
 
 
75534b8
460fdc7
7786ff5
460fdc7
7786ff5
 
 
460fdc7
 
 
75534b8
460fdc7
7786ff5
460fdc7
7786ff5
 
 
460fdc7
 
 
7786ff5
 
 
460fdc7
7786ff5
460fdc7
7786ff5
 
 
460fdc7
 
 
 
75534b8
460fdc7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65c5de1
460fdc7
 
 
 
 
 
 
65c5de1
460fdc7
 
 
 
 
 
 
 
 
65c5de1
460fdc7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
{
 "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'<a target=\"_blank\" href=\"{link}\">{model_name.split(\"/\")[-1]}</a>'\n",
    "\n",
    "\n",
    "def make_clickable_user(user_id):\n",
    "    link = \"https://huggingface.co/\" + user_id\n",
    "    return f'<a  target=\"_blank\" href=\"{link}\">{user_id}</a>'"
   ]
  },
  {
   "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": [
       "<div><iframe src=\"http://127.0.0.1:7894/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "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
}