Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
import torchaudio
|
| 4 |
+
from df import enhance, init_df
|
| 5 |
+
|
| 6 |
+
# Initialize DeepFilterNet model
|
| 7 |
+
model, df_state, _ = init_df()
|
| 8 |
+
|
| 9 |
+
def denoise_audio(audio):
|
| 10 |
+
# Load the input audio file
|
| 11 |
+
waveform, sample_rate = torchaudio.load(audio)
|
| 12 |
+
|
| 13 |
+
# Denoise the audio
|
| 14 |
+
enhanced_audio = enhance(model, df_state, waveform)
|
| 15 |
+
|
| 16 |
+
# Save and return the enhanced audio file
|
| 17 |
+
output_file = "enhanced_output.wav"
|
| 18 |
+
torchaudio.save(output_file, enhanced_audio, sample_rate)
|
| 19 |
+
|
| 20 |
+
return output_file
|
| 21 |
+
|
| 22 |
+
# Gradio interface
|
| 23 |
+
iface = gr.Interface(
|
| 24 |
+
fn=denoise_audio,
|
| 25 |
+
inputs=gr.Audio(source="upload", type="filepath"),
|
| 26 |
+
outputs="file",
|
| 27 |
+
title="DeepFilterNet Audio Denoising",
|
| 28 |
+
description="Upload an audio file to remove noise using DeepFilterNet."
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
iface.launch()
|