a / Dockerfile
nirkyy's picture
Update Dockerfile
6077ed1 verified
Raw History Blame Contribute Delete
2.05 kB
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"]