Spaces:
Sleeping
Sleeping
Download skill/scripts/create_science_project.py from cpuai/ahp-development-workstation: direct link, hf CLI and curl.
- Browser
- Download file 3.45 kB
-
https://huggingface.co/spaces/cpuai/ahp-development-workstation/resolve/main/skill/scripts/create_science_project.py
- Command line
-
hf download hf://spaces/cpuai/ahp-development-workstation/skill/scripts/create_science_project.py
-
curl -L -o create_science_project.py https://huggingface.co/spaces/cpuai/ahp-development-workstation/resolve/main/skill/scripts/create_science_project.py
3.45 kB
| #!/usr/bin/env python3 | |
| # -*- coding: utf-8 -*- | |
| """Create a non-destructive Hyperframes science project from an evidence-linked JSON.""" | |
| import argparse,json,re,shutil | |
| from pathlib import Path | |
| ROOT=Path(__file__).resolve().parents[1] | |
| MODULES=['narrate.py','mix_audio.py','preview_voices.py','validate_release.py','build_science_composition.py','audit_science.py','repair_subtitles.py','verify_subtitles.py','safezone_audit.py','audit_domain.py'] | |
| def make(output,story): | |
| output=Path(output).expanduser().resolve() | |
| story=Path(story).expanduser().resolve() | |
| cfg=json.loads(story.read_text(encoding='utf-8')) | |
| slug=cfg.get('slug','') | |
| if not re.fullmatch(r'[A-Za-z][A-Za-z0-9_-]{1,79}',slug):raise ValueError('invalid slug') | |
| if not cfg.get('claims') or not cfg.get('scenes'):raise ValueError('requires claims and scenes') | |
| if output.exists():raise FileExistsError('Refusing to overwrite existing project: '+str(output)) | |
| output.mkdir(parents=True) | |
| for folder in ('assets/scenes','assets/diagrams','assets/vendor','assets/voice','output','scripts'): | |
| (output/folder).mkdir(parents=True,exist_ok=True) | |
| shutil.copy2(story,output/'story.json') | |
| shutil.copy2(ROOT/'requirements.txt',output/'requirements.txt') | |
| for name in MODULES: shutil.copy2(ROOT/'scripts'/name,output/'scripts'/name) | |
| for i,sc in enumerate(cfg['scenes']): | |
| if sc.get('diagram_svg') and not (output/sc['diagram_svg']).exists(): | |
| loc=output/sc['diagram_svg'] | |
| if output not in loc.resolve().parents:raise ValueError('invalid diagram path') | |
| loc.parent.mkdir(parents=True,exist_ok=True) | |
| # This is explicitly a PLACEHOLDER and audit_science blocks final release. | |
| loc.write_text(f'<svg xmlns="http://www.w3.org/2000/svg" data-placeholder="true" viewBox="0 0 1080 1920"><rect width="1080" height="1920" fill="#17385c"/><text x="540" y="1020" font-family="sans-serif" font-size="60" fill="white" text-anchor="middle">请绘制第 {i+1} 幕科学示意图</text></svg>',encoding='utf-8') | |
| pkg={'name':f'hyperframes-science-{slug}','private':True,'type':'module','version':'0.1.0', | |
| 'scripts':{'preview':'hyperframes preview','check':'hyperframes check --json', | |
| 'snapshots':'hyperframes snapshot --frames 8 --output output/snapshots', | |
| 'render':f'hyperframes render --fps {cfg.get("video",{}).get("fps",30)} --workers 2 --no-browser-gpu --output output/{slug}.mp4'}, | |
| 'dependencies':{'hyperframes':'^0.8.115','gsap':'^3.15.0'}} | |
| (output/'package.json').write_text(json.dumps(pkg,ensure_ascii=False,indent=2),encoding='utf-8') | |
| (output/'README.md').write_text('本项目用 Hyperframes Science Skill v1.1 创建。用真正科学示意图替换 data-placeholder 画面,并先核实 story.json 的证据链。\n\n'+ | |
| '命令:pip install -r requirements.txt;npm install;python scripts/narrate.py;python scripts/repair_subtitles.py;python scripts/mix_audio.py;python scripts/build_science_composition.py;python scripts/audit_science.py;npm run check;npm run snapshots;npm run render;python scripts/validate_release.py。\n',encoding='utf-8') | |
| return output | |
| if __name__=='__main__': | |
| p=argparse.ArgumentParser();p.add_argument('--output',required=True);p.add_argument('--story',default=str(ROOT/'assets/science-story-template.json'));a=p.parse_args() | |
| print(make(a.output,a.story)) | |