Buckets:
| from pathlib import Path | |
| import importlib.util,json,base64,hashlib,time | |
| from PIL import Image | |
| root=Path('/marimo/nyako-generation');source=Path('/marimo/api_generate (4).py') | |
| spec=importlib.util.spec_from_file_location('user_generation',source);mod=importlib.util.module_from_spec(spec);spec.loader.exec_module(mod) | |
| base='http://127.0.0.1:7860' | |
| def status(stage,**kw): | |
| d={'stage':stage,**kw};(root/'hires-status.json').write_text(json.dumps(d,indent=2));print(json.dumps(d),flush=True) | |
| checkpoint=mod.select_checkpoint(mod.api_call(base,'/sdapi/v1/sd-models')) | |
| modules=mod.select_modules(mod.api_call(base,'/sdapi/v1/sd-modules')) | |
| payload=mod.make_payload(checkpoint,modules) | |
| original=payload.copy() | |
| caption=Path('/data/nyako-training/artifacts/dataset/001_00001.txt').read_bytes() | |
| assert caption.startswith(b'@nyako, ') | |
| payload['prompt']=caption.decode('utf-8-sig').strip()+'\n<lora:nyako_style:1>' | |
| assert all(payload[k]==v for k,v in original.items() if k!='prompt') | |
| assert payload['steps']==36 and payload['hr_second_pass_steps']==32 and payload['enable_hr'] | |
| assert payload['width']==1024 and payload['height']==1536 and payload['hr_scale']==1.5 | |
| (root/'hires-request.json').write_text(json.dumps(payload,ensure_ascii=False,indent=2)) | |
| status('generating',script=str(source),steps=payload['steps'],hires_steps=payload['hr_second_pass_steps'],sampler=payload['sampler_name'],scheduler=payload['scheduler'],seed=payload['seed'],upscaler=payload['hr_upscaler'],denoising_strength=payload['denoising_strength'],final_size=[1536,2304],changed_parameters=['prompt']) | |
| try: | |
| result=mod.api_call(base,'/sdapi/v1/txt2img',payload,timeout=3600) | |
| assert result.get('images') | |
| files=[] | |
| for i,encoded in enumerate(result['images']): | |
| p=root/f'nyako_style_script_hires_{payload["seed"]}_{i+1}.png';p.write_bytes(base64.b64decode(encoded.split(',')[-1])) | |
| with Image.open(p) as im: | |
| assert im.size==(1536,2304),f'Unexpected image size: {im.size}' | |
| im.verify() | |
| files.append(str(p)) | |
| (root/'hires-response-info.json').write_text(result.get('info','{}')) | |
| status('complete',images=files,final_size=[1536,2304],steps=36,hires_steps=32,source_script_sha256=hashlib.sha256(source.read_bytes()).hexdigest(),caption_sha256=hashlib.sha256(caption).hexdigest(),changed_parameters=['prompt']) | |
| except Exception as e: | |
| status('failed',error_type=type(e).__name__) | |
| # Save full error privately, never emit possible caption-containing API errors. | |
| (root/'hires-error.txt').write_text(str(e));raise SystemExit(1) | |
Xet Storage Details
- Size:
- 2.49 kB
- Xet hash:
- a5ad2568766695016834860d28b4090b8b8eb7ae7656f9a0ef526b8e5bac12b2
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.