Spaces:
Running
Running
File size: 570 Bytes
8fa3acc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import io
import json
import zipfile
from fastapi import HTTPException
def unzip_predictions_from_zip(zip_bytes: bytes) -> dict:
"""
Reads predictions.json directly from the ZIP in memory.
"""
with zipfile.ZipFile(io.BytesIO(zip_bytes)) as z:
if "predictions.json" not in z.namelist():
error_message = (
"The uploaded ZIP file does not contains a predictions.json file."
)
raise HTTPException(400, error_message)
with z.open("predictions.json") as f:
return json.load(f)
|