Spaces:
Sleeping
Sleeping
Download scripts/smoke_test.py from DataWisp/dot2dot-generator-kids: direct link, hf CLI and curl.
- Browser
- Download file 1.49 kB
-
https://huggingface.co/spaces/DataWisp/dot2dot-generator-kids/resolve/main/scripts/smoke_test.py
- Command line
-
hf download hf://spaces/DataWisp/dot2dot-generator-kids/scripts/smoke_test.py
-
curl -L -o smoke_test.py https://huggingface.co/spaces/DataWisp/dot2dot-generator-kids/resolve/main/scripts/smoke_test.py
1.49 kB
| from pathlib import Path | |
| import json | |
| import sys | |
| from PIL import Image, ImageDraw | |
| ROOT = Path(__file__).resolve().parents[1] | |
| SRC = ROOT / "src" | |
| if str(SRC) not in sys.path: | |
| sys.path.insert(0, str(SRC)) | |
| from dot2dot.pipeline import DotToDotPipeline | |
| def make_duck_like_outline(path: Path) -> Path: | |
| image = Image.new("RGB", (1200, 1200), "white") | |
| draw = ImageDraw.Draw(image) | |
| draw.ellipse((250, 430, 860, 900), outline="black", width=18) | |
| draw.ellipse((720, 260, 980, 520), outline="black", width=18) | |
| draw.polygon([(960, 380), (1120, 330), (1110, 430)], outline="black", fill="white") | |
| draw.line((370, 860, 320, 1030), fill="black", width=18) | |
| draw.line((540, 860, 520, 1030), fill="black", width=18) | |
| draw.arc((120, 510, 360, 780), start=300, end=80, fill="black", width=18) | |
| image.save(path) | |
| return path | |
| def main() -> None: | |
| output_dir = ROOT / "output" / "smoke_test" | |
| input_dir = ROOT / "input" / "smoke_test" | |
| output_dir.mkdir(parents=True, exist_ok=True) | |
| input_dir.mkdir(parents=True, exist_ok=True) | |
| source_path = make_duck_like_outline(input_dir / "duck_outline.png") | |
| pipeline = DotToDotPipeline() | |
| result = pipeline.build_book( | |
| input_dir=input_dir, | |
| output_dir=output_dir, | |
| age_key="6-8", | |
| title="Patinho Liga Pontos", | |
| trim_size="8.5x11", | |
| ) | |
| print(json.dumps({"source": str(source_path), **result}, indent=2, ensure_ascii=False)) | |
| if __name__ == "__main__": | |
| main() | |