ish717 commited on
Commit
457abb4
·
verified ·
1 Parent(s): 0dc90fd

Added transcribe

Browse files
Files changed (1) hide show
  1. app.py +32 -2
app.py CHANGED
@@ -1,4 +1,34 @@
1
  import streamlit as st
 
 
2
 
3
- x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import whisper
3
+ import os
4
 
5
+ # Load the Whisper model
6
+ model = whisper.load_model("base") # You can choose "tiny", "small", "medium", or "large"
7
+
8
+ def transcribe_audio(audio_file):
9
+ # Save the uploaded audio file to a temporary location
10
+ temp_file_path = "temp_audio.wav"
11
+ with open(temp_file_path, "wb") as f:
12
+ f.write(audio_file.getbuffer())
13
+
14
+ # Transcribe the audio
15
+ result = model.transcribe(temp_file_path)
16
+ os.remove(temp_file_path) # Clean up the temporary file
17
+ return result['text']
18
+
19
+ # Streamlit app layout
20
+ st.title("Audio Transcription App")
21
+ st.write("Upload an audio file to transcribe it using Whisper.")
22
+
23
+ # File uploader for audio files
24
+ audio_file = st.file_uploader("Choose an audio file", type=["wav", "mp3", "m4a"])
25
+
26
+ if audio_file is not None:
27
+ st.audio(audio_file, format='audio/wav')
28
+
29
+ # Transcribe the audio when the button is clicked
30
+ if st.button("Transcribe"):
31
+ with st.spinner("Transcribing..."):
32
+ transcription = transcribe_audio(audio_file)
33
+ st.success("Transcription complete!")
34
+ st.text_area("Transcription:", transcription, height=300)