Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
|
@@ -89,14 +89,22 @@ def processFile(filePath):
|
|
| 89 |
global gainWindow
|
| 90 |
global minimumGain
|
| 91 |
global maximumGain
|
|
|
|
| 92 |
waveformList, sampleRate = su.splitIntoTimeSegments(filePath)
|
|
|
|
| 93 |
enhancedWaveformList = []
|
|
|
|
| 94 |
for w in waveformList:
|
| 95 |
newW = enhance(dfModel,dfState,w,atten_lim_db=attenLimDB)#.detach().cpu()
|
| 96 |
enhancedWaveformList.append(newW)
|
|
|
|
| 97 |
waveformEnhanced = su.combineWaveforms(enhancedWaveformList)
|
|
|
|
| 98 |
waveform_gain_adjusted = su.equalizeVolume()(waveformEnhanced,sampleRate,gainWindow,minimumGain,maximumGain)
|
|
|
|
|
|
|
| 99 |
annotations = pipeline({"waveform": waveformEnhanced, "sample_rate": sampleRate})
|
|
|
|
| 100 |
speakerList = su.annotationToSpeakerList(annotations)
|
| 101 |
return (speakerList, annotations, int(waveformEnhanced.shape[-1]/sampleRate))
|
| 102 |
|
|
@@ -113,6 +121,7 @@ audio_tabs = []
|
|
| 113 |
temp_dir = tempfile.mkdtemp()
|
| 114 |
|
| 115 |
if uploaded_file_paths is not None:
|
|
|
|
| 116 |
valid_files = []
|
| 117 |
file_paths = []
|
| 118 |
audio_tabs = []
|
|
@@ -122,6 +131,7 @@ if uploaded_file_paths is not None:
|
|
| 122 |
st.error('File must be of type: {}'.format(supported_file_types))
|
| 123 |
uploaded_file = None
|
| 124 |
else:
|
|
|
|
| 125 |
if uploaded_file not in valid_files:
|
| 126 |
path = os.path.join(temp_dir, uploaded_file.name)
|
| 127 |
with open(path, "wb") as f:
|
|
@@ -141,6 +151,7 @@ if st.button("Analyze All Audio",key=f"button_all"):
|
|
| 141 |
if len(valid_files) == 0:
|
| 142 |
st.error('Upload file(s) first!')
|
| 143 |
else:
|
|
|
|
| 144 |
start_time = time.time()
|
| 145 |
totalFiles = len(valid_files)
|
| 146 |
for i in range(totalFiles):
|
|
|
|
| 89 |
global gainWindow
|
| 90 |
global minimumGain
|
| 91 |
global maximumGain
|
| 92 |
+
print("Loading file")
|
| 93 |
waveformList, sampleRate = su.splitIntoTimeSegments(filePath)
|
| 94 |
+
print("File loaded")
|
| 95 |
enhancedWaveformList = []
|
| 96 |
+
print("Denoising")
|
| 97 |
for w in waveformList:
|
| 98 |
newW = enhance(dfModel,dfState,w,atten_lim_db=attenLimDB)#.detach().cpu()
|
| 99 |
enhancedWaveformList.append(newW)
|
| 100 |
+
print("Audio denoised")
|
| 101 |
waveformEnhanced = su.combineWaveforms(enhancedWaveformList)
|
| 102 |
+
print("Equalizing Audio")
|
| 103 |
waveform_gain_adjusted = su.equalizeVolume()(waveformEnhanced,sampleRate,gainWindow,minimumGain,maximumGain)
|
| 104 |
+
print("Audio Equalized")
|
| 105 |
+
print("Detecting speakers")
|
| 106 |
annotations = pipeline({"waveform": waveformEnhanced, "sample_rate": sampleRate})
|
| 107 |
+
print("Speakers Detected")
|
| 108 |
speakerList = su.annotationToSpeakerList(annotations)
|
| 109 |
return (speakerList, annotations, int(waveformEnhanced.shape[-1]/sampleRate))
|
| 110 |
|
|
|
|
| 121 |
temp_dir = tempfile.mkdtemp()
|
| 122 |
|
| 123 |
if uploaded_file_paths is not None:
|
| 124 |
+
print("Found file paths")
|
| 125 |
valid_files = []
|
| 126 |
file_paths = []
|
| 127 |
audio_tabs = []
|
|
|
|
| 131 |
st.error('File must be of type: {}'.format(supported_file_types))
|
| 132 |
uploaded_file = None
|
| 133 |
else:
|
| 134 |
+
print(f"Valid file: {uploaded_file.name}")
|
| 135 |
if uploaded_file not in valid_files:
|
| 136 |
path = os.path.join(temp_dir, uploaded_file.name)
|
| 137 |
with open(path, "wb") as f:
|
|
|
|
| 151 |
if len(valid_files) == 0:
|
| 152 |
st.error('Upload file(s) first!')
|
| 153 |
else:
|
| 154 |
+
print("Start analyzing")
|
| 155 |
start_time = time.time()
|
| 156 |
totalFiles = len(valid_files)
|
| 157 |
for i in range(totalFiles):
|