Spaces:
Sleeping
Sleeping
Commit
·
84f2a5a
1
Parent(s):
5595fa0
Upload whisper_microphone.py
Browse files- whisper_microphone.py +57 -0
whisper_microphone.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""whisper_microphone.ipynb
|
| 3 |
+
|
| 4 |
+
Automatically generated by Colaboratory.
|
| 5 |
+
|
| 6 |
+
Original file is located at
|
| 7 |
+
https://colab.research.google.com/drive/1nvViL6jAkzpXX3quqkz2I44m70S-YN8t
|
| 8 |
+
|
| 9 |
+
# Using gradio for making a nice UI.
|
| 10 |
+
Upload audio file version.
|
| 11 |
+
|
| 12 |
+
Installing requirements.
|
| 13 |
+
"""
|
| 14 |
+
|
| 15 |
+
!pip install gradio
|
| 16 |
+
!pip install git+https://github.com/huggingface/transformers
|
| 17 |
+
|
| 18 |
+
from transformers import pipeline
|
| 19 |
+
import gradio as gr
|
| 20 |
+
import os
|
| 21 |
+
|
| 22 |
+
"""## Building a Demo
|
| 23 |
+
|
| 24 |
+
Now that we've fine-tuned our model we can build a demo to show
|
| 25 |
+
off its ASR capabilities! We'll make use of 🤗 Transformers
|
| 26 |
+
`pipeline`, which will take care of the entire ASR pipeline,
|
| 27 |
+
right from pre-processing the audio inputs to decoding the
|
| 28 |
+
model predictions.
|
| 29 |
+
|
| 30 |
+
Running the example below will generate a Gradio demo where can input audio to
|
| 31 |
+
our fine-tuned Whisper model to transcribe the corresponding text:
|
| 32 |
+
"""
|
| 33 |
+
|
| 34 |
+
from transformers import WhisperTokenizer
|
| 35 |
+
from transformers import WhisperProcessor
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
pipe = pipeline(model="Victorlopo21/whisper-medium-gl-30")
|
| 40 |
+
# change to "your-username/the-name-you-picked"
|
| 41 |
+
|
| 42 |
+
def transcribe(audio):
|
| 43 |
+
text = pipe(audio)['text']
|
| 44 |
+
return text
|
| 45 |
+
|
| 46 |
+
iface = gr.Interface(
|
| 47 |
+
fn=transcribe,
|
| 48 |
+
inputs=gr.Audio(source='microphone', type="filepath"),
|
| 49 |
+
outputs="text",
|
| 50 |
+
title="Whisper Small Galician",
|
| 51 |
+
description="Realtime demo for Galician speech recognition using a fine-tuned Whisper small model.",
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
iface.launch(debug=True)
|
| 55 |
+
|
| 56 |
+
# TO TRY
|
| 57 |
+
|