Spaces:
Sleeping
Sleeping
fix: update audio processing endpoint to default options to all-off when missing
Browse files
app/routes/data_processing.py
CHANGED
|
@@ -46,18 +46,22 @@ async def _process_rate_limit(request: Request) -> None:
|
|
| 46 |
@router.post("/audio", dependencies=[Depends(_process_rate_limit)])
|
| 47 |
async def process_audio_endpoint(
|
| 48 |
file: UploadFile = File(...),
|
| 49 |
-
options: str = Form(
|
| 50 |
):
|
| 51 |
"""
|
| 52 |
Process an audio file with the given augmentation options.
|
| 53 |
Returns the processed WAV file.
|
|
|
|
| 54 |
"""
|
| 55 |
MAX_PAYLOAD_BYTES = 30 * 1024 * 1024 # 30 MB
|
| 56 |
logger.info(f"Received audio processing request for file: {file.filename}")
|
| 57 |
|
| 58 |
# Parse options JSON string into validated Pydantic model
|
|
|
|
|
|
|
|
|
|
| 59 |
try:
|
| 60 |
-
parsed_options = AudioAugmentationOptions.model_validate_json(
|
| 61 |
except (ValidationError, json.JSONDecodeError) as e:
|
| 62 |
raise HTTPException(
|
| 63 |
status_code=422,
|
|
|
|
| 46 |
@router.post("/audio", dependencies=[Depends(_process_rate_limit)])
|
| 47 |
async def process_audio_endpoint(
|
| 48 |
file: UploadFile = File(...),
|
| 49 |
+
options: str = Form(default="{}")
|
| 50 |
):
|
| 51 |
"""
|
| 52 |
Process an audio file with the given augmentation options.
|
| 53 |
Returns the processed WAV file.
|
| 54 |
+
options is a JSON string; if missing or empty, defaults to all-off.
|
| 55 |
"""
|
| 56 |
MAX_PAYLOAD_BYTES = 30 * 1024 * 1024 # 30 MB
|
| 57 |
logger.info(f"Received audio processing request for file: {file.filename}")
|
| 58 |
|
| 59 |
# Parse options JSON string into validated Pydantic model
|
| 60 |
+
raw_options = options.strip() if options else "{}"
|
| 61 |
+
if not raw_options:
|
| 62 |
+
raw_options = "{}"
|
| 63 |
try:
|
| 64 |
+
parsed_options = AudioAugmentationOptions.model_validate_json(raw_options)
|
| 65 |
except (ValidationError, json.JSONDecodeError) as e:
|
| 66 |
raise HTTPException(
|
| 67 |
status_code=422,
|
tests/test_data_processing.py
CHANGED
|
@@ -90,3 +90,13 @@ def test_audio_accepts_camel_case_options(client: TestClient) -> None:
|
|
| 90 |
files={"file": ("test.wav", _fake_audio(), "audio/wav")},
|
| 91 |
)
|
| 92 |
assert response.status_code != 422
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
files={"file": ("test.wav", _fake_audio(), "audio/wav")},
|
| 91 |
)
|
| 92 |
assert response.status_code != 422
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def test_audio_defaults_when_options_missing(client: TestClient) -> None:
|
| 96 |
+
"""Missing options field should default to all-off, not 422."""
|
| 97 |
+
response = client.post(
|
| 98 |
+
"/api/process/audio",
|
| 99 |
+
files={"file": ("test.wav", _fake_audio(), "audio/wav")},
|
| 100 |
+
)
|
| 101 |
+
# Should proceed to processing (200) or processing error — never 422
|
| 102 |
+
assert response.status_code != 422
|