stardate69 commited on
Commit
750147c
·
verified ·
1 Parent(s): fcaf7e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -15
app.py CHANGED
@@ -5,7 +5,7 @@ import soundfile as sf
5
  from huggingface_hub import login
6
  from diffusers import StableAudioPipeline
7
  import os
8
- import tempfile
9
 
10
  # Load Hugging Face token securely
11
  HUGGINGFACE_TOKEN = os.getenv("HF_TOKEN")
@@ -48,28 +48,18 @@ def generate_audio():
48
  num_waveforms_per_prompt=1,
49
  generator=generator
50
  ).audios
51
- '''
52
  # Convert to numpy and save to a WAV file
53
  output_audio = audio_output[0].T.float().cpu().numpy()
54
  output_filename = "output.wav"
55
  output_path = os.path.join(OUTPUT_PATH, output_filename)
56
  sf.write(output_path, output_audio, pipe.vae.sampling_rate)
57
 
 
 
 
58
  # Return the WAV file
59
  return jsonify({"file_path": output_path}), 200
60
- '''
61
- # Convert to numpy
62
- output_audio = audio_output[0].T.float().cpu().numpy()
63
-
64
- # Create a temporary file to store the output audio
65
- with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as temp_file:
66
- temp_file_path = temp_file.name
67
- # Save the audio to the temporary file
68
- sf.write(temp_file_path, output_audio, pipe.vae.sampling_rate)
69
-
70
- # Return the file as an attachment
71
- return send_file(temp_file_path, as_attachment=True, download_name="output.wav", mimetype="audio/wav")
72
-
73
 
74
 
75
  except Exception as e:
 
5
  from huggingface_hub import login
6
  from diffusers import StableAudioPipeline
7
  import os
8
+ #import tempfile
9
 
10
  # Load Hugging Face token securely
11
  HUGGINGFACE_TOKEN = os.getenv("HF_TOKEN")
 
48
  num_waveforms_per_prompt=1,
49
  generator=generator
50
  ).audios
51
+
52
  # Convert to numpy and save to a WAV file
53
  output_audio = audio_output[0].T.float().cpu().numpy()
54
  output_filename = "output.wav"
55
  output_path = os.path.join(OUTPUT_PATH, output_filename)
56
  sf.write(output_path, output_audio, pipe.vae.sampling_rate)
57
 
58
+ # Absolute file path
59
+ absolute_output_path = os.path.abspath(output_path)
60
+
61
  # Return the WAV file
62
  return jsonify({"file_path": output_path}), 200
 
 
 
 
 
 
 
 
 
 
 
 
 
63
 
64
 
65
  except Exception as e: