Update app.py
Browse files
app.py
CHANGED
@@ -31,13 +31,23 @@ def encode_audio(audio_path):
|
|
31 |
# Reshape to match expected format [batch, seq_len, features]
|
32 |
tokens = tokens.reshape(1, -1, 1)
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
# Create a temporary file in /tmp which is writable in Spaces
|
35 |
temp_dir = "/tmp"
|
36 |
os.makedirs(temp_dir, exist_ok=True)
|
37 |
temp_file_path = os.path.join(temp_dir, f"tokens_{uuid.uuid4()}.oterin")
|
38 |
|
39 |
-
#
|
40 |
-
|
|
|
41 |
|
42 |
# Verify the file exists and has content
|
43 |
if not os.path.exists(temp_file_path) or os.path.getsize(temp_file_path) == 0:
|
|
|
31 |
# Reshape to match expected format [batch, seq_len, features]
|
32 |
tokens = tokens.reshape(1, -1, 1)
|
33 |
|
34 |
+
# Save to a BytesIO buffer first
|
35 |
+
buffer = io.BytesIO()
|
36 |
+
np.save(buffer, tokens)
|
37 |
+
buffer.seek(0)
|
38 |
+
|
39 |
+
# Verify the buffer has content
|
40 |
+
if buffer.getbuffer().nbytes == 0:
|
41 |
+
raise Exception("Failed to create token buffer")
|
42 |
+
|
43 |
# Create a temporary file in /tmp which is writable in Spaces
|
44 |
temp_dir = "/tmp"
|
45 |
os.makedirs(temp_dir, exist_ok=True)
|
46 |
temp_file_path = os.path.join(temp_dir, f"tokens_{uuid.uuid4()}.oterin")
|
47 |
|
48 |
+
# Write buffer to the temporary file
|
49 |
+
with open(temp_file_path, "wb") as f:
|
50 |
+
f.write(buffer.getvalue())
|
51 |
|
52 |
# Verify the file exists and has content
|
53 |
if not os.path.exists(temp_file_path) or os.path.getsize(temp_file_path) == 0:
|