Spaces:
Runtime error
Runtime error
File size: 6,960 Bytes
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 |
{
"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": 71,
"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",
" leaderboard_models.append(\n",
" (\n",
" submission.id.split(\"/\")[0],\n",
" submission.id.split(\"/\")[-1],\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": 74,
"id": "7579bfc6-ddf6-444d-ab7e-505734d86e4d",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/lewtun/miniconda3/envs/hf/lib/python3.8/site-packages/gradio/outputs.py:127: UserWarning: Usage of gradio.outputs is deprecated, and will not be supported in the future, please import your components from gradio.components\n",
" warnings.warn(\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Running on local URL: http://127.0.0.1:7876\n",
"\n",
"To create a public link, set `share=True` in `launch()`.\n"
]
},
{
"data": {
"text/html": [
"<div><iframe src=\"http://127.0.0.1:7876/\" 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": 74,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# |export\n",
"block = gr.Blocks()\n",
"\n",
"with block:\n",
" gr.Markdown(\"hi\")\n",
" with gr.Tabs():\n",
" with gr.TabItem(\"Animal\"):\n",
" with gr.Row():\n",
" animal_data = gr.outputs.Dataframe(type=\"pandas\")\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.outputs.Dataframe(type=\"pandas\")\n",
" with gr.Row():\n",
" data_run = gr.Button(\"Refresh\")\n",
" data_run.click(\n",
" get_submissions, inputs=gr.Variable(\"Animal\"), outputs=science_data\n",
" )\n",
" with gr.TabItem(\"Food\"):\n",
" with gr.Row():\n",
" food_data = gr.outputs.Dataframe(type=\"pandas\")\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.outputs.Dataframe(type=\"pandas\")\n",
" with gr.Row():\n",
" data_run = gr.Button(\"Refresh\")\n",
" data_run.click(\n",
" get_submissions, inputs=gr.Variable(\"Landscape\"), outputs=data\n",
" )\n",
" with gr.TabItem(\"Wilcard\"):\n",
" with gr.Row():\n",
" wildcard_data = gr.outputs.Dataframe(type=\"pandas\")\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": 75,
"id": "17ff7d33-0c9a-4ca0-bb7b-ba1661063035",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Closing server running on port: 7876\n"
]
}
],
"source": [
"block.close()"
]
},
{
"cell_type": "code",
"execution_count": 76,
"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
}
|