Update app.py
Browse files
app.py
CHANGED
@@ -26,10 +26,14 @@ cancel_encode = False
|
|
26 |
cancel_decode = False
|
27 |
cancel_stream = False
|
28 |
|
29 |
-
@spaces.GPU(duration=30)
|
30 |
def encode_audio(audio_file_path):
|
31 |
global cancel_encode
|
32 |
|
|
|
|
|
|
|
|
|
33 |
try:
|
34 |
# Load the audio file
|
35 |
waveform, sample_rate = torchaudio.load(audio_file_path)
|
@@ -79,10 +83,10 @@ def encode_audio(audio_file_path):
|
|
79 |
# Add this function to handle the output
|
80 |
def handle_encode_output(file_path):
|
81 |
if file_path is None:
|
82 |
-
return None, gr.Markdown("Encoding failed. Please
|
83 |
return file_path, gr.Markdown(visible=False)
|
84 |
|
85 |
-
@spaces.GPU(duration=30)
|
86 |
def decode_audio(encoded_file_path):
|
87 |
global cancel_decode
|
88 |
|
@@ -123,7 +127,7 @@ def decode_audio(encoded_file_path):
|
|
123 |
finally:
|
124 |
cancel_decode = False # Reset cancel flag after decoding
|
125 |
|
126 |
-
@spaces.GPU(duration=30)
|
127 |
async def stream_decode_audio(encoded_file_path) -> Generator[tuple, None, None]:
|
128 |
global cancel_stream
|
129 |
|
@@ -168,8 +172,13 @@ with gr.Blocks() as demo:
|
|
168 |
encoded_output = gr.File(label="Encoded File (.owie)", type="filepath") # Using "filepath" mode
|
169 |
encode_error_message = gr.Markdown(visible=False)
|
170 |
|
|
|
|
|
|
|
|
|
|
|
171 |
encode_button.click(
|
172 |
-
|
173 |
inputs=input_audio,
|
174 |
outputs=[encoded_output, encode_error_message]
|
175 |
)
|
|
|
26 |
cancel_decode = False
|
27 |
cancel_stream = False
|
28 |
|
29 |
+
@spaces.GPU(duration=30) # Changed from 250 to 30
|
30 |
def encode_audio(audio_file_path):
|
31 |
global cancel_encode
|
32 |
|
33 |
+
if audio_file_path is None:
|
34 |
+
print("No audio file provided")
|
35 |
+
return None
|
36 |
+
|
37 |
try:
|
38 |
# Load the audio file
|
39 |
waveform, sample_rate = torchaudio.load(audio_file_path)
|
|
|
83 |
# Add this function to handle the output
|
84 |
def handle_encode_output(file_path):
|
85 |
if file_path is None:
|
86 |
+
return None, gr.Markdown("Encoding failed. Please ensure you've uploaded an audio file and try again.", visible=True)
|
87 |
return file_path, gr.Markdown(visible=False)
|
88 |
|
89 |
+
@spaces.GPU(duration=30) # Changed from 250 to 30
|
90 |
def decode_audio(encoded_file_path):
|
91 |
global cancel_decode
|
92 |
|
|
|
127 |
finally:
|
128 |
cancel_decode = False # Reset cancel flag after decoding
|
129 |
|
130 |
+
@spaces.GPU(duration=30) # Changed from 250 to 30
|
131 |
async def stream_decode_audio(encoded_file_path) -> Generator[tuple, None, None]:
|
132 |
global cancel_stream
|
133 |
|
|
|
172 |
encoded_output = gr.File(label="Encoded File (.owie)", type="filepath") # Using "filepath" mode
|
173 |
encode_error_message = gr.Markdown(visible=False)
|
174 |
|
175 |
+
def encode_wrapper(audio):
|
176 |
+
if audio is None:
|
177 |
+
return None, gr.Markdown("Please upload an audio file before encoding.", visible=True)
|
178 |
+
return handle_encode_output(encode_audio(audio))
|
179 |
+
|
180 |
encode_button.click(
|
181 |
+
encode_wrapper,
|
182 |
inputs=input_audio,
|
183 |
outputs=[encoded_output, encode_error_message]
|
184 |
)
|