Spaces:
Runtime error
Runtime error
Download utils/format_registry.py from cloudaiRambo/cloudairambo: direct link, hf CLI and curl.
- Browser
- Download file 5.32 kB
-
https://huggingface.co/spaces/cloudaiRambo/cloudairambo/resolve/main/utils/format_registry.py
- Command line
-
hf download hf://spaces/cloudaiRambo/cloudairambo/utils/format_registry.py
-
curl -L -o format_registry.py https://huggingface.co/spaces/cloudaiRambo/cloudairambo/resolve/main/utils/format_registry.py
5.32 kB
| import subprocess | |
| import shutil | |
| from functools import lru_cache | |
| # ------------------------------------------------- | |
| # ImageMagick | |
| # ------------------------------------------------- | |
| def imagemagick_formats(): | |
| magick = shutil.which("magick") or shutil.which("convert") | |
| if not magick: | |
| return set() | |
| out = subprocess.check_output( | |
| [magick, "-list", "format"], | |
| stderr=subprocess.DEVNULL | |
| ).decode(errors="ignore") | |
| fmts = set() | |
| for line in out.splitlines(): | |
| parts = line.split() | |
| if parts and parts[0].isalpha(): | |
| fmts.add(parts[0].lower()) | |
| return fmts | |
| # ------------------------------------------------- | |
| # FFmpeg | |
| # ------------------------------------------------- | |
| def ffmpeg_formats(): | |
| if not shutil.which("ffmpeg"): | |
| return set() | |
| out = subprocess.check_output( | |
| ["ffmpeg", "-formats"], | |
| stderr=subprocess.STDOUT | |
| ).decode(errors="ignore") | |
| fmts = set() | |
| for line in out.splitlines(): | |
| if line.startswith(" D") or line.startswith(" E"): | |
| fmts.update(line.split()[1].split(",")) | |
| return fmts | |
| # ------------------------------------------------- | |
| # Pandoc | |
| # ------------------------------------------------- | |
| def pandoc_formats(): | |
| if not shutil.which("pandoc"): | |
| return set() | |
| out = subprocess.check_output( | |
| ["pandoc", "--list-output-formats"] | |
| ).decode(errors="ignore") | |
| return set(out.split()) | |
| # ------------------------------------------------- | |
| # LibreOffice | |
| # ------------------------------------------------- | |
| def libreoffice_formats(): | |
| if not (shutil.which("soffice") or shutil.which("libreoffice")): | |
| return set() | |
| return { | |
| "doc", "docx", "ppt", "pptx", | |
| "xls", "xlsx", "odt", "ods", "odp", | |
| "rtf", "pdf", "txt" | |
| } | |
| # ------------------------------------------------- | |
| # Calibre (Ebooks) | |
| # ------------------------------------------------- | |
| def ebook_formats(): | |
| if not shutil.which("ebook-convert"): | |
| return set() | |
| return {"epub", "mobi", "azw3", "fb2", "lit", "pdf"} | |
| # ------------------------------------------------- | |
| # Archives | |
| # ------------------------------------------------- | |
| def archive_formats(): | |
| return {"zip", "7z", "rar", "tar", "gz", "bz2", "xz"} | |
| # ------------------------------------------------- | |
| # GDAL / OGR (GIS) | |
| # ------------------------------------------------- | |
| def gdal_formats(): | |
| if not shutil.which("ogr2ogr"): | |
| return set() | |
| out = subprocess.check_output( | |
| ["ogrinfo", "--formats"], | |
| stderr=subprocess.DEVNULL | |
| ).decode(errors="ignore") | |
| fmts = set() | |
| for line in out.splitlines(): | |
| if "-" in line: | |
| name = line.split("-")[0].strip().lower() | |
| fmts.add(name) | |
| return fmts | |
| # ------------------------------------------------- | |
| # OpenBabel (Scientific / Chemistry) | |
| # ------------------------------------------------- | |
| def openbabel_formats(): | |
| if not shutil.which("obabel"): | |
| return set() | |
| out = subprocess.check_output( | |
| ["obabel", "-L", "formats"], | |
| stderr=subprocess.DEVNULL | |
| ).decode(errors="ignore") | |
| fmts = set() | |
| for line in out.splitlines(): | |
| if "." in line: | |
| ext = line.split(".")[1].split()[0].lower() | |
| fmts.add(ext) | |
| return fmts | |
| # ------------------------------------------------- | |
| # Poppler (Advanced PDF targets) | |
| # ------------------------------------------------- | |
| def poppler_formats(): | |
| if not shutil.which("pdftocairo"): | |
| return set() | |
| return {"svg", "html", "ps", "ppm"} | |
| # ------------------------------------------------- | |
| # Whisper (AI transcription targets) | |
| # ------------------------------------------------- | |
| def whisper_formats(): | |
| if not shutil.which("whisper"): | |
| return set() | |
| return {"txt", "srt", "vtt"} | |
| # ------------------------------------------------- | |
| # MASTER REGISTRY | |
| # ------------------------------------------------- | |
| def all_formats(): | |
| return { | |
| "images": imagemagick_formats(), | |
| "audio_video": ffmpeg_formats(), | |
| "documents": pandoc_formats(), | |
| "office": libreoffice_formats(), | |
| "ebooks": ebook_formats(), | |
| "archives": archive_formats(), | |
| "gis": gdal_formats(), | |
| "scientific": openbabel_formats(), | |
| "advanced_pdf": poppler_formats(), | |
| "speech_to_text": whisper_formats(), | |
| } | |
| def djvu_formats(): | |
| if not shutil.which("ddjvu"): | |
| return set() | |
| return {"djvu"} | |
| def graphicsmagick_formats(): | |
| if not shutil.which("gm"): | |
| return set() | |
| return { | |
| "bmp", "gif", "jpg", "jpeg", "png", "tiff", | |
| "webp", "pnm", "ppm", "ico", "psd" | |
| } | |
| def mupdf_formats(): | |
| if not shutil.which("mutool"): | |
| return set() | |
| return {"xps", "cbz", "svg"} | |
| # ------------------------------------------------- | |
| # CLI TEST | |
| # ------------------------------------------------- | |
| if __name__ == "__main__": | |
| f = all_formats() | |
| for k, v in f.items(): | |
| print(f"{k}: {len(v)}") | |
| total = set.union(*[set(v) for v in f.values() if v]) | |
| print("TOTAL DISTINCT FORMATS:", len(total)) | |