{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [], "toc_visible": true }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" }, "accelerator": "GPU", "gpuClass": "standard", "widgets": { "application/vnd.jupyter.widget-state+json": { "03b5d8d7c0e342edaf1bf8c0dae84706": { "model_module": "@jupyter-widgets/controls", "model_name": "HBoxModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HBoxModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HBoxView", "box_style": "", "children": [ "IPY_MODEL_76d0f00d16204d5e807a1fdde62d2b9f", "IPY_MODEL_85ce2407c68d478c88b238f77919ddd7", "IPY_MODEL_245826af4628483bb74015f45c5e52cf" ], "layout": "IPY_MODEL_4290384c4c8e4ba0929fcfd9c3183861" } }, "76d0f00d16204d5e807a1fdde62d2b9f": { "model_module": "@jupyter-widgets/controls", "model_name": "HTMLModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HTMLModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HTMLView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_6139fd52cac140289bc2f3dfdeb28003", "placeholder": "​", "style": "IPY_MODEL_3c08c26d91574ca1ae9d9738fc0294e0", "value": "100%" } }, "85ce2407c68d478c88b238f77919ddd7": { "model_module": "@jupyter-widgets/controls", "model_name": "FloatProgressModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "FloatProgressModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "ProgressView", "bar_style": "success", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_1cf6d579c80a481d87ca48651bf14aed", "max": 46830571, "min": 0, "orientation": "horizontal", "style": "IPY_MODEL_d7916a66c6c74f38a78ac8ae5b45521a", "value": 46830571 } }, "245826af4628483bb74015f45c5e52cf": { "model_module": "@jupyter-widgets/controls", "model_name": "HTMLModel", "model_module_version": "1.5.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HTMLModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HTMLView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_81f3a190007c4d099b6c8973aaaa7023", "placeholder": "​", "style": "IPY_MODEL_334cea03105d4886ac4e689c907dd543", "value": " 44.7M/44.7M [00:01<00:00, 31.3MB/s]" } }, "4290384c4c8e4ba0929fcfd9c3183861": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "model_module_version": "1.2.0", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "6139fd52cac140289bc2f3dfdeb28003": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "model_module_version": "1.2.0", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "3c08c26d91574ca1ae9d9738fc0294e0": { "model_module": "@jupyter-widgets/controls", "model_name": "DescriptionStyleModel", "model_module_version": "1.5.0", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "DescriptionStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "description_width": "" } }, "1cf6d579c80a481d87ca48651bf14aed": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "model_module_version": "1.2.0", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "d7916a66c6c74f38a78ac8ae5b45521a": { "model_module": "@jupyter-widgets/controls", "model_name": "ProgressStyleModel", "model_module_version": "1.5.0", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "ProgressStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "bar_color": null, "description_width": "" } }, "81f3a190007c4d099b6c8973aaaa7023": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "model_module_version": "1.2.0", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "334cea03105d4886ac4e689c907dd543": { "model_module": "@jupyter-widgets/controls", "model_name": "DescriptionStyleModel", "model_module_version": "1.5.0", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "DescriptionStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "description_width": "" } } } } }, "cells": [ { "cell_type": "markdown", "source": [ "## GPU Check" ], "metadata": { "id": "abRNUshGkERl" } }, { "cell_type": "code", "source": [ "gpu_info = !nvidia-smi\n", "gpu_info = '\\n'.join(gpu_info)\n", "if gpu_info.find('failed') >= 0:\n", " print('Not connected to a GPU')\n", "else:\n", " print(gpu_info)" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "Bj3utd9hhu6h", "outputId": "3894d68e-f235-4dd6-e837-41139675fe5a" }, "execution_count": 1, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Sat Oct 29 16:15:38 2022 \n", "+-----------------------------------------------------------------------------+\n", "| NVIDIA-SMI 460.32.03 Driver Version: 460.32.03 CUDA Version: 11.2 |\n", "|-------------------------------+----------------------+----------------------+\n", "| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |\n", "| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |\n", "| | | MIG M. |\n", "|===============================+======================+======================|\n", "| 0 Tesla T4 Off | 00000000:00:04.0 Off | 0 |\n", "| N/A 60C P8 10W / 70W | 0MiB / 15109MiB | 0% Default |\n", "| | | N/A |\n", "+-------------------------------+----------------------+----------------------+\n", " \n", "+-----------------------------------------------------------------------------+\n", "| Processes: |\n", "| GPU GI CI PID Type Process name GPU Memory |\n", "| ID ID Usage |\n", "|=============================================================================|\n", "| No running processes found |\n", "+-----------------------------------------------------------------------------+\n" ] } ] }, { "cell_type": "markdown", "source": [ "## Install Gradio" ], "metadata": { "id": "7onhw0j5kJbd" } }, { "cell_type": "code", "source": [ "! pip install gradio" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "1Pf-ER3Uiv9l", "outputId": "fe730240-d327-4d78-b80e-7f2f77feed73" }, "execution_count": 7, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n", "Collecting gradio\n", " Downloading gradio-3.8-py3-none-any.whl (11.6 MB)\n", "\u001b[K |████████████████████████████████| 11.6 MB 13.9 MB/s \n", "\u001b[?25hCollecting pydub\n", " Downloading pydub-0.25.1-py2.py3-none-any.whl (32 kB)\n", "Collecting paramiko\n", " Downloading paramiko-2.11.0-py2.py3-none-any.whl (212 kB)\n", "\u001b[K |████████████████████████████████| 212 kB 62.2 MB/s \n", "\u001b[?25hRequirement already satisfied: pillow in /usr/local/lib/python3.7/dist-packages (from gradio) (7.1.2)\n", "Requirement already satisfied: pydantic in /usr/local/lib/python3.7/dist-packages (from gradio) (1.10.2)\n", "Collecting h11<0.13,>=0.11\n", " Downloading h11-0.12.0-py3-none-any.whl (54 kB)\n", "\u001b[K |████████████████████████████████| 54 kB 4.0 MB/s \n", "\u001b[?25hRequirement already satisfied: jinja2 in /usr/local/lib/python3.7/dist-packages (from gradio) (2.11.3)\n", "Collecting httpx\n", " Downloading httpx-0.23.0-py3-none-any.whl (84 kB)\n", "\u001b[K |████████████████████████████████| 84 kB 3.9 MB/s \n", "\u001b[?25hCollecting websockets\n", " Downloading websockets-10.4-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (106 kB)\n", "\u001b[K |████████████████████████████████| 106 kB 67.4 MB/s \n", "\u001b[?25hRequirement already satisfied: aiohttp in /usr/local/lib/python3.7/dist-packages (from gradio) (3.8.3)\n", "Requirement already satisfied: matplotlib in /usr/local/lib/python3.7/dist-packages (from gradio) (3.2.2)\n", "Requirement already satisfied: pandas in /usr/local/lib/python3.7/dist-packages (from gradio) (1.3.5)\n", "Collecting uvicorn\n", " Downloading uvicorn-0.19.0-py3-none-any.whl (56 kB)\n", "\u001b[K |████████████████████████████████| 56 kB 5.5 MB/s \n", "\u001b[?25hRequirement already satisfied: pyyaml in /usr/local/lib/python3.7/dist-packages (from gradio) (6.0)\n", "Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from gradio) (1.21.6)\n", "Collecting fastapi\n", " Downloading fastapi-0.85.1-py3-none-any.whl (55 kB)\n", "\u001b[K |████████████████████████████████| 55 kB 4.0 MB/s \n", "\u001b[?25hCollecting ffmpy\n", " Downloading ffmpy-0.3.0.tar.gz (4.8 kB)\n", "Collecting python-multipart\n", " Downloading python-multipart-0.0.5.tar.gz (32 kB)\n", "Requirement already satisfied: fsspec in /usr/local/lib/python3.7/dist-packages (from gradio) (2022.10.0)\n", "Collecting pycryptodome\n", " Downloading pycryptodome-3.15.0-cp35-abi3-manylinux2010_x86_64.whl (2.3 MB)\n", "\u001b[K |████████████████████████████████| 2.3 MB 49.5 MB/s \n", "\u001b[?25hCollecting markdown-it-py[linkify,plugins]\n", " Downloading markdown_it_py-2.1.0-py3-none-any.whl (84 kB)\n", "\u001b[K |████████████████████████████████| 84 kB 3.6 MB/s \n", "\u001b[?25hRequirement already satisfied: requests in /usr/local/lib/python3.7/dist-packages (from gradio) (2.23.0)\n", "Collecting orjson\n", " Downloading orjson-3.8.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (272 kB)\n", "\u001b[K |████████████████████████████████| 272 kB 67.4 MB/s \n", "\u001b[?25hRequirement already satisfied: charset-normalizer<3.0,>=2.0 in /usr/local/lib/python3.7/dist-packages (from aiohttp->gradio) (2.1.1)\n", "Requirement already satisfied: asynctest==0.13.0 in /usr/local/lib/python3.7/dist-packages (from aiohttp->gradio) (0.13.0)\n", "Requirement already satisfied: async-timeout<5.0,>=4.0.0a3 in /usr/local/lib/python3.7/dist-packages (from aiohttp->gradio) (4.0.2)\n", "Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.7/dist-packages (from aiohttp->gradio) (22.1.0)\n", "Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.7/dist-packages (from aiohttp->gradio) (6.0.2)\n", "Requirement already satisfied: yarl<2.0,>=1.0 in /usr/local/lib/python3.7/dist-packages (from aiohttp->gradio) (1.8.1)\n", "Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.7/dist-packages (from aiohttp->gradio) (1.2.0)\n", "Requirement already satisfied: typing-extensions>=3.7.4 in /usr/local/lib/python3.7/dist-packages (from aiohttp->gradio) (4.1.1)\n", "Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.7/dist-packages (from aiohttp->gradio) (1.3.1)\n", "Requirement already satisfied: idna>=2.0 in /usr/local/lib/python3.7/dist-packages (from yarl<2.0,>=1.0->aiohttp->gradio) (2.10)\n", "Collecting starlette==0.20.4\n", " Downloading starlette-0.20.4-py3-none-any.whl (63 kB)\n", "\u001b[K |████████████████████████████████| 63 kB 2.4 MB/s \n", "\u001b[?25hCollecting anyio<5,>=3.4.0\n", " Downloading anyio-3.6.2-py3-none-any.whl (80 kB)\n", "\u001b[K |████████████████████████████████| 80 kB 10.2 MB/s \n", "\u001b[?25hCollecting sniffio>=1.1\n", " Downloading sniffio-1.3.0-py3-none-any.whl (10 kB)\n", "Collecting rfc3986[idna2008]<2,>=1.3\n", " Downloading rfc3986-1.5.0-py2.py3-none-any.whl (31 kB)\n", "Requirement already satisfied: certifi in /usr/local/lib/python3.7/dist-packages (from httpx->gradio) (2022.9.24)\n", "Collecting httpcore<0.16.0,>=0.15.0\n", " Downloading httpcore-0.15.0-py3-none-any.whl (68 kB)\n", "\u001b[K |████████████████████████████████| 68 kB 7.0 MB/s \n", "\u001b[?25hRequirement already satisfied: MarkupSafe>=0.23 in /usr/local/lib/python3.7/dist-packages (from jinja2->gradio) (2.0.1)\n", "Collecting mdurl~=0.1\n", " Downloading mdurl-0.1.2-py3-none-any.whl (10.0 kB)\n", "Collecting mdit-py-plugins\n", " Downloading mdit_py_plugins-0.3.1-py3-none-any.whl (46 kB)\n", "\u001b[K |████████████████████████████████| 46 kB 4.4 MB/s \n", "\u001b[?25hCollecting linkify-it-py~=1.0\n", " Downloading linkify_it_py-1.0.3-py3-none-any.whl (19 kB)\n", "Collecting uc-micro-py\n", " Downloading uc_micro_py-1.0.1-py3-none-any.whl (6.2 kB)\n", "Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->gradio) (1.4.4)\n", "Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->gradio) (2.8.2)\n", "Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->gradio) (3.0.9)\n", "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.7/dist-packages (from matplotlib->gradio) (0.11.0)\n", "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.7/dist-packages (from python-dateutil>=2.1->matplotlib->gradio) (1.15.0)\n", "Requirement already satisfied: pytz>=2017.3 in /usr/local/lib/python3.7/dist-packages (from pandas->gradio) (2022.5)\n", "Collecting bcrypt>=3.1.3\n", " Downloading bcrypt-4.0.1-cp36-abi3-manylinux_2_24_x86_64.whl (593 kB)\n", "\u001b[K |████████████████████████████████| 593 kB 63.1 MB/s \n", "\u001b[?25hCollecting cryptography>=2.5\n", " Downloading cryptography-38.0.1-cp36-abi3-manylinux_2_24_x86_64.whl (4.0 MB)\n", "\u001b[K |████████████████████████████████| 4.0 MB 50.5 MB/s \n", "\u001b[?25hCollecting pynacl>=1.0.1\n", " Downloading PyNaCl-1.5.0-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl (856 kB)\n", "\u001b[K |████████████████████████████████| 856 kB 59.6 MB/s \n", "\u001b[?25hRequirement already satisfied: cffi>=1.12 in /usr/local/lib/python3.7/dist-packages (from cryptography>=2.5->paramiko->gradio) (1.15.1)\n", "Requirement already satisfied: pycparser in /usr/local/lib/python3.7/dist-packages (from cffi>=1.12->cryptography>=2.5->paramiko->gradio) (2.21)\n", "Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests->gradio) (1.24.3)\n", "Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests->gradio) (3.0.4)\n", "Requirement already satisfied: click>=7.0 in /usr/local/lib/python3.7/dist-packages (from uvicorn->gradio) (7.1.2)\n", "Building wheels for collected packages: ffmpy, python-multipart\n", " Building wheel for ffmpy (setup.py) ... \u001b[?25l\u001b[?25hdone\n", " Created wheel for ffmpy: filename=ffmpy-0.3.0-py3-none-any.whl size=4712 sha256=30a69bb5c2b13d3f226683651d6c7e566842a49c9e840811e091e85f33d3cb6d\n", " Stored in directory: /root/.cache/pip/wheels/13/e4/6c/e8059816e86796a597c6e6b0d4c880630f51a1fcfa0befd5e6\n", " Building wheel for python-multipart (setup.py) ... \u001b[?25l\u001b[?25hdone\n", " Created wheel for python-multipart: filename=python_multipart-0.0.5-py3-none-any.whl size=31678 sha256=9cc4b9d0bfff456225d6cd5b036cc098475e4d97b6e6cf941c0552a6fc62ad0c\n", " Stored in directory: /root/.cache/pip/wheels/2c/41/7c/bfd1c180534ffdcc0972f78c5758f89881602175d48a8bcd2c\n", "Successfully built ffmpy python-multipart\n", "Installing collected packages: sniffio, mdurl, uc-micro-py, rfc3986, markdown-it-py, h11, anyio, starlette, pynacl, mdit-py-plugins, linkify-it-py, httpcore, cryptography, bcrypt, websockets, uvicorn, python-multipart, pydub, pycryptodome, paramiko, orjson, httpx, ffmpy, fastapi, gradio\n", "Successfully installed anyio-3.6.2 bcrypt-4.0.1 cryptography-38.0.1 fastapi-0.85.1 ffmpy-0.3.0 gradio-3.8 h11-0.12.0 httpcore-0.15.0 httpx-0.23.0 linkify-it-py-1.0.3 markdown-it-py-2.1.0 mdit-py-plugins-0.3.1 mdurl-0.1.2 orjson-3.8.1 paramiko-2.11.0 pycryptodome-3.15.0 pydub-0.25.1 pynacl-1.5.0 python-multipart-0.0.5 rfc3986-1.5.0 sniffio-1.3.0 starlette-0.20.4 uc-micro-py-1.0.1 uvicorn-0.19.0 websockets-10.4\n" ] } ] }, { "cell_type": "markdown", "source": [ "## Aggregate, process, clean, label, and version data" ], "metadata": { "id": "6PtjDSNMk39S" } }, { "cell_type": "code", "execution_count": 2, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 303, "referenced_widgets": [ "03b5d8d7c0e342edaf1bf8c0dae84706", "76d0f00d16204d5e807a1fdde62d2b9f", "85ce2407c68d478c88b238f77919ddd7", "245826af4628483bb74015f45c5e52cf", "4290384c4c8e4ba0929fcfd9c3183861", "6139fd52cac140289bc2f3dfdeb28003", "3c08c26d91574ca1ae9d9738fc0294e0", "1cf6d579c80a481d87ca48651bf14aed", "d7916a66c6c74f38a78ac8ae5b45521a", "81f3a190007c4d099b6c8973aaaa7023", "334cea03105d4886ac4e689c907dd543" ] }, "id": "FD1OBFNshXD3", "outputId": "aca8824c-aac5-4e49-910c-1da414b3fe27" }, "outputs": [ { "output_type": "display_data", "data": { "text/plain": [ "" ], "text/html": [ "\n", "\n" ] }, "metadata": {} }, { "output_type": "display_data", "data": { "text/plain": [ "" ], "text/html": [ "\n", "
\n", " \n", " 100.00% [811712512/811706944 00:24<00:00]\n", "
\n", " " ] }, "metadata": {} }, { "output_type": "stream", "name": "stderr", "text": [ "/usr/local/lib/python3.7/dist-packages/torchvision/models/_utils.py:209: UserWarning: The parameter 'pretrained' is deprecated since 0.13 and will be removed in 0.15, please use 'weights' instead.\n", " f\"The parameter '{pretrained_param}' is deprecated since 0.13 and will be removed in 0.15, \"\n", "/usr/local/lib/python3.7/dist-packages/torchvision/models/_utils.py:223: UserWarning: Arguments other than a weight enum or `None` for 'weights' are deprecated since 0.13 and will be removed in 0.15. The current behavior is equivalent to passing `weights=ResNet18_Weights.IMAGENET1K_V1`. You can also use `weights=ResNet18_Weights.DEFAULT` to get the most up-to-date weights.\n", " warnings.warn(msg)\n", "Downloading: \"https://download.pytorch.org/models/resnet18-f37072fd.pth\" to /root/.cache/torch/hub/checkpoints/resnet18-f37072fd.pth\n" ] }, { "output_type": "display_data", "data": { "text/plain": [ " 0%| | 0.00/44.7M [00:00" ], "text/html": [ "\n", "\n" ] }, "metadata": {} }, { "output_type": "display_data", "data": { "text/plain": [ "" ], "text/html": [ "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
epochtrain_lossvalid_losserror_ratetime
00.2130080.0403200.01082500:55
" ] }, "metadata": {} }, { "output_type": "display_data", "data": { "text/plain": [ "" ], "text/html": [ "\n", "\n" ] }, "metadata": {} }, { "output_type": "display_data", "data": { "text/plain": [ "" ], "text/html": [ "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
epochtrain_lossvalid_losserror_ratetime
00.0705590.0338510.01082500:53
" ] }, "metadata": {} } ], "source": [ "from fastai.vision.all import *\n", "path = untar_data(URLs.PETS)\n", "files = get_image_files(path/\"images\")\n", "def is_cat(x): return x[0].isupper() \n", "dls = ImageDataLoaders.from_name_func(\n", " path,\n", " files,\n", " pat='(.+)_\\d+.jpg',\n", " splitter=RandomSplitter(valid_pct=0.2, seed=42),\n", " label_func=is_cat, \n", " item_tfms=Resize(192),\n", " batch_tfms=aug_transforms(size=224, min_scale=0.75))" ] }, { "cell_type": "markdown", "source": [ "## Find model arch and weights / Write and debug model code" ], "metadata": { "id": "_17JIq8glHTs" } }, { "cell_type": "code", "source": [ "learn = vision_learner(dls, resnet18, metrics=error_rate)\n", "learn.fine_tune(1)\n", "learn.path = Path('.')\n", "learn.export('model.pkl')" ], "metadata": { "id": "YwdkNpnak2T0" }, "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "source": [ "## Deploy model" ], "metadata": { "id": "RBxVHB9jlTGj" } }, { "cell_type": "code", "source": [ "learn = load_learner('model.pkl')" ], "metadata": { "id": "wWaLAeHUhZ3A" }, "execution_count": 3, "outputs": [] }, { "cell_type": "code", "source": [ "categories = ('Dog', 'Cat')" ], "metadata": { "id": "YKRiQRudh_FY" }, "execution_count": 4, "outputs": [] }, { "cell_type": "code", "source": [ "def classify_image(img):\n", " pred, idx, probs = learn.predict(img)\n", " return dict(zip(categories, map(float, probs)))" ], "metadata": { "id": "aIInhbiOh_xG" }, "execution_count": 10, "outputs": [] }, { "cell_type": "code", "source": [ "#hide_output\n", "import gradio as gr\n", "\n", "image = gr.inputs.Image(shape=(192, 192))\n", "label = gr.outputs.Label()\n", "examples = ['Dog.jpg', 'cat.jpg', 'dunno.jpg']\n", "title = \"Dogs V Cats Classifier\"\n", "description = \"A classifier trained on the Oxford Pets dataset with fastai. Created as a demo for Gradio and HuggingFace Spaces.\"\n", "interpretation='default'\n", "enable_queue=True\n", "\n", "intf = gr.Interface(\n", " fn=classify_image,\n", " inputs=image,\n", " outputs=label,\n", " examples=examples,\n", " title=title,\n", " description=description,\n", " interpretation=interpretation,\n", " enable_queue=enable_queue\n", ")\n", "\n", "intf.launch(inline=True, share=True)" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 836 }, "id": "8pOqkLe3igZp", "outputId": "b8d290b2-eac4-41c3-d14d-6a974ac701b9" }, "execution_count": 11, "outputs": [ { "output_type": "stream", "name": "stderr", "text": [ "/usr/local/lib/python3.7/dist-packages/gradio/inputs.py:257: UserWarning: Usage of gradio.inputs is deprecated, and will not be supported in the future, please import your component from gradio.components\n", " \"Usage of gradio.inputs is deprecated, and will not be supported in the future, please import your component from gradio.components\",\n", "/usr/local/lib/python3.7/dist-packages/gradio/deprecation.py:40: UserWarning: `optional` parameter is deprecated, and it has no effect\n", " warnings.warn(value)\n", "/usr/local/lib/python3.7/dist-packages/gradio/outputs.py:197: UserWarning: Usage of gradio.outputs is deprecated, and will not be supported in the future, please import your components from gradio.components\n", " \"Usage of gradio.outputs is deprecated, and will not be supported in the future, please import your components from gradio.components\",\n", "/usr/local/lib/python3.7/dist-packages/gradio/deprecation.py:40: UserWarning: The 'type' parameter has been deprecated. Use the Number component instead.\n", " warnings.warn(value)\n", "/usr/local/lib/python3.7/dist-packages/gradio/deprecation.py:40: UserWarning: `enable_queue` is deprecated in `Interface()`, please use it within `launch()` instead.\n", " warnings.warn(value)\n" ] }, { "output_type": "stream", "name": "stdout", "text": [ "Colab notebook detected. To show errors in colab notebook, set `debug=True` in `launch()`\n", "Running on public URL: https://17c82fbf8dced356.gradio.app\n", "\n", "This share link expires in 72 hours. For free permanent hosting and GPU upgrades (NEW!), check out Spaces: https://huggingface.co/spaces\n" ] }, { "output_type": "display_data", "data": { "text/plain": [ "" ], "text/html": [ "
" ] }, "metadata": {} }, { "output_type": "execute_result", "data": { "text/plain": [ "(,\n", " 'http://127.0.0.1:7861/',\n", " 'https://17c82fbf8dced356.gradio.app')" ] }, "metadata": {}, "execution_count": 11 } ] } ] }