hugofloresgarcia commited on
Commit
9deebc2
·
1 Parent(s): ace23de

Fix UI: Replace Gallery with 4 separate Audio widgets

Browse files
Files changed (1) hide show
  1. app.py +11 -15
app.py CHANGED
@@ -44,10 +44,10 @@ def generate_audio(prompt, seconds_total=11):
44
  global model, model_config, device
45
 
46
  if model is None:
47
- return [], "Model not loaded. Please wait..."
48
 
49
  if not prompt or not prompt.strip():
50
- return [], "Please enter a text prompt."
51
 
52
  # Set up text and timing conditioning (repeat for batch_size)
53
  conditioning = [{
@@ -68,8 +68,6 @@ def generate_audio(prompt, seconds_total=11):
68
  batch_size=4 # Generate 4 variations
69
  )
70
 
71
- # Rearrange audio batch: [batch, channels, samples] -> [channels, batch*samples]
72
- # Then split back into individual files
73
  sample_rate = model_config["sample_rate"]
74
  audio_files = []
75
 
@@ -96,13 +94,14 @@ def generate_audio(prompt, seconds_total=11):
96
  sf.write(filename, audio, sample_rate)
97
  audio_files.append(filename)
98
 
99
- return audio_files, f"Generated 4 variations for: '{prompt}'"
 
100
 
101
  except Exception as e:
102
  import traceback
103
  error_msg = f"Error generating audio: {str(e)}\n{traceback.format_exc()}"
104
  print(error_msg)
105
- return [], error_msg
106
 
107
  # Load model on startup
108
  print("Initializing model...")
@@ -141,19 +140,16 @@ with gr.Blocks(title="Stable Audio Open Small - 4 Variations") as demo:
141
 
142
  with gr.Column():
143
  status_output = gr.Textbox(label="Status", interactive=False)
144
- audio_gallery = gr.Gallery(
145
- label="Generated Audio Variations",
146
- show_label=True,
147
- elem_id="gallery",
148
- columns=2,
149
- rows=2,
150
- height="auto"
151
- )
152
 
153
  generate_btn.click(
154
  fn=generate_audio,
155
  inputs=[prompt_input, seconds_input],
156
- outputs=[audio_gallery, status_output]
157
  )
158
 
159
  gr.Markdown("""
 
44
  global model, model_config, device
45
 
46
  if model is None:
47
+ return None, None, None, None, "Model not loaded. Please wait..."
48
 
49
  if not prompt or not prompt.strip():
50
+ return None, None, None, None, "Please enter a text prompt."
51
 
52
  # Set up text and timing conditioning (repeat for batch_size)
53
  conditioning = [{
 
68
  batch_size=4 # Generate 4 variations
69
  )
70
 
 
 
71
  sample_rate = model_config["sample_rate"]
72
  audio_files = []
73
 
 
94
  sf.write(filename, audio, sample_rate)
95
  audio_files.append(filename)
96
 
97
+ # Return 4 separate audio files and status message
98
+ return audio_files[0], audio_files[1], audio_files[2], audio_files[3], f"Generated 4 variations for: '{prompt}'"
99
 
100
  except Exception as e:
101
  import traceback
102
  error_msg = f"Error generating audio: {str(e)}\n{traceback.format_exc()}"
103
  print(error_msg)
104
+ return None, None, None, None, error_msg
105
 
106
  # Load model on startup
107
  print("Initializing model...")
 
140
 
141
  with gr.Column():
142
  status_output = gr.Textbox(label="Status", interactive=False)
143
+ gr.Markdown("### Generated Audio Variations")
144
+ audio_output_1 = gr.Audio(label="Variation 1", interactive=False)
145
+ audio_output_2 = gr.Audio(label="Variation 2", interactive=False)
146
+ audio_output_3 = gr.Audio(label="Variation 3", interactive=False)
147
+ audio_output_4 = gr.Audio(label="Variation 4", interactive=False)
 
 
 
148
 
149
  generate_btn.click(
150
  fn=generate_audio,
151
  inputs=[prompt_input, seconds_input],
152
+ outputs=[audio_output_1, audio_output_2, audio_output_3, audio_output_4, status_output]
153
  )
154
 
155
  gr.Markdown("""