tufailnewuse commited on
Commit
bbafd1c
·
verified ·
1 Parent(s): 373aa9e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+ import soundfile as sf
4
+ import tempfile
5
+
6
+ # Load the ASR model from Hugging Face
7
+ @st.cache_resource
8
+ def load_model():
9
+ # Use Hugging Face's pipeline with your desired model
10
+ return pipeline("automatic-speech-recognition", model="fractalego/personal-speech-to-text-model")
11
+
12
+ # Initialize the model pipeline
13
+ pipe = load_model()
14
+
15
+ # Streamlit UI
16
+ st.title("Speech-to-Text Transcription App")
17
+ st.write("Upload an audio file, and the AI model will transcribe it.")
18
+
19
+ # Upload audio file
20
+ uploaded_file = st.file_uploader("Choose an audio file", type=["wav", "mp3", "m4a"])
21
+
22
+ if uploaded_file is not None:
23
+ st.audio(uploaded_file, format='audio/wav')
24
+
25
+ # Save uploaded file to a temporary location
26
+ with tempfile.NamedTemporaryFile(delete=False) as temp_file:
27
+ temp_file.write(uploaded_file.read())
28
+ temp_file_path = temp_file.name
29
+
30
+ # Read the audio file and transcribe
31
+ with st.spinner("Transcribing... Please wait..."):
32
+ transcription = pipe(temp_file_path)
33
+
34
+ # Display the transcription result
35
+ st.subheader("Transcription")
36
+ st.write(transcription['text'])
37
+
38
+ else:
39
+ st.info("Please upload an audio file to start transcription.")