nirkyy commited on
Commit
d7ee9d8
·
verified ·
1 Parent(s): 6b92a8b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -19
app.py CHANGED
@@ -1,30 +1,26 @@
1
- import glob
2
  import os
 
3
  import gradio as gr
4
- from audio_separator.separator import Separator
 
5
 
6
- out_dir = "/tmp/out"
7
- os.makedirs(out_dir, exist_ok=True)
8
 
9
- separator = Separator(output_dir=out_dir)
10
- separator.load_model(model_filename="UVR-MDX-NET-Inst_HQ_3.onnx")
11
-
12
- def ambil_vokal(audio_file):
13
  if not audio_file:
14
  return None
15
- outputs = separator.separate(audio_file)
16
- for f in outputs:
17
- full_path = f if os.path.isabs(f) else os.path.join(out_dir, f)
18
- if "vocals" in os.path.basename(full_path).lower():
19
- return full_path
20
- matched = glob.glob(f"{out_dir}/*Vocals*.wav") + glob.glob(f"{out_dir}/*vocals*.wav")
21
- return matched[0] if matched else None
22
 
23
  demo = gr.Interface(
24
- fn=ambil_vokal,
25
- inputs=gr.Audio(type="filepath", label="Upload Audio"),
26
- outputs=gr.Audio(type="filepath", label="Hasil Vokal"),
27
- title="Vocal Extractor (Lightweight)"
28
  )
29
 
30
  demo.launch(server_name="0.0.0.0", server_port=7860)
 
 
1
  import os
2
+ import tempfile
3
  import gradio as gr
4
+ import soundfile as sf
5
+ from df.enhance import enhance, init_df, load_audio, save_audio
6
 
7
+ model, df_state, _ = init_df()
 
8
 
9
+ def hapus_noise(audio_file):
 
 
 
10
  if not audio_file:
11
  return None
12
+ audio, _ = load_audio(audio_file, sr=df_state.sr())
13
+ enhanced = enhance(model, df_state, audio)
14
+ with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp:
15
+ out_path = tmp.name
16
+ save_audio(out_path, enhanced, df_state.sr())
17
+ return out_path
 
18
 
19
  demo = gr.Interface(
20
+ fn=hapus_noise,
21
+ inputs=gr.Audio(type="filepath", label="Upload Audio Ber-noise"),
22
+ outputs=gr.Audio(type="filepath", label="Hasil Bersih Noise"),
23
+ title="Noise Remover (DeepFilterNet)"
24
  )
25
 
26
  demo.launch(server_name="0.0.0.0", server_port=7860)