phuntshowangdi
commited on
Commit
•
ca805e0
1
Parent(s):
b6eecda
Update app.py
Browse files
app.py
CHANGED
@@ -1,47 +1,46 @@
|
|
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 |
def main():
|
26 |
-
st.title("
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
st.
|
39 |
-
st.write(
|
40 |
-
|
41 |
-
st.subheader("Similarity Score")
|
42 |
-
st.write(f"{similarity_score:.2f}")
|
43 |
else:
|
44 |
-
st.warning("Please
|
45 |
|
46 |
if __name__ == "__main__":
|
47 |
main()
|
|
|
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 speech recognition pipeline
|
9 |
+
asr = pipeline(task="automatic-speech-recognition",
|
10 |
+
model="facebook/wav2vec2-base-960h")
|
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 |
+
audio_input = audio_file.read()
|
20 |
+
output = asr(audio_input)
|
21 |
+
return output[0]['transcription']
|
22 |
+
except Exception as e:
|
23 |
+
logging.error(f"Error during transcription: {str(e)}")
|
24 |
+
return f"Error processing the audio file: {str(e)}"
|
25 |
+
|
26 |
+
# Streamlit app UI
|
27 |
def main():
|
28 |
+
st.title("Simple Speech Recognition App")
|
29 |
+
st.write("### This app allows you to record or upload audio and see its transcription.")
|
30 |
+
|
31 |
+
# Upload audio file or record from microphone
|
32 |
+
audio_file = st.file_uploader("Upload Audio File", type=["wav", "mp3"])
|
33 |
+
if audio_file:
|
34 |
+
st.audio(audio_file, format='audio/wav')
|
35 |
+
|
36 |
+
# Button to transcribe audio
|
37 |
+
if st.button("Transcribe Audio"):
|
38 |
+
if audio_file:
|
39 |
+
transcription = transcribe_speech(audio_file)
|
40 |
+
st.write("### Transcription:")
|
41 |
+
st.write(transcription)
|
|
|
|
|
|
|
42 |
else:
|
43 |
+
st.warning("Please upload an audio file first.")
|
44 |
|
45 |
if __name__ == "__main__":
|
46 |
main()
|