Download services/detect.py from ZeloTech/zelotech: direct link, hf CLI and curl.
- Browser
- Download file 506 Bytes
-
https://huggingface.co/spaces/ZeloTech/zelotech/resolve/main/services/detect.py
- Command line
-
hf download hf://spaces/ZeloTech/zelotech/services/detect.py
-
curl -L -o detect.py https://huggingface.co/spaces/ZeloTech/zelotech/resolve/main/services/detect.py
506 Bytes
| def sniff_kind(path: str) -> str: | |
| """Detecta o tipo do arquivo pelos magic bytes, nao pela extensao. | |
| Mais confiavel que confiar no nome/Content-Type enviado pelo cliente. | |
| Retorna "pdf", "image" ou "unknown". | |
| """ | |
| with open(path, "rb") as f: | |
| head = f.read(12) | |
| if head[:5] == b"%PDF-": | |
| return "pdf" | |
| if head[:8] == b"\x89PNG\r\n\x1a\n": | |
| return "image" | |
| if head[:3] == b"\xff\xd8\xff": # JPEG | |
| return "image" | |
| return "unknown" | |