from pathlib import Path import json,sys,time,requests from PIL import Image root=Path('D:/web/dj');state=root/'integration-work/reference-image-live-result.json' config=json.loads((root/'model-bridge/client.json').read_text(encoding='utf-8-sig'));base=config['url'].rstrip('/') headers={'Authorization':'Bearer '+config['token']} if sys.argv[1]=='submit': assert not state.exists(),'Poll existing task instead' with (root/'integration-work/gpu1-8189-image-verification.png').open('rb') as image: r=requests.post(base+'/v1/images/edits',headers=headers,data={'model':'qwen_image_2_1','prompt':'Keep the exact cup shape, handle, camera angle, wooden table and soft daylight from the reference image. Change only the red ceramic glaze to deep cobalt blue. No text.','size':'512x512','n':'1','gpu':'gpu1'},files=[('image[]',('reference.png',image,'image/png'))],timeout=45) r.raise_for_status();result=r.json();assert result['provider_id']=='gpu1_8189';state.write_text(json.dumps(result));print(json.dumps(result)) else: saved=json.loads(state.read_text());jid=saved['task_id'] for _ in range(8): r=requests.get(base+'/v1/images/task/'+jid,headers=headers,timeout=15);r.raise_for_status();result=r.json() if result['status']=='completed': raw=requests.get(result['image_url'],timeout=30);raw.raise_for_status();out=root/'integration-work/reference-image-live-blue-cup.png';out.write_bytes(raw.content) with Image.open(out) as im:im.verify() saved.update(status='completed',provider_id=result['provider_id'],output=str(out));state.write_text(json.dumps(saved,indent=2));print(json.dumps(saved));break if result['status']=='failed':raise RuntimeError(result) print(json.dumps({'status':result['status'],'provider':result.get('provider_id')}),flush=True);time.sleep(5)