lllindsey0615 commited on
Commit
3927a41
·
1 Parent(s): 3c3a2fa

return only dict

Browse files
Files changed (1) hide show
  1. app.py +27 -18
app.py CHANGED
@@ -71,48 +71,57 @@ def generate_dummy_metadata(stem_choice: str, username: str) -> Dict:
71
  "labels": [vars(label) for label in label_list.labels]
72
  }
73
 
74
-
75
  def process_fn_stem(
76
  audio_file_path: str,
77
  demucs_model: str,
78
  stem_choice: str,
79
  profile: gr.OAuthProfile | None = None
80
- ) -> tuple:
 
81
  username = profile.username if profile else "anonymous"
82
- print(f"Processing for user: {username}")
83
 
 
84
  stem_signal = separate_stem(audio_file_path, model_name=demucs_model, stem_choice=stem_choice)
 
 
85
  stem_filename = f"{stem_choice.lower().replace(' ', '_')}.wav"
86
  stem_path = save_audio(stem_signal, stem_filename)
87
 
88
- metadata = generate_dummy_metadata(stem_choice, username)
89
- return stem_path, metadata
 
 
 
 
 
 
 
90
 
91
 
92
- # Gradio Interface
93
-
94
 
 
 
95
  with gr.Blocks() as demo:
96
  gr.Markdown("# 🎧 Demucs Stem Separator")
97
- gr.Markdown("Sign in with your Hugging Face account to use this tool.")
98
 
99
  gr.LoginButton()
100
 
101
- with gr.Row():
102
- model_dropdown = gr.Dropdown(label="Select Demucs Model", choices=DEMUX_MODELS, value="mdx_extra_q")
103
- stem_dropdown = gr.Dropdown(label="Select Stem", choices=list(STEM_CHOICES.keys()), value="Vocals")
104
-
105
  audio_input = gr.Audio(label="Upload Audio", type="filepath")
106
- stem_output = gr.File(label="Separated Stem (.wav)")
107
- metadata_output = gr.JSON(label="Separation Metadata")
108
 
109
- run_button = gr.Button("Separate Stem")
110
 
111
  run_button.click(
112
  fn=process_fn_stem,
113
  inputs=[audio_input, model_dropdown, stem_dropdown],
114
- outputs=[stem_output, metadata_output]
115
  )
116
 
117
- demo.queue()
118
- demo.launch()
 
 
 
71
  "labels": [vars(label) for label in label_list.labels]
72
  }
73
 
 
74
  def process_fn_stem(
75
  audio_file_path: str,
76
  demucs_model: str,
77
  stem_choice: str,
78
  profile: gr.OAuthProfile | None = None
79
+ ) -> dict:
80
+ # Get user info
81
  username = profile.username if profile else "anonymous"
 
82
 
83
+ # Separate stem
84
  stem_signal = separate_stem(audio_file_path, model_name=demucs_model, stem_choice=stem_choice)
85
+
86
+ # Save output
87
  stem_filename = f"{stem_choice.lower().replace(' ', '_')}.wav"
88
  stem_path = save_audio(stem_signal, stem_filename)
89
 
90
+ # Return flat dict with primitive types only
91
+ return {
92
+ "stem_file": stem_path,
93
+ "stem": stem_choice,
94
+ "user": username,
95
+ "timestamp": 0.0,
96
+ "amplitude": 0.7,
97
+ "description": f"Start of {stem_choice}"
98
+ }
99
 
100
 
 
 
101
 
102
+ # Gradio Interface
103
+ # Gradio UI
104
  with gr.Blocks() as demo:
105
  gr.Markdown("# 🎧 Demucs Stem Separator")
106
+ gr.Markdown("Log in with your Hugging Face account to separate stems from audio files.")
107
 
108
  gr.LoginButton()
109
 
110
+ model_dropdown = gr.Dropdown(label="Select Demucs Model", choices=DEMUX_MODELS, value="mdx_extra_q")
111
+ stem_dropdown = gr.Dropdown(label="Select Stem", choices=list(STEM_CHOICES.keys()), value="Vocals")
 
 
112
  audio_input = gr.Audio(label="Upload Audio", type="filepath")
113
+ output_file = gr.File(label="Separated Stem File (.wav)")
114
+ output_json = gr.JSON(label="Metadata")
115
 
116
+ run_button = gr.Button("Run Separation")
117
 
118
  run_button.click(
119
  fn=process_fn_stem,
120
  inputs=[audio_input, model_dropdown, stem_dropdown],
121
+ outputs=[output_file, output_json]
122
  )
123
 
124
+ demo.queue()
125
+
126
+ # Launch the app
127
+ demo.launch(show_error=True)