Spaces:
Sleeping
Sleeping
Download tutorial_routes.py from ohgnues/image-editing-study: direct link, hf CLI and curl.
- Browser
- Download file 1.08 kB
-
https://huggingface.co/spaces/ohgnues/image-editing-study/resolve/main/tutorial_routes.py
- Command line
-
hf download hf://spaces/ohgnues/image-editing-study/tutorial_routes.py
-
curl -L -o tutorial_routes.py https://huggingface.co/spaces/ohgnues/image-editing-study/resolve/main/tutorial_routes.py
1.08 kB
| """Public guidance examples; distinct from the evaluated sample set.""" | |
| import json | |
| from pathlib import Path | |
| from fastapi import HTTPException | |
| from fastapi.responses import FileResponse | |
| def register_tutorial_routes(app, root): | |
| root = Path(root) | |
| data_root = root / 'data' | |
| manifest_path = data_root / 'tutorials.json' | |
| def examples(): | |
| if not manifest_path.is_file(): | |
| return [] | |
| return json.loads(manifest_path.read_text()) | |
| def tutorials(): | |
| return examples() | |
| def tutorial_media(name: str): | |
| allowed = {Path(im['src']).name for row in examples() for im in row['images']} | |
| if name not in allowed or Path(name).name != name: | |
| raise HTTPException(404) | |
| base = (data_root / 'tutorials').resolve() | |
| path = (base / name).resolve() | |
| if not path.is_relative_to(base) or not path.is_file(): | |
| raise HTTPException(404) | |
| return FileResponse(path, headers={'Cache-Control': 'public, max-age=3600'}) | |