{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [], "gpuType": "T4" }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" }, "accelerator": "GPU" }, "cells": [ { "cell_type": "code", "execution_count": 4, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "KBOTNSWfwlMs", "outputId": "0767243b-aaac-414b-bf15-5c37712777c8" }, "outputs": [ { "output_type": "stream", "name": "stderr", "text": [ "/usr/local/lib/python3.11/dist-packages/huggingface_hub/utils/_auth.py:94: UserWarning: \n", "The secret `HF_TOKEN` does not exist in your Colab secrets.\n", "To authenticate with the Hugging Face Hub, create a token in your settings tab (https://huggingface.co/settings/tokens), set it as secret in your Google Colab and restart your session.\n", "You will be able to reuse this secret in all of your notebooks.\n", "Please note that authentication is recommended but still optional to access public models or datasets.\n", " warnings.warn(\n", "Device set to use cuda:0\n" ] } ], "source": [ "from transformers import pipeline\n", "\n", "model_id = \"Gyaneshere/distilhubert-finetuned-gtzan\"\n", "pipe = pipeline(\"audio-classification\", model=model_id)" ] }, { "cell_type": "code", "source": [ "def classify_audio(filepath):\n", " preds = pipe(filepath)\n", " outputs = {}\n", " for p in preds:\n", " outputs[p[\"label\"]] = p[\"score\"]\n", " return outputs" ], "metadata": { "id": "EDnsKBNTw21Y" }, "execution_count": 5, "outputs": [] }, { "cell_type": "code", "source": [ "import gradio as gr\n", "\n", "demo = gr.Interface(\n", " fn=classify_audio, inputs=gr.Audio(type=\"filepath\"), outputs=gr.Label()\n", ")\n", "demo.launch(debug=True)" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 648 }, "id": "bDO18TF_xAj0", "outputId": "a2fd8a7b-d673-431c-a0ac-ed47813f3cf1" }, "execution_count": null, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Running Gradio in a Colab notebook requires sharing enabled. Automatically setting `share=True` (you can turn this off by setting `share=False` in `launch()` explicitly).\n", "\n", "Colab notebook detected. This cell will run indefinitely so that you can see errors and logs. To turn off, set debug=False in launch().\n", "* Running on public URL: https://05087897ec4bd78398.gradio.live\n", "\n", "This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from the terminal in the working directory to deploy to Hugging Face Spaces (https://huggingface.co/spaces)\n" ] }, { "output_type": "display_data", "data": { "text/plain": [ "" ], "text/html": [ "
" ] }, "metadata": {} } ] } ] }