Spaces:
Sleeping
Sleeping
Bouaziz-bad
commited on
Commit
·
8a6c8ee
1
Parent(s):
86f8c42
Add audio transcription with Whisper
Browse files- README.md +15 -9
- app.py +41 -7
- example.wav +0 -0
README.md
CHANGED
|
@@ -1,11 +1,17 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
-
sdk:
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
---
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Audio Transcriber
|
| 3 |
+
emoji: 🎙️
|
| 4 |
+
colorFrom: green
|
| 5 |
+
colorTo: blue
|
| 6 |
+
sdk: gradio
|
| 7 |
+
app_file: app.py
|
| 8 |
+
python_version: "3.10"
|
| 9 |
+
short_description: Upload an audio file and get a transcription using Whisper.
|
| 10 |
+
tags:
|
| 11 |
+
- audio
|
| 12 |
+
- speech-to-text
|
| 13 |
+
- whisper
|
| 14 |
+
- transcription
|
| 15 |
+
models:
|
| 16 |
+
- openai/whisper-small
|
| 17 |
---
|
app.py
CHANGED
|
@@ -1,9 +1,43 @@
|
|
| 1 |
-
|
| 2 |
-
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from transformers import pipeline
|
| 4 |
|
| 5 |
+
# Load the Whisper model for speech recognition
|
| 6 |
+
device = 0 if torch.cuda.is_available() else -1
|
| 7 |
+
transcriber = pipeline(
|
| 8 |
+
"automatic-speech-recognition",
|
| 9 |
+
model="openai/whisper-small",
|
| 10 |
+
chunk_length_s=30,
|
| 11 |
+
device=device
|
| 12 |
+
)
|
| 13 |
|
| 14 |
+
def transcribe_audio(audio_file):
|
| 15 |
+
"""
|
| 16 |
+
Transcribe uploaded audio file.
|
| 17 |
+
Args:
|
| 18 |
+
audio_file (str): Path to the audio file
|
| 19 |
+
Returns:
|
| 20 |
+
str: Transcribed text
|
| 21 |
+
"""
|
| 22 |
+
if audio_file is None:
|
| 23 |
+
return "Please upload an audio file."
|
| 24 |
+
|
| 25 |
+
# Run transcription
|
| 26 |
+
result = transcriber(audio_file)
|
| 27 |
+
return result["text"]
|
| 28 |
+
|
| 29 |
+
# Define the Gradio interface
|
| 30 |
+
demo = gr.Interface(
|
| 31 |
+
fn=transcribe_audio,
|
| 32 |
+
inputs=gr.Audio(sources=["upload", "microphone"], type="filepath"),
|
| 33 |
+
outputs=gr.Textbox(label="Transcription", lines=8),
|
| 34 |
+
title="🎙️ Audio Transcription with Whisper",
|
| 35 |
+
description="Upload an audio file or record directly to transcribe it using OpenAI's Whisper model.",
|
| 36 |
+
examples=[
|
| 37 |
+
["example.wav"] # Optional: add a sample audio file named example.wav
|
| 38 |
+
],
|
| 39 |
+
allow_flagging="never"
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
# Launch the app
|
| 43 |
+
demo.launch()
|
example.wav
ADDED
|
Binary file (84.7 kB). View file
|
|
|