Update app.py
Browse files
app.py
CHANGED
@@ -26,7 +26,7 @@ cancel_encode = False
|
|
26 |
cancel_decode = False
|
27 |
cancel_stream = False
|
28 |
|
29 |
-
@spaces.GPU(duration=250)
|
30 |
def encode_audio(audio_file_path):
|
31 |
global cancel_encode
|
32 |
try:
|
@@ -38,6 +38,9 @@ def encode_audio(audio_file_path):
|
|
38 |
with torch.no_grad():
|
39 |
tokens = semanticodec.encode(audio)
|
40 |
|
|
|
|
|
|
|
41 |
# Convert to NumPy and save to a temporary .owie file
|
42 |
tokens_numpy = tokens.detach().cpu().numpy()
|
43 |
temp_fd, temp_file_path = tempfile.mkstemp(suffix=".owie")
|
@@ -52,12 +55,13 @@ def encode_audio(audio_file_path):
|
|
52 |
return temp_file_path
|
53 |
|
54 |
except Exception as e:
|
|
|
55 |
return f"Encoding error: {e}"
|
56 |
|
57 |
finally:
|
58 |
cancel_encode = False # Reset cancel flag after encoding
|
59 |
|
60 |
-
@spaces.GPU(duration=250)
|
61 |
def decode_audio(encoded_file_path):
|
62 |
global cancel_decode
|
63 |
try:
|
@@ -79,12 +83,13 @@ def decode_audio(encoded_file_path):
|
|
79 |
return temp_wav_path
|
80 |
|
81 |
except Exception as e:
|
|
|
82 |
return f"Decoding error: {e}"
|
83 |
|
84 |
finally:
|
85 |
cancel_decode = False # Reset cancel flag after decoding
|
86 |
|
87 |
-
@spaces.GPU(duration=250)
|
88 |
async def stream_decode_audio(encoded_file_path) -> Generator[tuple, None, None]:
|
89 |
global cancel_stream
|
90 |
try:
|
@@ -122,27 +127,27 @@ with gr.Blocks() as demo:
|
|
122 |
gr.Markdown("## Audio Compression with SemantiCodec (GPU/CPU)")
|
123 |
|
124 |
with gr.Tab("Encode"):
|
125 |
-
input_audio = gr.Audio(label="Input Audio", type="filepath")
|
126 |
encode_button = gr.Button("Encode")
|
127 |
cancel_encode_button = gr.Button("Cancel")
|
128 |
-
encoded_output = gr.File(label="Encoded File (.owie)", type="filepath")
|
129 |
|
130 |
encode_button.click(encode_audio, inputs=input_audio, outputs=encoded_output)
|
131 |
cancel_encode_button.click(lambda: globals().update(cancel_encode=True),
|
132 |
outputs=None) # Set cancel_encode flag
|
133 |
|
134 |
with gr.Tab("Decode"):
|
135 |
-
input_encoded = gr.File(label="Encoded File (.owie)", type="filepath")
|
136 |
decode_button = gr.Button("Decode")
|
137 |
cancel_decode_button = gr.Button("Cancel")
|
138 |
-
decoded_output = gr.Audio(label="Decoded Audio", type="filepath")
|
139 |
|
140 |
decode_button.click(decode_audio, inputs=input_encoded, outputs=decoded_output)
|
141 |
cancel_decode_button.click(lambda: globals().update(cancel_decode=True),
|
142 |
outputs=None) # Set cancel_decode flag
|
143 |
|
144 |
with gr.Tab("Streaming"):
|
145 |
-
input_encoded_stream = gr.File(label="Encoded File (.owie)", type="filepath")
|
146 |
stream_button = gr.Button("Start Streaming")
|
147 |
cancel_stream_button = gr.Button("Cancel")
|
148 |
audio_output = gr.Audio(label="Streaming Audio Output", streaming=True)
|
|
|
26 |
cancel_decode = False
|
27 |
cancel_stream = False
|
28 |
|
29 |
+
@spaces.GPU(duration=250)
|
30 |
def encode_audio(audio_file_path):
|
31 |
global cancel_encode
|
32 |
try:
|
|
|
38 |
with torch.no_grad():
|
39 |
tokens = semanticodec.encode(audio)
|
40 |
|
41 |
+
# Debugging print statement
|
42 |
+
print(f"Tokens shape: {tokens.shape}, dtype: {tokens.dtype}")
|
43 |
+
|
44 |
# Convert to NumPy and save to a temporary .owie file
|
45 |
tokens_numpy = tokens.detach().cpu().numpy()
|
46 |
temp_fd, temp_file_path = tempfile.mkstemp(suffix=".owie")
|
|
|
55 |
return temp_file_path
|
56 |
|
57 |
except Exception as e:
|
58 |
+
print(f"Encoding error: {e}")
|
59 |
return f"Encoding error: {e}"
|
60 |
|
61 |
finally:
|
62 |
cancel_encode = False # Reset cancel flag after encoding
|
63 |
|
64 |
+
@spaces.GPU(duration=250)
|
65 |
def decode_audio(encoded_file_path):
|
66 |
global cancel_decode
|
67 |
try:
|
|
|
83 |
return temp_wav_path
|
84 |
|
85 |
except Exception as e:
|
86 |
+
print(f"Decoding error: {e}")
|
87 |
return f"Decoding error: {e}"
|
88 |
|
89 |
finally:
|
90 |
cancel_decode = False # Reset cancel flag after decoding
|
91 |
|
92 |
+
@spaces.GPU(duration=250)
|
93 |
async def stream_decode_audio(encoded_file_path) -> Generator[tuple, None, None]:
|
94 |
global cancel_stream
|
95 |
try:
|
|
|
127 |
gr.Markdown("## Audio Compression with SemantiCodec (GPU/CPU)")
|
128 |
|
129 |
with gr.Tab("Encode"):
|
130 |
+
input_audio = gr.Audio(label="Input Audio", type="filepath") # Using "filepath" mode
|
131 |
encode_button = gr.Button("Encode")
|
132 |
cancel_encode_button = gr.Button("Cancel")
|
133 |
+
encoded_output = gr.File(label="Encoded File (.owie)", type="filepath") # Using "filepath" mode
|
134 |
|
135 |
encode_button.click(encode_audio, inputs=input_audio, outputs=encoded_output)
|
136 |
cancel_encode_button.click(lambda: globals().update(cancel_encode=True),
|
137 |
outputs=None) # Set cancel_encode flag
|
138 |
|
139 |
with gr.Tab("Decode"):
|
140 |
+
input_encoded = gr.File(label="Encoded File (.owie)", type="filepath") # Using "filepath" mode
|
141 |
decode_button = gr.Button("Decode")
|
142 |
cancel_decode_button = gr.Button("Cancel")
|
143 |
+
decoded_output = gr.Audio(label="Decoded Audio", type="filepath") # Using "filepath" mode
|
144 |
|
145 |
decode_button.click(decode_audio, inputs=input_encoded, outputs=decoded_output)
|
146 |
cancel_decode_button.click(lambda: globals().update(cancel_decode=True),
|
147 |
outputs=None) # Set cancel_decode flag
|
148 |
|
149 |
with gr.Tab("Streaming"):
|
150 |
+
input_encoded_stream = gr.File(label="Encoded File (.owie)", type="filepath") # Using "filepath" mode
|
151 |
stream_button = gr.Button("Start Streaming")
|
152 |
cancel_stream_button = gr.Button("Cancel")
|
153 |
audio_output = gr.Audio(label="Streaming Audio Output", streaming=True)
|