Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,7 @@ import spaces
|
|
9 |
import tempfile
|
10 |
import os
|
11 |
import numpy as np
|
|
|
12 |
|
13 |
# Check for CUDA availability and set device
|
14 |
try:
|
@@ -48,16 +49,17 @@ def encode(audio_file_path):
|
|
48 |
signal = jnp.expand_dims(signal, axis=(0, 1)) # Add batch and channel dimensions
|
49 |
|
50 |
# Set chunk duration based on available GPU memory (adjust as needed)
|
51 |
-
win_duration =
|
52 |
|
53 |
# Compress using chunking
|
54 |
dac_file = model.compress(compress_chunk, signal, sample_rate, win_duration=win_duration)
|
55 |
|
56 |
-
# Save the compressed DAC file to a
|
57 |
-
|
58 |
-
dac_file.save(
|
|
|
59 |
|
60 |
-
return
|
61 |
|
62 |
except Exception as e:
|
63 |
gr.Warning(f"An error occurred during encoding: {e}")
|
@@ -103,4 +105,4 @@ with gr.Blocks() as demo:
|
|
103 |
|
104 |
decode_button.click(decode, inputs=compressed_input, outputs=decoded_output)
|
105 |
|
106 |
-
demo.queue().launch()
|
|
|
9 |
import tempfile
|
10 |
import os
|
11 |
import numpy as np
|
12 |
+
import io
|
13 |
|
14 |
# Check for CUDA availability and set device
|
15 |
try:
|
|
|
49 |
signal = jnp.expand_dims(signal, axis=(0, 1)) # Add batch and channel dimensions
|
50 |
|
51 |
# Set chunk duration based on available GPU memory (adjust as needed)
|
52 |
+
win_duration = 5.0
|
53 |
|
54 |
# Compress using chunking
|
55 |
dac_file = model.compress(compress_chunk, signal, sample_rate, win_duration=win_duration)
|
56 |
|
57 |
+
# Save the compressed DAC file to a BytesIO object
|
58 |
+
buffer = io.BytesIO()
|
59 |
+
dac_file.save(buffer)
|
60 |
+
buffer.seek(0)
|
61 |
|
62 |
+
return (buffer, "compressed_audio.dac")
|
63 |
|
64 |
except Exception as e:
|
65 |
gr.Warning(f"An error occurred during encoding: {e}")
|
|
|
105 |
|
106 |
decode_button.click(decode, inputs=compressed_input, outputs=decoded_output)
|
107 |
|
108 |
+
demo.queue().launch()
|