Gyaneshere commited on
Commit
09e5539
·
verified ·
1 Parent(s): efa51c5

Upload gradio_app.ipynb

Browse files
Files changed (1) hide show
  1. gradio_app.ipynb +114 -0
gradio_app.ipynb ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "nbformat": 4,
3
+ "nbformat_minor": 0,
4
+ "metadata": {
5
+ "colab": {
6
+ "provenance": [],
7
+ "gpuType": "T4"
8
+ },
9
+ "kernelspec": {
10
+ "name": "python3",
11
+ "display_name": "Python 3"
12
+ },
13
+ "language_info": {
14
+ "name": "python"
15
+ },
16
+ "accelerator": "GPU"
17
+ },
18
+ "cells": [
19
+ {
20
+ "cell_type": "code",
21
+ "execution_count": 4,
22
+ "metadata": {
23
+ "colab": {
24
+ "base_uri": "https://localhost:8080/"
25
+ },
26
+ "id": "KBOTNSWfwlMs",
27
+ "outputId": "0767243b-aaac-414b-bf15-5c37712777c8"
28
+ },
29
+ "outputs": [
30
+ {
31
+ "output_type": "stream",
32
+ "name": "stderr",
33
+ "text": [
34
+ "/usr/local/lib/python3.11/dist-packages/huggingface_hub/utils/_auth.py:94: UserWarning: \n",
35
+ "The secret `HF_TOKEN` does not exist in your Colab secrets.\n",
36
+ "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",
37
+ "You will be able to reuse this secret in all of your notebooks.\n",
38
+ "Please note that authentication is recommended but still optional to access public models or datasets.\n",
39
+ " warnings.warn(\n",
40
+ "Device set to use cuda:0\n"
41
+ ]
42
+ }
43
+ ],
44
+ "source": [
45
+ "from transformers import pipeline\n",
46
+ "\n",
47
+ "model_id = \"Gyaneshere/distilhubert-finetuned-gtzan\"\n",
48
+ "pipe = pipeline(\"audio-classification\", model=model_id)"
49
+ ]
50
+ },
51
+ {
52
+ "cell_type": "code",
53
+ "source": [
54
+ "def classify_audio(filepath):\n",
55
+ " preds = pipe(filepath)\n",
56
+ " outputs = {}\n",
57
+ " for p in preds:\n",
58
+ " outputs[p[\"label\"]] = p[\"score\"]\n",
59
+ " return outputs"
60
+ ],
61
+ "metadata": {
62
+ "id": "EDnsKBNTw21Y"
63
+ },
64
+ "execution_count": 5,
65
+ "outputs": []
66
+ },
67
+ {
68
+ "cell_type": "code",
69
+ "source": [
70
+ "import gradio as gr\n",
71
+ "\n",
72
+ "demo = gr.Interface(\n",
73
+ " fn=classify_audio, inputs=gr.Audio(type=\"filepath\"), outputs=gr.Label()\n",
74
+ ")\n",
75
+ "demo.launch(debug=True)"
76
+ ],
77
+ "metadata": {
78
+ "colab": {
79
+ "base_uri": "https://localhost:8080/",
80
+ "height": 648
81
+ },
82
+ "id": "bDO18TF_xAj0",
83
+ "outputId": "a2fd8a7b-d673-431c-a0ac-ed47813f3cf1"
84
+ },
85
+ "execution_count": null,
86
+ "outputs": [
87
+ {
88
+ "output_type": "stream",
89
+ "name": "stdout",
90
+ "text": [
91
+ "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",
92
+ "\n",
93
+ "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",
94
+ "* Running on public URL: https://05087897ec4bd78398.gradio.live\n",
95
+ "\n",
96
+ "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"
97
+ ]
98
+ },
99
+ {
100
+ "output_type": "display_data",
101
+ "data": {
102
+ "text/plain": [
103
+ "<IPython.core.display.HTML object>"
104
+ ],
105
+ "text/html": [
106
+ "<div><iframe src=\"https://05087897ec4bd78398.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
107
+ ]
108
+ },
109
+ "metadata": {}
110
+ }
111
+ ]
112
+ }
113
+ ]
114
+ }