Spaces:
Paused
Paused
osanseviero
commited on
Commit
•
8eb2c7a
1
Parent(s):
a5bfe25
Upload whisper_notebook.ipynb
Browse files- whisper_notebook.ipynb +192 -0
whisper_notebook.ipynb
ADDED
@@ -0,0 +1,192 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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": "markdown",
|
21 |
+
"source": [
|
22 |
+
"# Whisper v3 is here!\n",
|
23 |
+
"\n",
|
24 |
+
"Whisper v3 is a new model open sourced by OpenAI. The model can do multilingual transcriptions and is quite impressive. For example, you can change from English to Spanish or Chinese in the middle of a sentence and it will work well!\n",
|
25 |
+
"\n",
|
26 |
+
"The model can be run in a free Google Colab instance and is integrated into `transformers` already, so switching can be a very smooth process if you already use the previous versions."
|
27 |
+
],
|
28 |
+
"metadata": {
|
29 |
+
"id": "OXaUqiE-eyXM"
|
30 |
+
}
|
31 |
+
},
|
32 |
+
{
|
33 |
+
"cell_type": "code",
|
34 |
+
"execution_count": 5,
|
35 |
+
"metadata": {
|
36 |
+
"id": "WFQeUT9EcIcK"
|
37 |
+
},
|
38 |
+
"outputs": [],
|
39 |
+
"source": [
|
40 |
+
"%%capture\n",
|
41 |
+
"!pip install git+https://github.com/huggingface/transformers gradio"
|
42 |
+
]
|
43 |
+
},
|
44 |
+
{
|
45 |
+
"cell_type": "markdown",
|
46 |
+
"source": [
|
47 |
+
"Let's use the high level `pipeline` from the `transformers` library to load the model."
|
48 |
+
],
|
49 |
+
"metadata": {
|
50 |
+
"id": "sZONes21fHTA"
|
51 |
+
}
|
52 |
+
},
|
53 |
+
{
|
54 |
+
"cell_type": "code",
|
55 |
+
"source": [
|
56 |
+
"import torch\n",
|
57 |
+
"from transformers import pipeline\n",
|
58 |
+
"\n",
|
59 |
+
"pipe = pipeline(\"automatic-speech-recognition\",\n",
|
60 |
+
" \"openai/whisper-large-v3\",\n",
|
61 |
+
" torch_dtype=torch.float16,\n",
|
62 |
+
" device=\"cuda:0\")"
|
63 |
+
],
|
64 |
+
"metadata": {
|
65 |
+
"colab": {
|
66 |
+
"base_uri": "https://localhost:8080/"
|
67 |
+
},
|
68 |
+
"id": "DvBdwMdPcr-Y",
|
69 |
+
"outputId": "47f32218-fd85-49ea-d880-d31577bcf9b8"
|
70 |
+
},
|
71 |
+
"execution_count": 3,
|
72 |
+
"outputs": [
|
73 |
+
{
|
74 |
+
"output_type": "stream",
|
75 |
+
"name": "stderr",
|
76 |
+
"text": [
|
77 |
+
"Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.\n",
|
78 |
+
"Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.\n"
|
79 |
+
]
|
80 |
+
}
|
81 |
+
]
|
82 |
+
},
|
83 |
+
{
|
84 |
+
"cell_type": "code",
|
85 |
+
"source": [
|
86 |
+
"pipe(\"https://cdn-media.huggingface.co/speech_samples/sample1.flac\")"
|
87 |
+
],
|
88 |
+
"metadata": {
|
89 |
+
"colab": {
|
90 |
+
"base_uri": "https://localhost:8080/"
|
91 |
+
},
|
92 |
+
"id": "GZFkIyhjc0Nc",
|
93 |
+
"outputId": "f1463431-3e08-4438-815f-b71e5e7a1503"
|
94 |
+
},
|
95 |
+
"execution_count": 2,
|
96 |
+
"outputs": [
|
97 |
+
{
|
98 |
+
"output_type": "execute_result",
|
99 |
+
"data": {
|
100 |
+
"text/plain": [
|
101 |
+
"{'text': \" going along slushy country roads and speaking to damp audiences in draughty schoolrooms day after day for a fortnight he'll have to put in an appearance at some place of worship on sunday morning and he can come to us immediately afterwards\"}"
|
102 |
+
]
|
103 |
+
},
|
104 |
+
"metadata": {},
|
105 |
+
"execution_count": 2
|
106 |
+
}
|
107 |
+
]
|
108 |
+
},
|
109 |
+
{
|
110 |
+
"cell_type": "markdown",
|
111 |
+
"source": [
|
112 |
+
"Let's now build a quick Gradio demo where we can play with the model directly using our microphone!"
|
113 |
+
],
|
114 |
+
"metadata": {
|
115 |
+
"id": "pt3YtM_PfTQY"
|
116 |
+
}
|
117 |
+
},
|
118 |
+
{
|
119 |
+
"cell_type": "code",
|
120 |
+
"source": [
|
121 |
+
"import gradio as gr\n",
|
122 |
+
"\n",
|
123 |
+
"def transcribe(inputs):\n",
|
124 |
+
" if inputs is None:\n",
|
125 |
+
" raise gr.Error(\"No audio file submitted! Please record an audio before submitting your request.\")\n",
|
126 |
+
"\n",
|
127 |
+
" text = pipe(inputs, generate_kwargs={\"task\": \"transcribe\"}, return_timestamps=True)[\"text\"]\n",
|
128 |
+
" return text\n",
|
129 |
+
"\n",
|
130 |
+
"demo = gr.Interface(\n",
|
131 |
+
" fn=transcribe,\n",
|
132 |
+
" inputs=[\n",
|
133 |
+
" gr.Audio(sources=[\"microphone\", \"upload\"], type=\"filepath\"),\n",
|
134 |
+
" ],\n",
|
135 |
+
" outputs=\"text\",\n",
|
136 |
+
" title=\"Whisper Large V3: Transcribe Audio\",\n",
|
137 |
+
" description=(\n",
|
138 |
+
" \"Transcribe long-form microphone or audio inputs with the click of a button! Demo uses the\"\n",
|
139 |
+
" \" checkpoint [openai/whisper-large-v3](https://huggingface.co/openai/whisper-large-v3) and 🤗 Transformers to transcribe audio files\"\n",
|
140 |
+
" \" of arbitrary length.\"\n",
|
141 |
+
" ),\n",
|
142 |
+
" allow_flagging=\"never\",\n",
|
143 |
+
")\n",
|
144 |
+
"\n",
|
145 |
+
"demo.launch()\n"
|
146 |
+
],
|
147 |
+
"metadata": {
|
148 |
+
"colab": {
|
149 |
+
"base_uri": "https://localhost:8080/",
|
150 |
+
"height": 648
|
151 |
+
},
|
152 |
+
"id": "K0b2UZLVdIze",
|
153 |
+
"outputId": "bcff00e0-4fc8-4883-9ba4-480f5a6665f0"
|
154 |
+
},
|
155 |
+
"execution_count": 4,
|
156 |
+
"outputs": [
|
157 |
+
{
|
158 |
+
"output_type": "stream",
|
159 |
+
"name": "stdout",
|
160 |
+
"text": [
|
161 |
+
"Setting queue=True in a Colab notebook requires sharing enabled. Setting `share=True` (you can turn this off by setting `share=False` in `launch()` explicitly).\n",
|
162 |
+
"\n",
|
163 |
+
"Colab notebook detected. To show errors in colab notebook, set debug=True in launch()\n",
|
164 |
+
"Running on public URL: https://037dbdb04542aa1a29.gradio.live\n",
|
165 |
+
"\n",
|
166 |
+
"This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)\n"
|
167 |
+
]
|
168 |
+
},
|
169 |
+
{
|
170 |
+
"output_type": "display_data",
|
171 |
+
"data": {
|
172 |
+
"text/plain": [
|
173 |
+
"<IPython.core.display.HTML object>"
|
174 |
+
],
|
175 |
+
"text/html": [
|
176 |
+
"<div><iframe src=\"https://037dbdb04542aa1a29.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
177 |
+
]
|
178 |
+
},
|
179 |
+
"metadata": {}
|
180 |
+
},
|
181 |
+
{
|
182 |
+
"output_type": "execute_result",
|
183 |
+
"data": {
|
184 |
+
"text/plain": []
|
185 |
+
},
|
186 |
+
"metadata": {},
|
187 |
+
"execution_count": 4
|
188 |
+
}
|
189 |
+
]
|
190 |
+
}
|
191 |
+
]
|
192 |
+
}
|