Spaces:
Runtime error
Runtime error
Commit
·
470a6ad
1
Parent(s):
1644496
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,26 +1,39 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import librosa
|
| 3 |
-
import io
|
| 4 |
-
from IPython.display import Audio
|
| 5 |
from transformers import pipeline
|
| 6 |
-
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
audio = np.frombuffer(audio['data'], dtype=np.int16)
|
| 12 |
-
librosa.output.write_wav('audio_input.wav', audio, 16000)
|
| 13 |
-
y, sr = librosa.load('audio_input.wav', sr=None)
|
| 14 |
-
result = transcription(y)
|
| 15 |
|
| 16 |
-
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
outputs = 'text'
|
| 24 |
)
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
+
pipe = pipeline('automatic-speech-recognition', model='openai/whisper-small')
|
| 3 |
|
| 4 |
+
def transcribe_speech(filepath):
|
| 5 |
+
output = pipe(
|
| 6 |
+
filepath,
|
| 7 |
+
max_new_tokens=256,
|
| 8 |
+
generate_kwargs={
|
| 9 |
+
"task": "transcribe",
|
| 10 |
+
"language": "english",
|
| 11 |
+
},
|
| 12 |
+
chunk_length_s=30,
|
| 13 |
+
batch_size=8,
|
| 14 |
+
)
|
| 15 |
+
return output["text"]
|
| 16 |
|
| 17 |
+
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
demo = gr.Blocks()
|
| 20 |
|
| 21 |
+
mic_transcribe = gr.Interface(
|
| 22 |
+
fn=transcribe_speech,
|
| 23 |
+
inputs=gr.Audio(sources="microphone", type="filepath"),
|
| 24 |
+
outputs='text',
|
| 25 |
+
)
|
| 26 |
|
| 27 |
+
file_transcribe = gr.Interface(
|
| 28 |
+
fn=transcribe_speech,
|
| 29 |
+
inputs=gr.Audio(sources="upload", type="filepath"),
|
| 30 |
+
outputs='text',
|
|
|
|
| 31 |
)
|
| 32 |
|
| 33 |
+
with demo:
|
| 34 |
+
gr.TabbedInterface(
|
| 35 |
+
[mic_transcribe, file_transcribe],
|
| 36 |
+
["Transcribe Microphone", "Transcribe Audio File"],
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
demo.launch()
|