taham655 commited on
Commit
45aff15
1 Parent(s): b0197ca
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ import whisper
4
+ import soundfile as sf
5
+
6
+ # Assuming you have your .env file configured with necessary API keys or configurations
7
+ # load_dotenv()
8
+
9
+ # Initialize the model outside the main app function to load it only once
10
+ model = whisper.load_model("base")
11
+
12
+ def transcribe_audio(audio_file):
13
+ # Save the audio file to a temporary file
14
+ with open("temp_audio_file", "wb") as f:
15
+ f.write(audio_file.getbuffer())
16
+
17
+ # Transcribe the audio file using the Whisper model
18
+ result = model.transcribe("temp_audio_file")
19
+ return result["text"]
20
+
21
+ # Streamlit app
22
+ def main():
23
+ st.title('USE ME TO TRANSCRIBE')
24
+
25
+ # Audio file uploader
26
+ uploaded_file = st.file_uploader("Upload an audio file", type=["wav", "mp3", "m4a", "ogg", "flac"])
27
+
28
+ if uploaded_file is not None:
29
+ # Show a button to start the transcription process
30
+ if st.button('Transcribe'):
31
+ # Show a message while transcribing
32
+ with st.spinner('Transcribing...'):
33
+ text = transcribe_audio(uploaded_file)
34
+
35
+ # Show the transcription
36
+ st.subheader('Transcription:')
37
+ st.write(text)
38
+ else:
39
+ st.write('Upload an audio file to get started.')
40
+
41
+ if __name__ == "__main__":
42
+ main()