cdleong commited on
Commit
73363ec
·
1 Parent(s): d3a2cef

Cleanup results for many uploads

Browse files
Files changed (1) hide show
  1. app.py +9 -12
app.py CHANGED
@@ -21,7 +21,7 @@ def get_supported_codes():
21
  return supported_codes
22
 
23
 
24
- def get_path_to_wav_format(uploaded_file):
25
  # st.write(dir(uploaded_file))
26
  # st.write(type(uploaded_file))
27
  # st.write(uploaded_file)
@@ -36,9 +36,10 @@ def get_path_to_wav_format(uploaded_file):
36
  new_desired_path = actual_file_path.with_suffix(".wav")
37
  encoding="PCM_S" # Prevent encoding errors. https://stackoverflow.com/questions/60352850/wave-error-unknown-format-3-arises-when-trying-to-convert-a-wav-file-into-text
38
  bits_per_sample=16
39
- st.info(f"Allosaurus requires .wav files. Converting with torchaudio, encoding={encoding}, bits_per_sample={bits_per_sample}")
40
  waveform, sample_rate = torchaudio.load(actual_file_path)
41
- st.info(f"Uploaded file sample_rate: {sample_rate}")
 
 
42
  torchaudio.save(new_desired_path, waveform, sample_rate,
43
  encoding=encoding,
44
  bits_per_sample=bits_per_sample,
@@ -99,18 +100,14 @@ if __name__ == "__main__":
99
  )
100
 
101
  results = {} # for better download/display
 
 
 
102
  for uploaded_file in uploaded_files:
103
 
104
- if uploaded_file is not None:
105
-
106
-
107
-
108
- st.audio(uploaded_file, format='audio/wav')
109
-
110
- wav_file = get_path_to_wav_format(uploaded_file)
111
- # st.write(wav_file)
112
  result = model.recognize(wav_file, langcode)
113
  results[uploaded_file.name] = result
114
- # st.write(result)
115
 
116
  st.write(results)
 
21
  return supported_codes
22
 
23
 
24
+ def get_path_to_wav_format(uploaded_file, suppress_outputs=False):
25
  # st.write(dir(uploaded_file))
26
  # st.write(type(uploaded_file))
27
  # st.write(uploaded_file)
 
36
  new_desired_path = actual_file_path.with_suffix(".wav")
37
  encoding="PCM_S" # Prevent encoding errors. https://stackoverflow.com/questions/60352850/wave-error-unknown-format-3-arises-when-trying-to-convert-a-wav-file-into-text
38
  bits_per_sample=16
 
39
  waveform, sample_rate = torchaudio.load(actual_file_path)
40
+ if not suppress_outputs:
41
+ st.info(f"Allosaurus requires .wav files. Converting with torchaudio, encoding={encoding}, bits_per_sample={bits_per_sample}")
42
+ st.info(f"Uploaded file sample_rate: {sample_rate}")
43
  torchaudio.save(new_desired_path, waveform, sample_rate,
44
  encoding=encoding,
45
  bits_per_sample=bits_per_sample,
 
100
  )
101
 
102
  results = {} # for better download/display
103
+
104
+ uploaded_files_count = len(uploaded_files)
105
+ suppress_output_threshold = 2
106
  for uploaded_file in uploaded_files:
107
 
108
+ if uploaded_file is not None:
109
+ wav_file = get_path_to_wav_format(uploaded_file, uploaded_files_count>suppress_output_threshold)
 
 
 
 
 
 
110
  result = model.recognize(wav_file, langcode)
111
  results[uploaded_file.name] = result
 
112
 
113
  st.write(results)