Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
import numpy as np
|
| 4 |
+
import soundfile as sf
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
pipe1 = pipeline("automatic-speech-recognition", model="openai/whisper-base")
|
| 8 |
+
|
| 9 |
+
def transcribe_audio(audio):
|
| 10 |
+
audio_data, _ = sf.read(audio) # Load audio file
|
| 11 |
+
audio_array = np.array(audio_data) # Convert to numpy array
|
| 12 |
+
|
| 13 |
+
transcription = pipe1(audio_array)
|
| 14 |
+
transcription_text = transcription['text']
|
| 15 |
+
|
| 16 |
+
return transcription_text
|
| 17 |
+
|
| 18 |
+
# Gradio interface
|
| 19 |
+
demo = gr.Interface(fn=transcribe_audio, inputs=gr.Audio(source="microphone", type="filepath"), outputs="text")
|
| 20 |
+
demo.launch(share=True)
|