Neal Caren commited on
Commit
19ccd4b
·
1 Parent(s): 1ac8b8b

Turned off logging and file now stored in temp dir.

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -5,7 +5,7 @@ import subprocess
5
  from simple_diarizer.diarizer import Diarizer
6
  import streamlit as st
7
  import base64
8
-
9
 
10
 
11
 
@@ -17,7 +17,7 @@ def create_download_link(val, filename, label):
17
  def segment(nu_speakers):
18
 
19
  diar = Diarizer(embed_model='ecapa',cluster_method='sc')
20
- segments = diar.diarize('mono.wav', num_speakers=nu_speakers)
21
 
22
  sdf = pd.DataFrame(segments)
23
 
@@ -31,14 +31,14 @@ def segment(nu_speakers):
31
  def audio_to_df(uploaded):
32
  monotize(uploaded)
33
  model = whisper.load_model(model_size)
34
- result = model.transcribe('mono.wav',verbose=True,
35
  without_timestamps=False,
36
  task = task)
37
  tdf = pd.DataFrame(result['segments'])
38
  return tdf
39
 
40
  def monotize(uploaded):
41
- cmd = f"ffmpeg -y -i {uploaded} -acodec pcm_s16le -ar 16000 -ac 1 mono.wav"
42
  subprocess.Popen(cmd, shell=True).wait()
43
 
44
  def add_preface(row):
@@ -50,7 +50,7 @@ def transcribe(uploaded, nu_speakers):
50
  with st.spinner(text="Converting file..."):
51
  monotize('temp_audio')
52
 
53
- audio_file = open('mono.wav', 'rb')
54
  audio_bytes = audio_file.read()
55
  st.audio('mono.wav', format='audio/wav')
56
 
@@ -124,6 +124,10 @@ if submit:
124
  else:
125
  task = 'transcribe'
126
 
 
 
 
 
127
  bytes_data = uploaded.getvalue()
128
  with open('temp_audio', 'wb') as outfile:
129
  outfile.write(bytes_data)
@@ -136,3 +140,4 @@ if submit:
136
 
137
  download_url = create_download_link(csv, 'transcript.csv', 'Download transcript as CSV (with time codes)')
138
  st.markdown(download_url, unsafe_allow_html=True)
 
 
5
  from simple_diarizer.diarizer import Diarizer
6
  import streamlit as st
7
  import base64
8
+ import tempfile
9
 
10
 
11
 
 
17
  def segment(nu_speakers):
18
 
19
  diar = Diarizer(embed_model='ecapa',cluster_method='sc')
20
+ segments = diar.diarize(temp_file, num_speakers=nu_speakers)
21
 
22
  sdf = pd.DataFrame(segments)
23
 
 
31
  def audio_to_df(uploaded):
32
  monotize(uploaded)
33
  model = whisper.load_model(model_size)
34
+ result = model.transcribe(temp_file,
35
  without_timestamps=False,
36
  task = task)
37
  tdf = pd.DataFrame(result['segments'])
38
  return tdf
39
 
40
  def monotize(uploaded):
41
+ cmd = f"ffmpeg -y -i {uploaded} -acodec pcm_s16le -ar 16000 -ac 1 {temp_file}"
42
  subprocess.Popen(cmd, shell=True).wait()
43
 
44
  def add_preface(row):
 
50
  with st.spinner(text="Converting file..."):
51
  monotize('temp_audio')
52
 
53
+ audio_file = open(temp_file, 'rb')
54
  audio_bytes = audio_file.read()
55
  st.audio('mono.wav', format='audio/wav')
56
 
 
124
  else:
125
  task = 'transcribe'
126
 
127
+ #temporary file to store audio_file
128
+ tmp_dir = tempfile.TemporaryDirectory()
129
+ temp_file = tmp_dir.name + '/mono.wav'
130
+
131
  bytes_data = uploaded.getvalue()
132
  with open('temp_audio', 'wb') as outfile:
133
  outfile.write(bytes_data)
 
140
 
141
  download_url = create_download_link(csv, 'transcript.csv', 'Download transcript as CSV (with time codes)')
142
  st.markdown(download_url, unsafe_allow_html=True)
143
+ tmp_dir.cleanup()