Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -25,6 +25,10 @@ pipe = pipe.to(device)
|
|
| 25 |
# Initialize Flask app
|
| 26 |
app = Flask(__name__)
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
# Route to generate audio
|
| 29 |
|
| 30 |
@app.route("/generate", methods=["GET"])
|
|
@@ -46,17 +50,16 @@ def generate_audio():
|
|
| 46 |
generator=generator
|
| 47 |
).audios
|
| 48 |
|
| 49 |
-
# Create
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
# Write the audio to the temporary file
|
| 53 |
-
sf.write(tmpfile.name, output_audio, pipe.vae.sampling_rate)
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
|
| 58 |
-
#
|
| 59 |
-
|
|
|
|
| 60 |
|
| 61 |
'''
|
| 62 |
# Convert audio to BytesIO in memory
|
|
|
|
| 25 |
# Initialize Flask app
|
| 26 |
app = Flask(__name__)
|
| 27 |
|
| 28 |
+
# Set up a folder for public files (you can choose a different directory)
|
| 29 |
+
PUBLIC_DIRECTORY = os.path.join(os.getcwd(), 'static', 'generated_audio')
|
| 30 |
+
os.makedirs(PUBLIC_DIRECTORY, exist_ok=True)
|
| 31 |
+
|
| 32 |
# Route to generate audio
|
| 33 |
|
| 34 |
@app.route("/generate", methods=["GET"])
|
|
|
|
| 50 |
generator=generator
|
| 51 |
).audios
|
| 52 |
|
| 53 |
+
# Create an absolute file path in the "static/generated_audio" directory
|
| 54 |
+
output_filename = f"{prompt.replace(' ', '_')}_output.wav"
|
| 55 |
+
output_file_path = os.path.join(PUBLIC_DIRECTORY, output_filename)
|
|
|
|
|
|
|
| 56 |
|
| 57 |
+
# Write the generated audio to the file
|
| 58 |
+
sf.write(output_file_path, audio_output.T.cpu().numpy(), pipe.vae.sampling_rate)
|
| 59 |
|
| 60 |
+
# Return the absolute URL to the file
|
| 61 |
+
download_url = f"/download/{output_filename}"
|
| 62 |
+
return jsonify({"download_url": download_url}), 200
|
| 63 |
|
| 64 |
'''
|
| 65 |
# Convert audio to BytesIO in memory
|