
    Jj0                     4   d Z ddlZddlZddlmZ ej
                  j                  d e ee      j                               ddl
ZddlZddlZej                   dz  Zd Zd Zd Zd Zd	j-                  g d
      Zd ZdZdZdZd Zd Zedk(  r e        yy)u7  s16 — nb2 체인 (사용자 지시, 2026-07-05):

  A. **nb2 가 코드 대신 블록 다이어그램 작도** — 그림 중심이 아니라 구조 파악
     전용: 플랫 단색 블록(사각/원)만, 균일 가는 윤곽, 텍스처/음영/3D/원근/상세
     금지. 중요 물체들과 상대적·물리적·논리적 관계에 집중. "코딩처럼 단순한
     블록 구조만". 입력 = 추출 FACTS 텍스트만(레이아웃 참조 이미지 0).
  B. A 를 참조(모사 금지)로 **nb2 가 상세 fp** — LLM 상세 설명(층수 포함)+FACTS
     +실내 fp 드래프팅 스타일 레퍼런스.
  C. B(fp) 를 공간 SOT 로 **실사 부감 2장 — gpt-image-2 / nb2 각각**, 상세 설명
     ·FACTS·장소 데이터 전부 주입.
시나리오 중립: 템플릿은 일반 어휘만, 구체 내용은 데이터(FACTS/desc/loc/override).
사용: .venv/bin/python s16_nb2_chain.py [--only blocks|fp|photos|html]
산출: out/blockset/nb2_{blocks,fp}.png, out/blockset/photo_fromfp_{gpt,nb2}.png,
      plans/nb2_chain_prompts.json, blockgen.html 갱신
    N)Pathblocksetc                 z    dj                  dj                  g d      dt        j                  | d      z   g      S )N


)u@   Draw ONE SCHEMATIC BLOCK DIAGRAM of a real property's layout —z8the kind of flat figure a computer program draws: strictz>TOP-DOWN, plain solid-colour rectangles and circles on a plainz6light background, uniform thin dark outlines. PURPOSE:u@   structural comprehension only — which elements exist and theirz>relative sizes, positions and physical/logical relations (whatz:is beside / inside / connected to what). NOT a picture: noz8texture, no materials, no shading, no shadows, no 3D, nou:   perspective, no artistic detail, no tiny symbols — everyz=element is ONE plain block (rectangle or circle). Fill colourz?encodes ONLY the height layer, in flat steps (darker = higher).z?No text, letters, numbers, markers, legend or compass anywhere.z>LAYOUT RELATIONS (draw exactly these elements and relations):
Fids)joinS14summary_lines)layouts    Q/Users/manta/Documents/Projects/TheRoad-I1/scratchpad/forest_exp/s16_nb2_chain.pyblocks_promptr      sD    ;;		 
 	 	J


F
.	/      c                     dj                  dj                  g d      t        j                  |      t        j                  | d      t        j                  t        j
                  g      S )Nr   r   )z?The FIRST attached image is a rough BLOCK REFERENCE of one realz;property: it tells you only WHAT exists and the APPROXIMATEz@arrangement. Do NOT trace or copy its composition, block shapes,u@   proportions or spacing — compose the site plan yourself so thez=place reads as a real, believable property that satisfies thez8facts below. Its fill colours encode height layers only.Fr   )r
   S15
desc_blockfacts_blockSTYLE_REF_NOTESTYLE_2D)r   recondescs      r   	fp_promptr   1   sU    ;;		 
 	 	tE*  r   c                 n   t        j                         }dj                  |j                  d      xs g       }dj                  d dj                  g d      t	        j
                  |      t	        j                  | |      dt        j                  |      z   |dj                  g d      fD              S )	Nr   photo_appearancer   c              3   $   K   | ]  }|r| 
 y wN .0xs     r   	<genexpr>zphoto_prompt.<locals>.<genexpr>E   s!       #Q. 
/  #   u?   The FIRST attached image is the property's SITE PLAN — use itz?for STRUCTURE ONLY: what exists, counts, relative positions andz>connections. It is a flat drawing: its colours, flat fills andz:graphic style are NOT materials and must not appear in thez:output. Compose the real scene freely from that structure.r   .WHAT THIS PLACE LOOKS LIKE (production data):
)?Render ONE PHOTOREALISTIC bird's-eye location reference of this?property from a high oblique angle tilted about 30 degrees from=vertical: real built volumes ordered by the described heightsu@   and storeys, with real varied materials per the data — never az>uniform drawing-coloured mass. Plain even daylight, completelyz9unpopulated, no movable props, no posted papers, no text,z:letters, circles, markers or legend anywhere. Never exposezinterior rooms.r   load_overridesr
   getr   r   r   	loc_linesr   r   r   r	   ov
appearances         r   photo_promptr0   B   s    				B266"45;<J;; 		 
 	 	tC(9
--
			 	
 		#   r   c                 n   t        j                         }dj                  |j                  d      xs g       }dj                  d dj                  g d      t	        j
                  |      t	        j                  | |      dt        j                  |      z   |dj                  g d      fD              S )	u   생활감 변형 — 특정 물품 열거 금지(사용자 규칙): 실주민의 일상 흔적을
    모델이 자유 창작. 사람/가독 텍스트/스토리 특정 소품만 금지.r   r   r   c              3   $   K   | ]  }|r| 
 y wr   r   r   s     r   r"   z%photo_prompt_lived.<locals>.<genexpr>d   s!       #Q6 
7  #r#   r$   r   r%   )r&   r'   r(   z0and storeys, real varied materials per the data.z?No people in frame, no readable text, letters, numbers, markersz:or legend anywhere, and nothing tied to any specific storyz=event. BUT the place must clearly look LIVED-IN: the ordinaryz=everyday traces that real residents of such a place naturallyu8   leave — you invent them freely; their kind, amount andz=placement are your choice, true to how this regional buildingz6type actually looks inhabited. Avoid a sterile, empty,z+showroom look. Never expose interior rooms.r)   r-   s         r   photo_prompt_livedr3   _   s     
			B266"45;<J;; 		 
 	 	tC(9
--
			 
 	#   r   r   )z@Before generating, use web search to ground yourself in how thisuC   regional building type actually looks in reality — its materials,zEweathering and the everyday traces its residents leave. Then generatez*ONE image that satisfies everything below.c                    ddl }ddl}t        j                         }|j	                  t        |      j                               j                  d      }|j                         }d}dD ]  }		 |j                  j                  dd|	iddd	d
gddt        dz   | z   ddd| dgdg      }
d}d}|
j                  D ]4  }t        |dd      }|dk(  rt        |dd      }|s%dt        |      v s3d}6 |st        d      |j!                  |j#                  |             t        j$                  dd|	 ddt        |      g|t'        |j                         |z
  d      t        |      | d	       t)        d |	 d!| d"       |c S  t        d&|       # t*        $ r3}|}t        j$                  d#d|	t        |      dd$ d%       Y d}~dd}~ww xY w)'uK   gpt Responses API — web_search + image_generation 도구 결합 (실험).r   Nascii)
web_searchweb_search_previewzgpt-5.5typeimage_generation	1536x1024high)r8   sizequalityuser
input_textr   )r8   textinput_imagezdata:image/png;base64,)r8   	image_url)rolecontent)modeltoolsinputFimage_generation_callresultr6   Tz)no image_generation_call result in outputimgzgpt-responses+zsearch+generates16_photo_websearch   )	kindenginemodetagrefsweb_search_invokeddur_soutpromptzwebsearch photo OK (z, searched=)	img_errori  )rM   rP   toolerrorzwebsearch photo failed: )base64timeFopenai_client	b64encoder   
read_bytesdecode	monotonic	responsescreateWEBSEARCH_PREAMBLEoutputgetattrstrRuntimeErrorwrite_bytes	b64decoderunlogroundprint	Exception)rU   ref_pngout_pathrZ   r[   clientb64t0lastws_toolrespimg_b64searcheditemtexcs                   r   websearch_photor|      s   __F


4=335
6
=
=g
FC		BD7"	A##**( 2K#)+, !')/&86AC*$:3%"@B4   + D GHD&$///%dHd;GQ/#H $ "#NOO  !1!1'!:;HHey/I/8M"7|nH$T^^%5%:A> ]f	> ?
 (	XJaHIO? 8H 1$8
99	  	ADHHk2G%C#@ A A	As&   -A3F!F/BF	G(GGuA   (no layout reference — compose the diagram from the text alone)u   BLOCK REFERENCE (what exists + approximate arrangement only) — never trace its shapes; fill colours encode height layers only.u|   SITE PLAN (spatial ground truth) — translate to real photographic volumes; never copy its drawing style; no text anywhere.c           	          i  fd}t        j                         }|dv r7t              }|d<   t        j                  d|g t
        dz          |        |dv rlt         |      }|d<   t        t
        dz  fg}|r!|j                  t         j                  |f       t        j                  d||t
        dz          |        |d	k(  rt
        dz  }t         |d
      }	|	d<   t        j                  d|	|gt
        dz          |        t         |d      }
|
d<   t        j                  d|
t        |fgt
        dz          |        |	d<   	 t        |	|t
        dz          |        y |dv rt
        dz  }|dk(  rdnd}t!         |d
      }	|	d| d<   t        j                  d| d|	|gt
        d| dz          |        t!         |d      }
|
d| d<   t        j                  d| d|
t        |fgt
        d| dz          |        y y # t        $ r}t        d|       Y d }~d }~ww xY w)Nc                  ^    t        j                  d       t        j                          y )Nnb2_chain_prompts)r\   	save_planr   
build_html)r   promptsr   s   r   savezrun.<locals>.save   s     	'1vu%r   )allblocksznb2_blocks.pngs16_nb2_blocks)rp   )r   fpz
nb2_fp.png
s16_nb2_fpphotos3Tr   zphoto_fromfp3_gpt.pngs16_photo_fromfp3_gpt)rQ   rp   Fzphoto_fromfp3_nb2.pngs16_photo_fromfp3_nb2zphoto_fromfp3_gptsearch.pngzwebsearch variant failed:)r   photosphotos2r   2 photo_fromfpz_gpt.pngs16_photo_fromfp_gptz_nb2.png_nb2)r   	indoor_fpr   r\   img_nb2OUTBr   NB2_FP_BLOCKS_LABELappendNB2_STYLE_LABELr3   img_gptNB2_PHOTO_FP_LABELr|   rn   rm   r0   )r   r   r   onlyr   fp_styleprQ   fp_pngpgpnr{   sfxr   s   ``           @r   runr      s   G& }}U#H  &!$% !			"ArD;K4KL}feT* !$d-=&=>?KK,,h78			,4$2EFy$t>+-'(			)2VH"99	;t?+-'(			)2&/0"99	; 	13-.	4B/L(LM 	++$Y&cB&%4802,se8,-			$SE.&LX">>	@&%5902,se8,-			$SE.&/0LX">>	@ 	 ,	  	4-s33	4s   H) )	I2IIc                     t        j                         } | j                  ddg d       | j                         }t	        j
                         }t	        j                  d      }t	        j                  d      }|j                  dk(  rt        j                  ||       nt        ||||j                         t	        j                  dd	|j                  d
       y )Nz--onlyr   )r   r   r   r   r   r   html)defaultchoicesblockset_layout_v2fp_place_descr   stages16_nb2_chain)rM   r   done)argparseArgumentParseradd_argument
parse_argsr\   
load_recon	load_planr   r   r   r   rk   )apargsr   r   r   s        r   mainr      s    		 	 	"BOOHe0  1 ==?DLLNE[[-.F;;'DyyFvu%E64+HHgKLr   __main__)__doc__r   syspathlibr   pathinsertrg   __file__parent
forest_libr\   s14_blockgenr   s15_fp_redor   OUTr   r   r   r0   r3   r
   rd   r|   NB2_BLOCKS_LABELr   r   r   r   __name__r   r   r   <module>r      s     
  3tH~,,- .   uuz*": F YY    ,:^ . + 
6rM  zF r   