Spaces:
Running
Running
Hendrik Schroeter
commited on
Commit
·
42ea010
1
Parent(s):
031a5ff
Try to cleanup some stuff
Browse files
app.py
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
|
|
| 1 |
import math
|
|
|
|
| 2 |
import tempfile
|
|
|
|
| 3 |
from typing import Optional, Tuple, Union
|
| 4 |
|
| 5 |
import gradio as gr
|
|
@@ -144,8 +147,16 @@ def demo_fn(speech_upl: str, noise_type: str, snr: int, mic_input: str):
|
|
| 144 |
ax_enh.clear()
|
| 145 |
noisy_im = spec_im(sample, sr=sr, figure=fig_noisy, ax=ax_noisy)
|
| 146 |
enh_im = spec_im(enhanced, sr=sr, figure=fig_enh, ax=ax_enh)
|
| 147 |
-
#
|
| 148 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
return noisy_wav, noisy_im, enhanced_wav, enh_im
|
| 150 |
|
| 151 |
|
|
|
|
| 1 |
+
import glob
|
| 2 |
import math
|
| 3 |
+
import os
|
| 4 |
import tempfile
|
| 5 |
+
import time
|
| 6 |
from typing import Optional, Tuple, Union
|
| 7 |
|
| 8 |
import gradio as gr
|
|
|
|
| 147 |
ax_enh.clear()
|
| 148 |
noisy_im = spec_im(sample, sr=sr, figure=fig_noisy, ax=ax_noisy)
|
| 149 |
enh_im = spec_im(enhanced, sr=sr, figure=fig_enh, ax=ax_enh)
|
| 150 |
+
# Cleanup some old wav files
|
| 151 |
+
if os.path.exists("/tmp"):
|
| 152 |
+
days = 1
|
| 153 |
+
for f in glob.glob("/tmp/*wav"):
|
| 154 |
+
is_old = (time.time() - os.path.getmtime(f)) / 3600 > 24 * days
|
| 155 |
+
if is_old and f not in (enhanced_wav, noisy_wav):
|
| 156 |
+
try:
|
| 157 |
+
os.remove(f)
|
| 158 |
+
except Exception as e:
|
| 159 |
+
print(f"failed to remove file {f}: e")
|
| 160 |
return noisy_wav, noisy_im, enhanced_wav, enh_im
|
| 161 |
|
| 162 |
|