high77 commited on
Commit
7eff386
·
verified ·
1 Parent(s): e5f3342

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -0
app.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import subprocess
3
+ import os
4
+ import shutil
5
+
6
+ def separate_audio(input_file):
7
+ if input_file is None:
8
+ return None, None, "Please upload a file first."
9
+
10
+ # 1. Setup paths
11
+ output_dir = "separated"
12
+ if os.path.exists(output_dir):
13
+ shutil.rmtree(output_dir) # Clean up previous run
14
+ os.makedirs(output_dir, exist_ok=True)
15
+
16
+ print(f"Processing: {input_file}")
17
+
18
+ # 2. Run Demucs (Command Line Interface inside Python)
19
+ # We use "htdemucs" (high quality) and 2 stems (vocals/accompaniment)
20
+ command = [
21
+ "demucs",
22
+ "--two-stems=vocals",
23
+ "-n", "htdemucs",
24
+ "--out", output_dir,
25
+ input_file
26
+ ]
27
+
28
+ try:
29
+ subprocess.run(command, check=True)
30
+ except subprocess.CalledProcessError as e:
31
+ return None, None, f"Error during separation: {str(e)}"
32
+
33
+ # 3. Locate Output Files
34
+ # Demucs structure: separated/htdemucs/{filename}/vocals.wav
35
+ filename_no_ext = os.path.splitext(os.path.basename(input_file))[0]
36
+ target_folder = os.path.join(output_dir, "htdemucs", filename_no_ext)
37
+
38
+ vocals_path = os.path.join(target_folder, "vocals.wav")
39
+ bg_path = os.path.join(target_folder, "no_vocals.wav")
40
+
41
+ if os.path.exists(vocals_path) and os.path.exists(bg_path):
42
+ return vocals_path, bg_path, "✅ Separation Complete!"
43
+ else:
44
+ return None, None, "❌ Could not find output files."
45
+
46
+ # --- The Interface ---
47
+ with gr.Blocks(title="Indic Dubbing Studio") as demo:
48
+ gr.Markdown("# 🎙️ Indic Dubbing Studio - Phase 1")
49
+ gr.Markdown("Step 1: Separate your video into **Vocals** (for translation) and **Background** (for mixing).")
50
+
51
+ with gr.Row():
52
+ with gr.Column():
53
+ input_file = gr.Audio(type="filepath", label="Upload Video or Audio", sources=["upload"])
54
+ process_btn = gr.Button("Split Audio (Demucs)", variant="primary")
55
+
56
+ with gr.Column():
57
+ status_output = gr.Label(label="Status")
58
+ out_vocals = gr.Audio(label="Vocals (Clean Speech)")
59
+ out_bg = gr.Audio(label="Background (Music/SFX)")
60
+
61
+ process_btn.click(
62
+ fn=separate_audio,
63
+ inputs=[input_file],
64
+ outputs=[out_vocals, out_bg, status_output]
65
+ )
66
+
67
+ if __name__ == "__main__":
68
+ demo.launch()