Commit
•
5ca36ec
1
Parent(s):
eb91cf4
Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +1,37 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
|
|
1 |
import streamlit as st
|
2 |
+
import logging
|
3 |
+
from transformers import pipeline
|
4 |
+
|
5 |
+
# Setup logging
|
6 |
+
logging.basicConfig(level=logging.INFO)
|
7 |
+
|
8 |
+
# Load automatic speech recognition (ASR) pipeline
|
9 |
+
asr = pipeline(task="automatic-speech-recognition",
|
10 |
+
model="distil-whisper/distil-small.en")
|
11 |
+
|
12 |
+
# Function for transcribing speech
|
13 |
+
def transcribe_speech(audio_file):
|
14 |
+
if not audio_file:
|
15 |
+
logging.error("No audio file provided.")
|
16 |
+
return "No audio found, please retry."
|
17 |
+
try:
|
18 |
+
logging.info(f"Processing file: {audio_file.name}")
|
19 |
+
output = asr(audio_file.name) # Assuming `asr` directly takes a file path
|
20 |
+
return output[0]["transcription"]
|
21 |
+
except Exception as e:
|
22 |
+
logging.error(f"Error during transcription: {str(e)}")
|
23 |
+
return f"Error processing the audio file: {str(e)}"
|
24 |
+
|
25 |
+
# Streamlit UI
|
26 |
+
st.title("Speech Recognition")
|
27 |
+
|
28 |
+
uploaded_file = st.file_uploader("Upload audio file", type=["wav", "mp3"])
|
29 |
+
|
30 |
+
if uploaded_file:
|
31 |
+
st.audio(uploaded_file, format='audio/wav')
|
32 |
+
|
33 |
+
if st.button("Transcribe Audio"):
|
34 |
+
transcription = transcribe_speech(uploaded_file)
|
35 |
+
st.write("Transcription:")
|
36 |
+
st.write(transcription)
|
37 |
|