{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "-iqK1uZxKOPk" }, "source": [] }, { "cell_type": "code", "execution_count": 3, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "BarGLJEUlp88", "outputId": "84b24178-ffbb-4151-de2d-069dd5746ac7" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: datasets in /usr/local/lib/python3.10/dist-packages (2.19.1)\n", "Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from datasets) (3.14.0)\n", "Requirement already satisfied: numpy>=1.17 in /usr/local/lib/python3.10/dist-packages (from datasets) (1.25.2)\n", "Requirement already satisfied: pyarrow>=12.0.0 in /usr/local/lib/python3.10/dist-packages (from datasets) (14.0.2)\n", "Requirement already satisfied: pyarrow-hotfix in /usr/local/lib/python3.10/dist-packages (from datasets) (0.6)\n", "Requirement already satisfied: dill<0.3.9,>=0.3.0 in /usr/local/lib/python3.10/dist-packages (from datasets) (0.3.8)\n", "Requirement already satisfied: pandas in /usr/local/lib/python3.10/dist-packages (from datasets) (2.0.3)\n", "Requirement already satisfied: requests>=2.19.0 in /usr/local/lib/python3.10/dist-packages (from datasets) (2.31.0)\n", "Requirement already satisfied: tqdm>=4.62.1 in /usr/local/lib/python3.10/dist-packages (from datasets) (4.66.4)\n", "Requirement already satisfied: xxhash in /usr/local/lib/python3.10/dist-packages (from datasets) (3.4.1)\n", "Requirement already satisfied: multiprocess in /usr/local/lib/python3.10/dist-packages (from datasets) (0.70.16)\n", "Requirement already satisfied: fsspec[http]<=2024.3.1,>=2023.1.0 in /usr/local/lib/python3.10/dist-packages (from datasets) (2023.6.0)\n", "Requirement already satisfied: aiohttp in /usr/local/lib/python3.10/dist-packages (from datasets) (3.9.5)\n", "Requirement already satisfied: huggingface-hub>=0.21.2 in /usr/local/lib/python3.10/dist-packages (from datasets) (0.23.0)\n", "Requirement already satisfied: packaging in /usr/local/lib/python3.10/dist-packages (from datasets) (24.0)\n", "Requirement already satisfied: pyyaml>=5.1 in /usr/local/lib/python3.10/dist-packages (from datasets) (6.0.1)\n", "Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.10/dist-packages (from aiohttp->datasets) (1.3.1)\n", "Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->datasets) (23.2.0)\n", "Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from aiohttp->datasets) (1.4.1)\n", "Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.10/dist-packages (from aiohttp->datasets) (6.0.5)\n", "Requirement already satisfied: yarl<2.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->datasets) (1.9.4)\n", "Requirement already satisfied: async-timeout<5.0,>=4.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->datasets) (4.0.3)\n", "Requirement already satisfied: typing-extensions>=3.7.4.3 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.21.2->datasets) (4.11.0)\n", "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests>=2.19.0->datasets) (3.3.2)\n", "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests>=2.19.0->datasets) (3.7)\n", "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests>=2.19.0->datasets) (2.0.7)\n", "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests>=2.19.0->datasets) (2024.2.2)\n", "Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.10/dist-packages (from pandas->datasets) (2.8.2)\n", "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas->datasets) (2023.4)\n", "Requirement already satisfied: tzdata>=2022.1 in /usr/local/lib/python3.10/dist-packages (from pandas->datasets) (2024.1)\n", "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.8.2->pandas->datasets) (1.16.0)\n" ] } ], "source": [ "pip install datasets" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "MoeKcp3tlQSf", "outputId": "1d6fd480-d37f-4028-de75-9595abc97464" }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/user/Desktop/model/venv/lib/python3.11/site-packages/datasets/load.py:1486: FutureWarning: The repository for marsyas/gtzan contains custom code which must be executed to correctly load the dataset. You can inspect the repository content at https://hf.co/datasets/marsyas/gtzan\n", "You can avoid this message in future by passing the argument `trust_remote_code=True`.\n", "Passing `trust_remote_code=True` will be mandatory to load this dataset from the next major release of `datasets`.\n", " warnings.warn(\n" ] }, { "data": { "text/plain": [ "DatasetDict({\n", " train: Dataset({\n", " features: ['file', 'audio', 'genre'],\n", " num_rows: 999\n", " })\n", "})" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from datasets import load_dataset\n", "\n", "gtzan = load_dataset(\"marsyas/gtzan\", \"all\")\n", "gtzan" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "A3GolExklYZH", "outputId": "bdf2d280-749a-4a62-b398-92aa9174079e" }, "outputs": [ { "data": { "text/plain": [ "DatasetDict({\n", " train: Dataset({\n", " features: ['file', 'audio', 'genre'],\n", " num_rows: 999\n", " })\n", "})" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gtzan" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "id": "r7nBVDEKmKzq" }, "outputs": [], "source": [ "gtzan = gtzan['train'].train_test_split(seed=42, test_size=0.1)\n" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "AVT3baEn9IAo", "outputId": "8c3fe83a-b0a6-4427-c401-28722a4725fb" }, "outputs": [ { "data": { "text/plain": [ "{'file': '/home/user/.cache/huggingface/datasets/downloads/extracted/8467212e1467f829ca8aa5be797cbd9704e95050d4c3e44235bb44dfacaa486f/genres/pop/pop.00098.wav',\n", " 'audio': {'path': '/home/user/.cache/huggingface/datasets/downloads/extracted/8467212e1467f829ca8aa5be797cbd9704e95050d4c3e44235bb44dfacaa486f/genres/pop/pop.00098.wav',\n", " 'array': array([ 0.10720825, 0.16122437, 0.28585815, ..., -0.22924805,\n", " -0.20629883, -0.11334229]),\n", " 'sampling_rate': 22050},\n", " 'genre': 7}" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gtzan[\"train\"][0]" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 35 }, "id": "qrB5kdIx9WwX", "outputId": "3c0eaa93-f8db-4b39-d5dd-d312d82cc554" }, "outputs": [ { "data": { "text/plain": [ "'pop'" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "id2label_fn = gtzan[\"train\"].features[\"genre\"].int2str\n", "id2label_fn(gtzan[\"train\"][0][\"genre\"])" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "MHzcJshE9b1B", "outputId": "dff1405a-1070-44e5-eb08-ace3416df099" }, "outputs": [ { "data": { "text/plain": [ "DatasetDict({\n", " train: Dataset({\n", " features: ['file', 'audio', 'genre'],\n", " num_rows: 899\n", " })\n", " test: Dataset({\n", " features: ['file', 'audio', 'genre'],\n", " num_rows: 100\n", " })\n", "})" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gtzan" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "Q54XUqyW9opO", "outputId": "2a03f78b-b911-42ea-ab87-0f8250cedb16" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: gradio in ./venv/lib/python3.11/site-packages (4.31.4)\n", "Requirement already satisfied: aiofiles<24.0,>=22.0 in ./venv/lib/python3.11/site-packages (from gradio) (23.2.1)\n", "Requirement already satisfied: altair<6.0,>=4.2.0 in ./venv/lib/python3.11/site-packages (from gradio) (5.3.0)\n", "Requirement already satisfied: fastapi in ./venv/lib/python3.11/site-packages (from gradio) (0.111.0)\n", "Requirement already satisfied: ffmpy in ./venv/lib/python3.11/site-packages (from gradio) (0.3.2)\n", "Requirement already satisfied: gradio-client==0.16.4 in ./venv/lib/python3.11/site-packages (from gradio) (0.16.4)\n", "Requirement already satisfied: httpx>=0.24.1 in ./venv/lib/python3.11/site-packages (from gradio) (0.27.0)\n", "Requirement already satisfied: huggingface-hub>=0.19.3 in ./venv/lib/python3.11/site-packages (from gradio) (0.23.0)\n", "Requirement already satisfied: importlib-resources<7.0,>=1.3 in ./venv/lib/python3.11/site-packages (from gradio) (6.4.0)\n", "Requirement already satisfied: jinja2<4.0 in ./venv/lib/python3.11/site-packages (from gradio) (3.1.4)\n", "Requirement already satisfied: markupsafe~=2.0 in ./venv/lib/python3.11/site-packages (from gradio) (2.1.5)\n", "Requirement already satisfied: matplotlib~=3.0 in ./venv/lib/python3.11/site-packages (from gradio) (3.9.0)\n", "Requirement already satisfied: numpy~=1.0 in ./venv/lib/python3.11/site-packages (from gradio) (1.26.4)\n", "Requirement already satisfied: orjson~=3.0 in ./venv/lib/python3.11/site-packages (from gradio) (3.10.3)\n", "Requirement already satisfied: packaging in ./venv/lib/python3.11/site-packages (from gradio) (24.0)\n", "Requirement already satisfied: pandas<3.0,>=1.0 in ./venv/lib/python3.11/site-packages (from gradio) (2.2.2)\n", "Requirement already satisfied: pillow<11.0,>=8.0 in ./venv/lib/python3.11/site-packages (from gradio) (10.3.0)\n", "Requirement already satisfied: pydantic>=2.0 in ./venv/lib/python3.11/site-packages (from gradio) (2.7.1)\n", "Requirement already satisfied: pydub in ./venv/lib/python3.11/site-packages (from gradio) (0.25.1)\n", "Requirement already satisfied: python-multipart>=0.0.9 in ./venv/lib/python3.11/site-packages (from gradio) (0.0.9)\n", "Requirement already satisfied: pyyaml<7.0,>=5.0 in ./venv/lib/python3.11/site-packages (from gradio) (6.0.1)\n", "Requirement already satisfied: ruff>=0.2.2 in ./venv/lib/python3.11/site-packages (from gradio) (0.4.4)\n", "Requirement already satisfied: semantic-version~=2.0 in ./venv/lib/python3.11/site-packages (from gradio) (2.10.0)\n", "Requirement already satisfied: tomlkit==0.12.0 in ./venv/lib/python3.11/site-packages (from gradio) (0.12.0)\n", "Requirement already satisfied: typer<1.0,>=0.12 in ./venv/lib/python3.11/site-packages (from gradio) (0.12.3)\n", "Requirement already satisfied: typing-extensions~=4.0 in ./venv/lib/python3.11/site-packages (from gradio) (4.11.0)\n", "Requirement already satisfied: urllib3~=2.0 in ./venv/lib/python3.11/site-packages (from gradio) (2.2.1)\n", "Requirement already satisfied: uvicorn>=0.14.0 in ./venv/lib/python3.11/site-packages (from gradio) (0.29.0)\n", "Requirement already satisfied: fsspec in ./venv/lib/python3.11/site-packages (from gradio-client==0.16.4->gradio) (2024.3.1)\n", "Requirement already satisfied: websockets<12.0,>=10.0 in ./venv/lib/python3.11/site-packages (from gradio-client==0.16.4->gradio) (11.0.3)\n", "Requirement already satisfied: jsonschema>=3.0 in ./venv/lib/python3.11/site-packages (from altair<6.0,>=4.2.0->gradio) (4.22.0)\n", "Requirement already satisfied: toolz in ./venv/lib/python3.11/site-packages (from altair<6.0,>=4.2.0->gradio) (0.12.1)\n", "Requirement already satisfied: anyio in ./venv/lib/python3.11/site-packages (from httpx>=0.24.1->gradio) (4.3.0)\n", "Requirement already satisfied: certifi in ./venv/lib/python3.11/site-packages (from httpx>=0.24.1->gradio) (2024.2.2)\n", "Requirement already satisfied: httpcore==1.* in ./venv/lib/python3.11/site-packages (from httpx>=0.24.1->gradio) (1.0.5)\n", "Requirement already satisfied: idna in ./venv/lib/python3.11/site-packages (from httpx>=0.24.1->gradio) (3.7)\n", "Requirement already satisfied: sniffio in ./venv/lib/python3.11/site-packages (from httpx>=0.24.1->gradio) (1.3.1)\n", "Requirement already satisfied: h11<0.15,>=0.13 in ./venv/lib/python3.11/site-packages (from httpcore==1.*->httpx>=0.24.1->gradio) (0.14.0)\n", "Requirement already satisfied: filelock in ./venv/lib/python3.11/site-packages (from huggingface-hub>=0.19.3->gradio) (3.14.0)\n", "Requirement already satisfied: requests in ./venv/lib/python3.11/site-packages (from huggingface-hub>=0.19.3->gradio) (2.31.0)\n", "Requirement already satisfied: tqdm>=4.42.1 in ./venv/lib/python3.11/site-packages (from huggingface-hub>=0.19.3->gradio) (4.66.4)\n", "Requirement already satisfied: contourpy>=1.0.1 in ./venv/lib/python3.11/site-packages (from matplotlib~=3.0->gradio) (1.2.1)\n", "Requirement already satisfied: cycler>=0.10 in ./venv/lib/python3.11/site-packages (from matplotlib~=3.0->gradio) (0.12.1)\n", "Requirement already satisfied: fonttools>=4.22.0 in ./venv/lib/python3.11/site-packages (from matplotlib~=3.0->gradio) (4.51.0)\n", "Requirement already satisfied: kiwisolver>=1.3.1 in ./venv/lib/python3.11/site-packages (from matplotlib~=3.0->gradio) (1.4.5)\n", "Requirement already satisfied: pyparsing>=2.3.1 in ./venv/lib/python3.11/site-packages (from matplotlib~=3.0->gradio) (3.1.2)\n", "Requirement already satisfied: python-dateutil>=2.7 in ./venv/lib/python3.11/site-packages (from matplotlib~=3.0->gradio) (2.9.0.post0)\n", "Requirement already satisfied: pytz>=2020.1 in ./venv/lib/python3.11/site-packages (from pandas<3.0,>=1.0->gradio) (2024.1)\n", "Requirement already satisfied: tzdata>=2022.7 in ./venv/lib/python3.11/site-packages (from pandas<3.0,>=1.0->gradio) (2024.1)\n", "Requirement already satisfied: annotated-types>=0.4.0 in ./venv/lib/python3.11/site-packages (from pydantic>=2.0->gradio) (0.6.0)\n", "Requirement already satisfied: pydantic-core==2.18.2 in ./venv/lib/python3.11/site-packages (from pydantic>=2.0->gradio) (2.18.2)\n", "Requirement already satisfied: click>=8.0.0 in ./venv/lib/python3.11/site-packages (from typer<1.0,>=0.12->gradio) (8.1.7)\n", "Requirement already satisfied: shellingham>=1.3.0 in ./venv/lib/python3.11/site-packages (from typer<1.0,>=0.12->gradio) (1.5.4)\n", "Requirement already satisfied: rich>=10.11.0 in ./venv/lib/python3.11/site-packages (from typer<1.0,>=0.12->gradio) (13.7.1)\n", "Requirement already satisfied: starlette<0.38.0,>=0.37.2 in ./venv/lib/python3.11/site-packages (from fastapi->gradio) (0.37.2)\n", "Requirement already satisfied: fastapi-cli>=0.0.2 in ./venv/lib/python3.11/site-packages (from fastapi->gradio) (0.0.4)\n", "Requirement already satisfied: ujson!=4.0.2,!=4.1.0,!=4.2.0,!=4.3.0,!=5.0.0,!=5.1.0,>=4.0.1 in ./venv/lib/python3.11/site-packages (from fastapi->gradio) (5.10.0)\n", "Requirement already satisfied: email_validator>=2.0.0 in ./venv/lib/python3.11/site-packages (from fastapi->gradio) (2.1.1)\n", "Requirement already satisfied: dnspython>=2.0.0 in ./venv/lib/python3.11/site-packages (from email_validator>=2.0.0->fastapi->gradio) (2.6.1)\n", "Requirement already satisfied: attrs>=22.2.0 in ./venv/lib/python3.11/site-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (23.2.0)\n", "Requirement already satisfied: jsonschema-specifications>=2023.03.6 in ./venv/lib/python3.11/site-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (2023.12.1)\n", "Requirement already satisfied: referencing>=0.28.4 in ./venv/lib/python3.11/site-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (0.35.1)\n", "Requirement already satisfied: rpds-py>=0.7.1 in ./venv/lib/python3.11/site-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (0.18.1)\n", "Requirement already satisfied: six>=1.5 in ./venv/lib/python3.11/site-packages (from python-dateutil>=2.7->matplotlib~=3.0->gradio) (1.16.0)\n", "Requirement already satisfied: markdown-it-py>=2.2.0 in ./venv/lib/python3.11/site-packages (from rich>=10.11.0->typer<1.0,>=0.12->gradio) (3.0.0)\n", "Requirement already satisfied: pygments<3.0.0,>=2.13.0 in ./venv/lib/python3.11/site-packages (from rich>=10.11.0->typer<1.0,>=0.12->gradio) (2.18.0)\n", "Requirement already satisfied: httptools>=0.5.0 in ./venv/lib/python3.11/site-packages (from uvicorn>=0.14.0->gradio) (0.6.1)\n", "Requirement already satisfied: python-dotenv>=0.13 in ./venv/lib/python3.11/site-packages (from uvicorn>=0.14.0->gradio) (1.0.1)\n", "Requirement already satisfied: uvloop!=0.15.0,!=0.15.1,>=0.14.0 in ./venv/lib/python3.11/site-packages (from uvicorn>=0.14.0->gradio) (0.19.0)\n", "Requirement already satisfied: watchfiles>=0.13 in ./venv/lib/python3.11/site-packages (from uvicorn>=0.14.0->gradio) (0.21.0)\n", "Requirement already satisfied: charset-normalizer<4,>=2 in ./venv/lib/python3.11/site-packages (from requests->huggingface-hub>=0.19.3->gradio) (3.3.2)\n", "Requirement already satisfied: mdurl~=0.1 in ./venv/lib/python3.11/site-packages (from markdown-it-py>=2.2.0->rich>=10.11.0->typer<1.0,>=0.12->gradio) (0.1.2)\n", "Note: you may need to restart the kernel to use updated packages.\n" ] } ], "source": [ "pip install gradio" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "id": "3nsunOhq9i6K" }, "outputs": [], "source": [ "import gradio as gr" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 715 }, "id": "wD4Jd7qg-ApE", "outputId": "734b3fcf-6440-4b4b-8405-2c3a830e8569", "scrolled": true }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/user/Desktop/model/venv/lib/python3.11/site-packages/gradio/processing_utils.py:582: UserWarning: Trying to convert audio automatically from float64 to 16-bit int format.\n", " warnings.warn(warning.format(data.dtype))\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Running on local URL: http://127.0.0.1:7860\n", "\n", "To create a public link, set `share=True` in `launch()`.\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "Epoch | \n", "Training Loss | \n", "Validation Loss | \n", "Accuracy | \n", "
---|---|---|---|
1 | \n", "1.977700 | \n", "1.902388 | \n", "0.530000 | \n", "
2 | \n", "1.182000 | \n", "1.280992 | \n", "0.650000 | \n", "
3 | \n", "1.038300 | \n", "1.033311 | \n", "0.690000 | \n", "
4 | \n", "0.654200 | \n", "0.885210 | \n", "0.720000 | \n", "
5 | \n", "0.553500 | \n", "0.713898 | \n", "0.800000 | \n", "
6 | \n", "0.475900 | \n", "0.584029 | \n", "0.840000 | \n", "
7 | \n", "0.285600 | \n", "0.552340 | \n", "0.830000 | \n", "
8 | \n", "0.145000 | \n", "0.631408 | \n", "0.800000 | \n", "
9 | \n", "0.269300 | \n", "0.572215 | \n", "0.820000 | \n", "
10 | \n", "0.171400 | \n", "0.589203 | \n", "0.800000 | \n", "
"
],
"text/plain": [
"
Copy a token from your Hugging Face\ntokens page and paste it below.
Immediately click login after copying\nyour token or it might be stored in plain text in this notebook file.