(
md: str,
base_dir=''
)
| 65 | return f"data:{mime};base64,{b64}" |
| 66 | |
| 67 | def md_to_blocks( |
| 68 | md: str, |
| 69 | base_dir='' |
| 70 | ): |
| 71 | blocks, pos = [], 0 |
| 72 | pat = re.compile(r'!\[.*?\]\((.*?)\)', re.DOTALL) |
| 73 | |
| 74 | for m in pat.finditer(md): |
| 75 | # --- text before this image --------------------------------------- |
| 76 | txt = md[pos : m.start()].strip() |
| 77 | if txt: |
| 78 | blocks.append({"type": "text", "text": txt}) |
| 79 | |
| 80 | # --- the image itself --------------------------------------------- |
| 81 | img_path = unquote(m.group(1)) |
| 82 | img_path = os.path.join(base_dir, img_path) |
| 83 | |
| 84 | blocks.append({"type": "image_url", "image_url": {"url": pil_to_data_uri(Image.open(img_path), fmt="PNG")}}) |
| 85 | pos = m.end() |
| 86 | |
| 87 | # --- any trailing text ------------------------------------------------- |
| 88 | tail = md[pos:].strip() |
| 89 | if tail: |
| 90 | blocks.append({"type": "text", "text": tail}) |
| 91 | |
| 92 | return blocks |
| 93 | |
| 94 | def compute_vlm_ppl(content): |
| 95 | VLLM_BASE_URL = "http://localhost:7000/v1" |
no test coverage detected