Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -23,6 +23,7 @@ IDEMPOTENCY_KEY_HEADER = "Idempotency-Key"
|
|
| 23 |
CONTENT_ENCODING_HEADER = "Content-Encoding"
|
| 24 |
ACCEPT_ENCODING_HEADER = "Accept-Encoding"
|
| 25 |
GZIP_ENCODING = "gzip"
|
|
|
|
| 26 |
LOW_SIGNAL_PATTERNS = [
|
| 27 |
re.compile(pattern, re.IGNORECASE)
|
| 28 |
for pattern in [
|
|
@@ -120,6 +121,11 @@ def _content_encoding(value: str | None) -> str:
|
|
| 120 |
def _decode_request_body(raw: bytes, content_encoding: str | None) -> tuple[bytes, bool]:
|
| 121 |
encoding = _content_encoding(content_encoding)
|
| 122 |
if encoding == "identity":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
return raw, False
|
| 124 |
if encoding != GZIP_ENCODING:
|
| 125 |
raise UnsupportedContentEncoding(
|
|
|
|
| 23 |
CONTENT_ENCODING_HEADER = "Content-Encoding"
|
| 24 |
ACCEPT_ENCODING_HEADER = "Accept-Encoding"
|
| 25 |
GZIP_ENCODING = "gzip"
|
| 26 |
+
GZIP_MAGIC = b"\x1f\x8b"
|
| 27 |
LOW_SIGNAL_PATTERNS = [
|
| 28 |
re.compile(pattern, re.IGNORECASE)
|
| 29 |
for pattern in [
|
|
|
|
| 121 |
def _decode_request_body(raw: bytes, content_encoding: str | None) -> tuple[bytes, bool]:
|
| 122 |
encoding = _content_encoding(content_encoding)
|
| 123 |
if encoding == "identity":
|
| 124 |
+
if raw.startswith(GZIP_MAGIC):
|
| 125 |
+
try:
|
| 126 |
+
return gzip.decompress(raw), True
|
| 127 |
+
except OSError as exc:
|
| 128 |
+
raise ValueError("invalid gzip request body") from exc
|
| 129 |
return raw, False
|
| 130 |
if encoding != GZIP_ENCODING:
|
| 131 |
raise UnsupportedContentEncoding(
|