{ "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": [ "
" ], "text/plain": [ "" ] }, "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 }