{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "name": "AudioClassificationgradio.ipynb", "provenance": [], "collapsed_sections": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "8e25e79ba0c34ac2a39504d2bdb23a44": { "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_c326c94972544c0cafd0aec1424d3d66", "IPY_MODEL_a5ded79eb6274a2693d4f6f46dbdaae6", "IPY_MODEL_9165407f88a44866a6372082c5a1bdd1" ], "layout": "IPY_MODEL_cd13120cc6f345ff958b3438a51d9caf" } }, "c326c94972544c0cafd0aec1424d3d66": { "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_358da8bada514630b9078cd49fb2b2dc", "placeholder": "​", "style": "IPY_MODEL_53a416f6a7e9499ea6a88e44f2087c0d", "value": "Downloading: 100%" } }, "a5ded79eb6274a2693d4f6f46dbdaae6": { "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_74ce31440c4c497cb1ff10748a39c9e0", "max": 103192469, "min": 0, "orientation": "horizontal", "style": "IPY_MODEL_908199f1d2244909bd58c3bc46e6a47f", "value": 103192469 } }, "9165407f88a44866a6372082c5a1bdd1": { "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_3efa06b0aafd4f2ea01ebfc0a7d6abe6", "placeholder": "​", "style": "IPY_MODEL_10ed9d0b19814111b80a281ea80f60d9", "value": " 103M/103M [00:02<00:00, 51.8MB/s]" } }, "cd13120cc6f345ff958b3438a51d9caf": { "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 } }, "358da8bada514630b9078cd49fb2b2dc": { "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 } }, "53a416f6a7e9499ea6a88e44f2087c0d": { "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": "" } }, "74ce31440c4c497cb1ff10748a39c9e0": { "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 } }, "908199f1d2244909bd58c3bc46e6a47f": { "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": "" } }, "3efa06b0aafd4f2ea01ebfc0a7d6abe6": { "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 } }, "10ed9d0b19814111b80a281ea80f60d9": { "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": "code", "execution_count": 1, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "tj_BVh5omaoQ", "outputId": "413b2cf4-f8da-4bb3-a0a3-1c58cd89cfa0" }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "\u001b[K |████████████████████████████████| 197 kB 24.3 MB/s \n", "\u001b[K |████████████████████████████████| 2.9 MB 52.4 MB/s \n", "\u001b[K |████████████████████████████████| 77 kB 5.4 MB/s \n", "\u001b[K |████████████████████████████████| 60 kB 6.1 MB/s \n", "\u001b[K |████████████████████████████████| 84 kB 3.1 MB/s \n", "\u001b[K |████████████████████████████████| 54 kB 2.7 MB/s \n", "\u001b[K |████████████████████████████████| 1.1 MB 40.9 MB/s \n", "\u001b[K |████████████████████████████████| 2.0 MB 42.1 MB/s \n", "\u001b[K |████████████████████████████████| 253 kB 54.9 MB/s \n", "\u001b[K |████████████████████████████████| 53 kB 2.1 MB/s \n", "\u001b[K |████████████████████████████████| 212 kB 44.2 MB/s \n", "\u001b[K |████████████████████████████████| 271 kB 64.4 MB/s \n", "\u001b[K |████████████████████████████████| 144 kB 45.5 MB/s \n", "\u001b[K |████████████████████████████████| 94 kB 3.1 MB/s \n", "\u001b[K |████████████████████████████████| 58 kB 6.2 MB/s \n", "\u001b[K |████████████████████████████████| 10.9 MB 53.7 MB/s \n", "\u001b[K |████████████████████████████████| 79 kB 7.1 MB/s \n", "\u001b[K |████████████████████████████████| 43 kB 1.8 MB/s \n", "\u001b[K |████████████████████████████████| 62 kB 953 kB/s \n", "\u001b[K |████████████████████████████████| 856 kB 47.5 MB/s \n", "\u001b[K |████████████████████████████████| 4.0 MB 58.7 MB/s \n", "\u001b[K |████████████████████████████████| 58 kB 6.0 MB/s \n", "\u001b[?25h Building wheel for ffmpy (setup.py) ... \u001b[?25l\u001b[?25hdone\n", " Building wheel for python-multipart (setup.py) ... \u001b[?25l\u001b[?25hdone\n" ] } ], "source": [ "! pip install -Uqq fastai gradio torchaudio torchvision huggingface_hub" ] }, { "cell_type": "code", "source": [ "import gradio\n", "import torchaudio\n", "from fastai.vision.all import *\n", "from fastai.learner import load_learner\n", "from torchvision.utils import save_image\n", "from huggingface_hub import hf_hub_download" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "xIM_o4w-ms2J", "outputId": "936b730f-2d52-4cc2-fd7a-afbf86d05687" }, "execution_count": 2, "outputs": [ { "output_type": "stream", "name": "stderr", "text": [ "/usr/local/lib/python3.7/dist-packages/paramiko/transport.py:236: CryptographyDeprecationWarning: Blowfish has been deprecated\n", " \"class\": algorithms.Blowfish,\n" ] } ] }, { "cell_type": "code", "source": [ "model = load_learner(\n", " hf_hub_download(\"kurianbenoy/music_genre_classification_baseline\", \"model.pkl\")\n", ")\n", "\n", "labels = model.dls.vocab" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 49, "referenced_widgets": [ "8e25e79ba0c34ac2a39504d2bdb23a44", "c326c94972544c0cafd0aec1424d3d66", "a5ded79eb6274a2693d4f6f46dbdaae6", "9165407f88a44866a6372082c5a1bdd1", "cd13120cc6f345ff958b3438a51d9caf", "358da8bada514630b9078cd49fb2b2dc", "53a416f6a7e9499ea6a88e44f2087c0d", "74ce31440c4c497cb1ff10748a39c9e0", "908199f1d2244909bd58c3bc46e6a47f", "3efa06b0aafd4f2ea01ebfc0a7d6abe6", "10ed9d0b19814111b80a281ea80f60d9" ] }, "id": "MJxNnlsYmwsJ", "outputId": "3ba1eca7-1986-4f29-a549-b51bb79a4c88" }, "execution_count": 3, "outputs": [ { "output_type": "display_data", "data": { "text/plain": [ "Downloading: 0%| | 0.00/103M [00:00" ], "text/html": [ "\n", " \n", " " ] }, "metadata": {} }, { "output_type": "execute_result", "data": { "text/plain": [ "(,\n", " 'http://127.0.0.1:7862/',\n", " 'https://55955.gradio.app')" ] }, "metadata": {}, "execution_count": 13 } ] }, { "cell_type": "code", "source": [ "input_audio = [gradio.inputs.Audio(source=\"microphone\", type=\"filepath\", label=\"Record/ Drop audio\")]\n", "input_audio" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "8Ptz2HMdnAE7", "outputId": "2cac3314-07eb-4c91-d5ed-770e2ed6ae0d" }, "execution_count": 9, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "[Audio(label=\"Record/ Drop audio\")]" ] }, "metadata": {}, "execution_count": 9 } ] }, { "cell_type": "code", "source": [ "" ], "metadata": { "id": "_wHGGfNfnufy" }, "execution_count": null, "outputs": [] } ] }