Spaces:
Running on Zero
Running on Zero
Refuse an unreadable file with a gr.Error
Browse filesprocess_fn read the input with soundfile outside any try, so a file that is not audio failed with an uncaught exception, which HARP shows as a crash. It is refused with a gr.Error naming the problem instead.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
app.py
CHANGED
|
@@ -62,7 +62,10 @@ def process_fn(input_audio_path: str, output_sample_rate: str) -> str:
|
|
| 62 |
# under ZeroGPU's emulation
|
| 63 |
if not input_audio_path:
|
| 64 |
raise gr.Error("Choose an audio file.")
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
| 66 |
if len(audio) == 0:
|
| 67 |
raise gr.Error("The audio file is empty.")
|
| 68 |
duration = len(audio) / input_rate
|
|
|
|
| 62 |
# under ZeroGPU's emulation
|
| 63 |
if not input_audio_path:
|
| 64 |
raise gr.Error("Choose an audio file.")
|
| 65 |
+
try:
|
| 66 |
+
audio, input_rate = sf.read(input_audio_path, always_2d=True)
|
| 67 |
+
except Exception as exc:
|
| 68 |
+
raise gr.Error(f"Could not read the audio file: {exc}") from exc
|
| 69 |
if len(audio) == 0:
|
| 70 |
raise gr.Error("The audio file is empty.")
|
| 71 |
duration = len(audio) / input_rate
|