Khushi Dahiya commited on
Commit
b6cb034
·
1 Parent(s): 2ff3e07

updating result output to audio file rather than encoded wav

Browse files
Files changed (1) hide show
  1. demos/melodyflow_app.py +7 -15
demos/melodyflow_app.py CHANGED
@@ -20,7 +20,6 @@ from tempfile import NamedTemporaryFile
20
  import time
21
  import typing as tp
22
  import warnings
23
- import base64
24
  import asyncio
25
  import threading
26
  from concurrent.futures import ThreadPoolExecutor
@@ -281,16 +280,7 @@ def _do_predictions_batch(texts, melodies, solver, steps, target_flowstep,
281
  file.name, output, MODEL.sample_rate, strategy="loudness",
282
  loudness_headroom_db=16, loudness_compressor=True, add_suffix=False)
283
 
284
- # Read and encode audio
285
- with open(file.name, 'rb') as f:
286
- audio_bytes = f.read()
287
- audio_base64 = base64.b64encode(audio_bytes).decode('utf-8')
288
-
289
- results.append({
290
- "audio": audio_base64,
291
- "format": "wav"
292
- })
293
-
294
  file_cleaner.add(file.name)
295
 
296
  print(f"Batch finished: {len(texts)} requests in {time.time() - be:.2f}s")
@@ -461,6 +451,8 @@ def predict(model, text,
461
  # Get result
462
  try:
463
  result = future.result()
 
 
464
  return result
465
  except Exception as e:
466
  raise gr.Error(f"Generation failed: {str(e)}")
@@ -530,7 +522,7 @@ def ui_local(launch_kwargs):
530
  label="Regularization Strength", minimum=0.0, maximum=1.0, value=0.0, interactive=False)
531
  with gr.Column():
532
  audio_outputs = [
533
- gr.JSON(label=f"Generated Audio - variation {i+1}") for i in range(N_REPEATS)]
534
  submit.click(fn=predict,
535
  inputs=[model, text,
536
  solver,
@@ -541,7 +533,7 @@ def ui_local(launch_kwargs):
541
  duration,
542
  melody,
543
  model_path,],
544
- outputs=[o for o in audio_outputs],
545
  concurrency_limit=8) # Set concurrency limit on the event listener
546
  melody.change(toggle_melody, melody, [solver])
547
  solver.change(toggle_solver, [solver, melody], [steps, target_flowstep,
@@ -653,7 +645,7 @@ def ui_hf(launch_kwargs):
653
  label="Regularization Strength", minimum=0.0, maximum=1.0, value=0.0, interactive=False)
654
  with gr.Column():
655
  audio_outputs = [
656
- gr.JSON(label=f"Generated Audio - variation {i+1}") for i in range(N_REPEATS)]
657
  submit.click(fn=predict,
658
  inputs=[model, text,
659
  solver,
@@ -663,7 +655,7 @@ def ui_hf(launch_kwargs):
663
  regularization_strength,
664
  duration,
665
  melody,],
666
- outputs=[o for o in audio_outputs],
667
  concurrency_limit=8) # Set concurrency limit on the event listener
668
  melody.change(toggle_melody, melody, [solver])
669
  solver.change(toggle_solver, [solver, melody], [steps, target_flowstep,
 
20
  import time
21
  import typing as tp
22
  import warnings
 
23
  import asyncio
24
  import threading
25
  from concurrent.futures import ThreadPoolExecutor
 
280
  file.name, output, MODEL.sample_rate, strategy="loudness",
281
  loudness_headroom_db=16, loudness_compressor=True, add_suffix=False)
282
 
283
+ results.append(file.name)
 
 
 
 
 
 
 
 
 
284
  file_cleaner.add(file.name)
285
 
286
  print(f"Batch finished: {len(texts)} requests in {time.time() - be:.2f}s")
 
451
  # Get result
452
  try:
453
  result = future.result()
454
+ if isinstance(result, list) and len(result) > 0:
455
+ return result[0]
456
  return result
457
  except Exception as e:
458
  raise gr.Error(f"Generation failed: {str(e)}")
 
522
  label="Regularization Strength", minimum=0.0, maximum=1.0, value=0.0, interactive=False)
523
  with gr.Column():
524
  audio_outputs = [
525
+ gr.Audio(label=f"Generated Audio - variation {i+1}") for i in range(N_REPEATS)]
526
  submit.click(fn=predict,
527
  inputs=[model, text,
528
  solver,
 
533
  duration,
534
  melody,
535
  model_path,],
536
+ outputs=audio_outputs,
537
  concurrency_limit=8) # Set concurrency limit on the event listener
538
  melody.change(toggle_melody, melody, [solver])
539
  solver.change(toggle_solver, [solver, melody], [steps, target_flowstep,
 
645
  label="Regularization Strength", minimum=0.0, maximum=1.0, value=0.0, interactive=False)
646
  with gr.Column():
647
  audio_outputs = [
648
+ gr.Audio(label=f"Generated Audio - variation {i+1}") for i in range(N_REPEATS)]
649
  submit.click(fn=predict,
650
  inputs=[model, text,
651
  solver,
 
655
  regularization_strength,
656
  duration,
657
  melody,],
658
+ outputs=audio_outputs,
659
  concurrency_limit=8) # Set concurrency limit on the event listener
660
  melody.change(toggle_melody, melody, [solver])
661
  solver.change(toggle_solver, [solver, melody], [steps, target_flowstep,