Spaces:
Running on Zero
Running on Zero
Download build_prompts.py from INTERNETCON/AI-KING-Studio: direct link, hf CLI and curl.
- Browser
- Download file 1.4 kB
-
https://huggingface.co/spaces/INTERNETCON/AI-KING-Studio/resolve/main/build_prompts.py
- Command line
-
hf download hf://spaces/INTERNETCON/AI-KING-Studio/build_prompts.py
-
curl -L -o build_prompts.py https://huggingface.co/spaces/INTERNETCON/AI-KING-Studio/resolve/main/build_prompts.py
1.4 kB
| """Build prompts.json for the Prompt Library tab from ../../images/prompt-pack.md. | |
| Run locally: python build_prompts.py [path/to/prompt-pack.md] | |
| Each fenced code block becomes a card: {section, label, prompt}. | |
| """ | |
| import json, re, sys, pathlib | |
| def parse(md: str): | |
| cards, section, label = [], "General", "" | |
| lines = md.splitlines() | |
| i = 0 | |
| while i < len(lines): | |
| ln = lines[i] | |
| if ln.startswith("#"): | |
| section = ln.lstrip("#").strip() | |
| label = "" | |
| elif re.match(r"^\*\*[^*]+\*\*\s*$", ln.strip()): | |
| label = ln.strip().strip("*").strip() | |
| elif ln.strip().startswith("```"): | |
| buf = [] | |
| i += 1 | |
| while i < len(lines) and not lines[i].strip().startswith("```"): | |
| buf.append(lines[i]); i += 1 | |
| text = "\n".join(buf).strip() | |
| if text: | |
| cards.append({"section": section, "label": label or "Prompt", "prompt": text}) | |
| i += 1 | |
| return cards | |
| if __name__ == "__main__": | |
| here = pathlib.Path(__file__).parent | |
| src = pathlib.Path(sys.argv[1]) if len(sys.argv) > 1 else here.parent.parent / "images" / "prompt-pack.md" | |
| cards = parse(src.read_text(encoding="utf-8")) | |
| (here / "prompts.json").write_text(json.dumps(cards, indent=1, ensure_ascii=False), encoding="utf-8") | |
| print(f"wrote {len(cards)} prompt cards from {src}") | |