zeimoto commited on
Commit
b7a06a7
·
verified ·
1 Parent(s): 339f108

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -1,9 +1,6 @@
1
  import streamlit as st
2
  from st_audiorec import st_audiorec
3
 
4
- import librosa
5
- import soundfile
6
-
7
  from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
8
  from datasets import load_dataset
9
  import torch
@@ -14,26 +11,29 @@ audio_transcription: str = None
14
 
15
  def main ():
16
 
 
 
17
  print("Run init model")
18
  pipe = init_model()
19
  # x = st.slider('Select a value')
20
  # st.write(x, 'squared is', x * x)
21
 
 
22
  print("Render UI")
23
  wav_audio_data = st_audiorec()
24
 
25
  if wav_audio_data is not None:
 
26
  st.audio(wav_audio_data, format='audio/wav')
 
 
 
27
 
28
- print("Load data: audio1")
29
  # dataset = load_dataset("distil-whisper/librispeech_long", "clean", split="validation")
30
  # sample = dataset[0]["audio"]
31
 
32
- audio_file_path = "data/audio1.wav"
33
- audio_data, sample_rate = librosa.load(audio_file_path)
34
- sample = transcribe(audio_data, pipe)
35
- st.write('Sample:', transcribe(sample))
36
-
37
 
38
  def init_model ():
39
  device = "cuda:0" if torch.cuda.is_available() else "cpu"
@@ -62,7 +62,10 @@ def init_model ():
62
  )
63
  print(f'Init model successful: {model}' )
64
  return pipe
 
 
65
 
 
66
  def transcribe (audio_sample: bytes, pipe) -> str:
67
 
68
  # dataset = load_dataset("distil-whisper/librispeech_long", "clean", split="validation")
 
1
  import streamlit as st
2
  from st_audiorec import st_audiorec
3
 
 
 
 
4
  from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
5
  from datasets import load_dataset
6
  import torch
 
11
 
12
  def main ():
13
 
14
+ print("Run init model")
15
+ pipe = init_model()
16
  print("Run init model")
17
  pipe = init_model()
18
  # x = st.slider('Select a value')
19
  # st.write(x, 'squared is', x * x)
20
 
21
+ print("Render UI")
22
  print("Render UI")
23
  wav_audio_data = st_audiorec()
24
 
25
  if wav_audio_data is not None:
26
+ print("Loading data...")
27
  st.audio(wav_audio_data, format='audio/wav')
28
+ sample = transcribe(wav_audio_data, pipe)
29
+ st.write('Sample:', sample)
30
+
31
 
32
+
33
  # dataset = load_dataset("distil-whisper/librispeech_long", "clean", split="validation")
34
  # sample = dataset[0]["audio"]
35
 
36
+ # audio_file_path = "data/audio1.wav"
 
 
 
 
37
 
38
  def init_model ():
39
  device = "cuda:0" if torch.cuda.is_available() else "cpu"
 
62
  )
63
  print(f'Init model successful: {model}' )
64
  return pipe
65
+ print(f'Init model successful: {model}' )
66
+ return pipe
67
 
68
+ def transcribe (audio_sample: bytes, pipe) -> str:
69
  def transcribe (audio_sample: bytes, pipe) -> str:
70
 
71
  # dataset = load_dataset("distil-whisper/librispeech_long", "clean", split="validation")