roman commited on
Commit
c1dd4e9
·
1 Parent(s): 33b3376

change app for whisper testing

Browse files
Files changed (1) hide show
  1. app.py +25 -23
app.py CHANGED
@@ -1,32 +1,34 @@
1
- # import streamlit as st
2
- #
3
- # x = st.slider('Select a value')
4
- # st.write(x, 'squared is', x * x)
5
-
6
-
7
  import streamlit as st
8
- from transformers import pipeline
 
 
 
 
 
9
 
10
- st.write("Starting the app")
11
 
12
- # Load a pre-trained pipeline for text generation
13
- generator = pipeline('text-generation', model='gpt2')
14
 
15
- st.title('Simple Hugging Face Space with Streamlit')
 
16
 
17
- # Text input widget
18
- input_text = st.text_area('Enter your text here:', '')
 
 
 
19
 
20
- if st.button('Generate'):
21
- if input_text:
22
- # Generate text using the model
23
- outputs = generator(input_text, max_length=50, num_return_sequences=1)
24
- st.write('Generated Text:')
25
- st.write(outputs[0]['generated_text'])
26
- else:
27
- st.write('Please enter some text to generate.')
28
 
29
- # if __name__ == '__main__':
30
- # st.title('ACR')
31
 
 
32
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import whisper
3
+ import tempfile
4
+ from pydub import AudioSegment
5
+
6
+ # Load the Whisper model
7
+ model = whisper.load_model("base")
8
 
9
+ st.title("Voice Recognition App using Whisper")
10
 
11
+ st.write("Upload an audio file and the Whisper model will transcribe it to text.")
 
12
 
13
+ # File uploader for audio file
14
+ uploaded_file = st.file_uploader("Choose an audio file", type=["wav", "mp3", "m4a"])
15
 
16
+ if uploaded_file is not None:
17
+ # Save the uploaded file temporarily
18
+ with tempfile.NamedTemporaryFile(delete=False) as temp_file:
19
+ temp_file.write(uploaded_file.read())
20
+ temp_file_path = temp_file.name
21
 
22
+ # Convert audio file to a format supported by Whisper (if necessary)
23
+ audio = AudioSegment.from_file(temp_file_path)
24
+ temp_wav_path = tempfile.mktemp(suffix=".wav")
25
+ audio.export(temp_wav_path, format="wav")
 
 
 
 
26
 
27
+ st.audio(uploaded_file, format="audio/wav")
 
28
 
29
+ st.write("Transcribing audio...")
30
 
31
+ # Transcribe audio using Whisper model
32
+ result = model.transcribe(temp_wav_path)
33
+ st.write("Transcription:")
34
+ st.write(result["text"])