Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
import torch
|
4 |
+
|
5 |
+
# Load the Whisper model
|
6 |
+
model_id = "openai/whisper-tiny.en"
|
7 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
8 |
+
pipe = pipeline("automatic-speech-recognition", model=model_id, device=device)
|
9 |
+
|
10 |
+
def transcribe_audio(audio_file):
|
11 |
+
# Read audio file
|
12 |
+
audio_bytes = audio_file.read()
|
13 |
+
# Get transcription results
|
14 |
+
results = pipe(audio_bytes)
|
15 |
+
# Return the transcription
|
16 |
+
return results
|
17 |
+
|
18 |
+
# Streamlit interface
|
19 |
+
st.title("Speech to Text with Whisper")
|
20 |
+
audio_file = st.file_uploader("Upload an audio file", type=['wav', 'mp3', 'ogg'])
|
21 |
+
|
22 |
+
if audio_file is not None:
|
23 |
+
# Display a button to transcribe the audio
|
24 |
+
if st.button('Transcribe'):
|
25 |
+
with st.spinner(f'Transcribing audio...'):
|
26 |
+
transcription = transcribe_audio(audio_file)
|
27 |
+
st.text_area("Transcription", transcription['text'], height=150)
|