Spaces:
Runtime error
Runtime error
Hendrik Schroeter commited on
Commit ·
b64ea7b
1
Parent(s): 9b336fb
Update to df3, improve cleanup
Browse files2 unmodified lines345667899 unmodified lines192021222223242574 unmodified lines10010110210310310410510640 unmodified lines14714814915015115215315415515615715815915015115215315415515694 unmodified lines25125225325425525625725825926026126226326426526626726826957 unmodified lines3273283293233303312 unmodified linesimport osimport tempfileimport timefrom typing import Optional, Tuple, Unionfrom typing import List, Optional, Tuple, Union
import gradio as grimport matplotlib.pyplot as plt9 unmodified linesfrom df.io import resample
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")model, df, _ = init_df("./DeepFilterNet2", config_allow_defaults=True)model, df, _ = init_df(config_allow_defaults=True)model = model.to(device=device).eval()
fig_noisy: plt.Figure74 unmodified lines return audio, meta
def demo_fn(speech_upl: str, noise_type: str, snr: int, mic_input: str):def demo_fn(speech_upl: str, noise_type: str, snr: int, mic_input: Optional[str] = None): if mic_input: speech_upl = mic_input sr = config("sr", 48000, int, section="df")40 unmodified lines ax_enh.clear() noisy_im = spec_im(sample, sr=sr, figure=fig_noisy, ax=ax_noisy) enh_im = spec_im(enhanced, sr=sr, figure=fig_enh, ax=ax_enh) # Cleanup some old wav files if os.path.exists("/tmp"): days = 1 for f in glob.glob("/tmp/*wav"): is_old = (time.time() - os.path.getmtime(f)) / 3600 > 24 * days if is_old and f not in (enhanced_wav, noisy_wav): try: os.remove(f) except Exception as e: print(f"failed to remove file {f}: {e}") filter = [speech_upl, noisy_wav, enhanced_wav] if mic_input is not None and mic_input != "": filter.append(mic_input) cleanup_tmp(filter) return noisy_wav, noisy_im, enhanced_wav, enh_im
94 unmodified lines return Image.frombytes("RGB", figure.canvas.get_width_height(), figure.canvas.tostring_rgb())
def cleanup_tmp(filter: List[str] = [], hours_keep=2): # Cleanup some old wav files if os.path.exists("/tmp"): for f in glob.glob("/tmp/*"): is_old = (time.time() - os.path.getmtime(f)) / 3600 > hours_keep if is_old and f not in filter: try: os.remove(f) logger.info(f"Removed file {f}") except Exception as e: logger.warning(f"failed to remove file {f}: {e}")
def toggle(choice): if choice == "mic": return gr.update(visible=True, value=None), gr.update(visible=False, value=None)57 unmodified lines ), gr.Markdown(open("usage.md").read())
cleanup_tmp()demo.launch(enable_queue=True)app.py+21-14