Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,33 +1,46 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from df.enhance import enhance, init_df, load_audio, save_audio
|
|
|
|
| 3 |
import torch
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
# Model
|
|
|
|
| 6 |
model, df_state, _ = init_df()
|
| 7 |
|
| 8 |
def enhance_audio(audio_path):
|
| 9 |
if audio_path is None:
|
| 10 |
return None
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
# Interface
|
| 25 |
iface = gr.Interface(
|
| 26 |
fn=enhance_audio,
|
| 27 |
inputs=gr.Audio(type="filepath", label="Upload Noisy Audio"),
|
| 28 |
-
outputs=gr.Audio(type="filepath", label="Clean Voice"),
|
| 29 |
-
title="AI Voice
|
| 30 |
-
description="
|
| 31 |
)
|
| 32 |
|
| 33 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from df.enhance import enhance, init_df, load_audio, save_audio
|
| 3 |
+
from df.io import load_audio as load_audio_df # Name clash bachane ke liye
|
| 4 |
import torch
|
| 5 |
+
import numpy as np
|
| 6 |
+
import tempfile
|
| 7 |
+
import os
|
| 8 |
|
| 9 |
+
# 1. Model Load karein
|
| 10 |
+
# config_allow_defaults=True se minor errors ignore ho jate hain
|
| 11 |
model, df_state, _ = init_df()
|
| 12 |
|
| 13 |
def enhance_audio(audio_path):
|
| 14 |
if audio_path is None:
|
| 15 |
return None
|
| 16 |
|
| 17 |
+
try:
|
| 18 |
+
# 2. Audio Load karein
|
| 19 |
+
# df_state.sr() model ka required sample rate (48kHz) deta hai
|
| 20 |
+
audio, _ = load_audio_df(audio_path, sr=df_state.sr())
|
| 21 |
+
|
| 22 |
+
# 3. Enhance (Noise Reduction)
|
| 23 |
+
# Model CPU par hi run karega kyunki init_df default wahi karta hai
|
| 24 |
+
enhanced_audio = enhance(model, df_state, audio)
|
| 25 |
+
|
| 26 |
+
# 4. Output Save karein (Temp file banana safe rehta hai)
|
| 27 |
+
# Hugging Face par static naam ("enhanced.wav") kabhi kabhi permission error deta hai
|
| 28 |
+
output_file = tempfile.NamedTemporaryFile(suffix=".wav", delete=False).name
|
| 29 |
+
save_audio(output_file, enhanced_audio, df_state.sr())
|
| 30 |
+
|
| 31 |
+
return output_file
|
| 32 |
+
|
| 33 |
+
except Exception as e:
|
| 34 |
+
print(f"Error aa gaya: {e}")
|
| 35 |
+
return None
|
| 36 |
|
| 37 |
+
# Interface Setup
|
| 38 |
iface = gr.Interface(
|
| 39 |
fn=enhance_audio,
|
| 40 |
inputs=gr.Audio(type="filepath", label="Upload Noisy Audio"),
|
| 41 |
+
outputs=gr.Audio(type="filepath", label="Clean Voice Output"),
|
| 42 |
+
title="AI Voice Cleaner (DeepFilterNet)",
|
| 43 |
+
description="Yeh tool background noise (pankha, traffic) hatata hai using CPU."
|
| 44 |
)
|
| 45 |
|
| 46 |
iface.launch()
|