Spaces:
Running
Running
File size: 2,045 Bytes
ab37518 81154bc 86bfe69 6b92a8b ab37518 a628e27 6077ed1 1ebc568 6077ed1 1ebc568 a628e27 1ebc568 a628e27 1ebc568 6077ed1 1ebc568 6077ed1 1ebc568 a628e27 ab37518 a628e27 ab37518 a628e27 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | FROM python:3.10-slim
WORKDIR /app
RUN apt-get update && apt-get install -y ffmpeg libsndfile1 git && rm -rf /var/lib/apt/lists/*
RUN pip install --no-cache-dir --extra-index-url https://download.pytorch.org/whl/cpu torch torchaudio
RUN pip install --no-cache-dir deepfilternet gradio soundfile
RUN cat <<'EOF' > /app/app.py
import sys, types
import numpy as np
import soundfile as sf
import torch
class AudioMetaData:
pass
m = types.ModuleType("torchaudio.backend.common")
m.AudioMetaData = AudioMetaData
sys.modules.setdefault("torchaudio.backend", types.ModuleType("torchaudio.backend"))
sys.modules["torchaudio.backend.common"] = m
import torchaudio as ta
def _ta_info(file, **kwargs):
info = sf.info(file)
return types.SimpleNamespace(
sample_rate=info.samplerate,
num_frames=info.frames,
num_channels=info.channels,
bits_per_sample=16,
encoding="PCM_S",
)
def _ta_load(filepath, **kwargs):
data, sr = sf.read(filepath, dtype="float32", always_2d=True)
tensor = torch.from_numpy(data.T)
return tensor, sr
def _ta_save(filepath, src, sample_rate, **kwargs):
arr = src.detach().cpu().numpy()
if arr.ndim == 2:
arr = arr.T
sf.write(filepath, arr, sample_rate)
ta.info = _ta_info
ta.load = _ta_load
ta.save = _ta_save
import gradio as gr
from df.enhance import enhance, init_df, load_audio, save_audio
model, df_state, _ = init_df()
def denoise(audio_path):
if not audio_path:
return None
audio, _ = load_audio(audio_path, sr=df_state.sr())
enhanced = enhance(model, df_state, audio)
out_path = "/app/cleaned.wav"
save_audio(out_path, enhanced, df_state.sr())
return out_path
demo = gr.Interface(
fn=denoise,
inputs=gr.Audio(type="filepath", label="Input Audio"),
outputs=gr.Audio(type="filepath", label="Cleaned Audio"),
title="DeepFilterNet Audio Denoiser"
)
if __name__ == "__main__":
demo.launch(server_name="0.0.0.0", server_port=7860)
EOF
EXPOSE 7860
CMD ["python", "/app/app.py"]
|