Spaces:
Runtime error
Runtime error
Download utils/pandoc_utils.py from cloudaiRambo/cloudairambo: direct link, hf CLI and curl.
- Browser
- Download file 730 Bytes
-
https://huggingface.co/spaces/cloudaiRambo/cloudairambo/resolve/main/utils/pandoc_utils.py
- Command line
-
hf download hf://spaces/cloudaiRambo/cloudairambo/utils/pandoc_utils.py
-
curl -L -o pandoc_utils.py https://huggingface.co/spaces/cloudaiRambo/cloudairambo/resolve/main/utils/pandoc_utils.py
730 Bytes
| import subprocess | |
| import os | |
| import uuid | |
| from core.config import settings | |
| def convert_pandoc(input_path: str, target_ext: str): | |
| target_ext = target_ext.lower().lstrip(".") | |
| output_name = f"{uuid.uuid4()}.{target_ext}" | |
| output_path = os.path.join(settings.OUTPUT_DIR, output_name) | |
| cmd = ["pandoc", input_path, "-o", output_path] | |
| # ✅ CRITICAL LINE (UNICODE SAFE) | |
| if target_ext == "pdf": | |
| cmd.extend(["--pdf-engine=xelatex"]) | |
| proc = subprocess.run( | |
| cmd, | |
| stdout=subprocess.PIPE, | |
| stderr=subprocess.PIPE | |
| ) | |
| if proc.returncode != 0: | |
| stderr = proc.stderr.decode(errors="ignore") | |
| raise RuntimeError("Pandoc failed: " + stderr) | |
| return output_path | |