Pecorized commited on
Commit
c76c8a0
·
1 Parent(s): 945ab77

boxes modify

Browse files
Files changed (1) hide show
  1. app.py +27 -19
app.py CHANGED
@@ -96,41 +96,49 @@ def inference(audio, vocals, bass, drums, other, piano, guitar, lead_vocals, bac
96
 
97
  # Collecting all file paths
98
  stem_files = {
99
- "vocals": "./out/htdemucs_6s/test/vocals.wav",
100
- "bass": "./out/htdemucs_6s/test/bass.wav",
101
- "drums": "./out/htdemucs_6s/test/drums.wav",
102
- "other": "./out/htdemucs_6s/test/other.wav",
103
- "piano": "./out/htdemucs_6s/test/piano.wav",
104
- "guitar": "./out/htdemucs_6s/test/guitar.wav",
105
- "lead_vocals": primary_stem_path,
106
- "backing_vocals": secondary_stem_path
107
  }
108
 
109
  # Filter out unchecked stems
110
  selected_stems = {
111
- "vocals": vocals,
112
- "bass": bass,
113
- "drums": drums,
114
- "other": other,
115
- "piano": piano,
116
- "guitar": guitar,
117
- "lead_vocals": lead_vocals,
118
- "backing_vocals": backing_vocals
119
  }
120
 
121
- return [stem_files[stem] if selected_stems[stem] and os.path.isfile(stem_files[stem]) else None for stem in selected_stems]
122
 
123
  # Checkbox for each stem
124
  checkboxes = [gr.components.Checkbox(label=stem) for stem in ["Vocals", "Bass", "Drums", "Other", "Piano", "Guitar", "Lead Vocals", "Backing Vocals"]]
125
 
 
 
 
 
 
 
 
 
126
  # Gradio Interface
127
  title = "Source Separation Demo"
128
  description = "Music Source Separation in the Waveform Domain. To use it, simply upload your audio and select the stems you want to display."
129
  gr.Interface(
130
  inference,
131
  [gr.components.Audio(type="numpy", label="Input")] + checkboxes,
132
- [gr.components.Audio(type="filepath", label=stem, optional=True) for stem in ["Vocals", "Bass", "Drums", "Other", "Piano", "Guitar", "Lead Vocals", "Backing Vocals"]],
133
  title=title,
134
  description=description,
135
  live=True # Enable live updates
136
- ).launch()
 
96
 
97
  # Collecting all file paths
98
  stem_files = {
99
+ "Vocals": "./out/htdemucs_6s/test/vocals.wav",
100
+ "Bass": "./out/htdemucs_6s/test/bass.wav",
101
+ "Drums": "./out/htdemucs_6s/test/drums.wav",
102
+ "Other": "./out/htdemucs_6s/test/other.wav",
103
+ "Piano": "./out/htdemucs_6s/test/piano.wav",
104
+ "Guitar": "./out/htdemucs_6s/test/guitar.wav",
105
+ "Lead Vocals": primary_stem_path,
106
+ "Backing Vocals": secondary_stem_path
107
  }
108
 
109
  # Filter out unchecked stems
110
  selected_stems = {
111
+ "Vocals": vocals,
112
+ "Bass": bass,
113
+ "Drums": drums,
114
+ "Other": other,
115
+ "Piano": piano,
116
+ "Guitar": guitar,
117
+ "Lead Vocals": lead_vocals,
118
+ "Backing Vocals": backing_vocals
119
  }
120
 
121
+ return {stem: stem_files[stem] if selected_stems[stem] and os.path.isfile(stem_files[stem]) else None for stem in selected_stems}
122
 
123
  # Checkbox for each stem
124
  checkboxes = [gr.components.Checkbox(label=stem) for stem in ["Vocals", "Bass", "Drums", "Other", "Piano", "Guitar", "Lead Vocals", "Backing Vocals"]]
125
 
126
+ # Custom output component function
127
+ def output_component(stem_results):
128
+ components = []
129
+ for stem, file_path in stem_results.items():
130
+ if file_path:
131
+ components.append(gr.Audio(file_path, label=stem))
132
+ return components
133
+
134
  # Gradio Interface
135
  title = "Source Separation Demo"
136
  description = "Music Source Separation in the Waveform Domain. To use it, simply upload your audio and select the stems you want to display."
137
  gr.Interface(
138
  inference,
139
  [gr.components.Audio(type="numpy", label="Input")] + checkboxes,
140
+ gr.outputs.Dynamic(output_component),
141
  title=title,
142
  description=description,
143
  live=True # Enable live updates
144
+ ).launch()