
    cTj+                        d Z ddlZddlZddlmZ  ee      j                  Zej                  j                  d e
e             ddlZddlZddlZddlZddlZ ej(                         Zej-                  d e
edz  dz  dz  dz        	       ej-                  d
d	       edk(  rej1                         nej1                  g       Z eej4                        Zej8                  Zg dZdj?                  g d      Z dj?                  g d      Z!d Z"edk(  rA ejF                  ejH                        Z%e%d   D ]  Z& e"e&e%d   e&   d            e'd       yy)u  s38 플레이트 s29 풀 체인 — 8개 실외 플레이트 전부.

플레이트별: ①nb2 3롤(마스터 참조) → ②GPT/Gemini 0-10 합산 판정(축:
프롬프트 충실+물리 정합+★마스터 구조 일치+★지역 실물 사실성, 동점=
Gemini 우선) → ③승자 이중 critique → 결함 취합 i2i 수정(0건=승자 그대로)
= bg3_<tag>.png. 판정 기록=plans/s38_light_v1.json plate_chain.
    N)Pathz--masterout
forest_maptop2ztop2_photo_fixed_nb2.png)defaultz--prefixbg3__main__)ABC
)z>You are given ONE image-generation prompt, ONE MASTER locationzCphotograph (the ground truth of this property), and THREE candidatezAphotographs labelled A, B, C in the order attached, all generatedz7from that prompt with the master attached as reference.z2Pick the ONE candidate that best satisfies ALL of:z>- fidelity to the prompt (structure, camera, materials, state,z5  exclusions such as no people and no readable text),z=- physical coherence (no floating/split volumes, stairs reachz(  their destination, possible geometry),zA- MASTER consistency (storey count, massing, the external stair'szB  full run, rooftop structure placement, walls, gate and yard mustz  match the master photograph),z>- regional authenticity (the prompt declares a real region andz=  era; everything must look like that region's real, ordinaryu8     built environment — nothing foreign or genericized).z@Check every candidate point by point; base verdicts only on whatz<is visible. Also give every candidate an integer score 0-10.z@Output: winner, ranking best-to-worst, and per candidate a scorez:plus a one-line Korean verdict citing the decisive points.)
z<You are given: an image-generation prompt, a MASTER locationz@photograph (ground truth), and ONE photograph generated from thez@prompt with the master as reference. List what is WRONG with it:z/- fidelity to the prompt, - physical coherence,zB- MASTER consistency (storeys, massing, stair run, rooftop, walls,z?  gate, yard), - regional authenticity per the prompt's region.z9Base every finding only on what is visible. Ignore taste.z=issues: issue_ko (short Korean line) + fix_en (ONE imperativez>English edit fixing exactly that while changing nothing else).z Empty array if nothing is wrong.c                 	  
 t        j                  t        j                        }|j	                  di       j	                  | i       }g }t
        D ]  
t        j                  t         d|  d
j                          dz  }t        j                  dt         d|  d
j                          |t        j                  t        fgd|       |j                  |        dd|z   d	dd
d	t        j                  t              g}t        t
        |      D ]A  \  
}|j                  dd
 dd	       |j                  t        j                  |             C i ddt         d|  fddt         d|  ffD ]4  \  }}	t        j                   |	t"        |t$        j&                  |      |<   6 t
        D 

ci c]  

t)        
fddD               }}
t+        |j-                               }|j/                         D 
cg c]  \  }
}||k(  s|
 }}
}d   d   t1        |fd      }t        j                  t         d|  d|j                          dz  }|j3                  ||t        D ci c]  }||   d    c}d       t5        d|  d| d|        dd|z   d	ddd	t        j                  t              ddd	t        j                  |      g}i }ddt         d|  fddt         d|  ffD ]4  \  }}	t        j                   |	t6        |t$        j8                  |      ||<   6 d D cg c]  \  }}||   d!   D ]  }d"| d#|d$      }}}}|D ci c]  }|||   d!    c}|d%<   t        j                  t         d|  dz  }|j;                         r|j=                          |s+t?        j@                  ||       d&|d'<   t5        d|  d(       nd)jC                  t$        jD                  d*d+jC                  |      z   d,t$        jF                  g      }t        j                  dt         d-|  |t$        jH                  |fd.t        fgd|       d/|d'<   t5        d|  d0tK        |       d1       t        jL                  t        j                  |       y c c}
w c c}}
w c c}w c c}}}w c c}w )2Nplate_chain_z.pngs38_z16:9)aspect_ratioout_pathtextzTHE PROMPT:
)typer   z!MASTER photograph (ground truth):z
Candidate :gpt_judge_gpt_
gemini-pro_judge_gem_)modelc              3   R   K   | ]  }t        fd |   d   D                 yw)c              3   :   K   | ]  }|d    k(  s|d     yw)labelscoreN ).0vlabs     Q/Users/manta/Documents/Projects/TheRoad-I1/scratchpad/forest_exp/x_plate_chain.py	<genexpr>z"chain.<locals>.<genexpr>.<genexpr>Z   s#     K!5A7s9JQwZ!5s   
verdictsN)next)r!   mjudger#   s     r$   r%   zchain.<locals>.<genexpr>Y   s-      (&A 	Kq*!5KK&s   $')r   r   rankingc                 2    | v rj                  |       S dS )Nc   )index)r#   gem_ranks    r$   <lambda>zchain.<locals>.<lambda>_   s%     %-NN3$7 %)&(%)    )keyr&   )totalsselectedprefixr&   [z] judge totals=z sel=zMASTER photograph:zPhotograph to examine:
_crit_gpt_
_crit_gem_))r   zGPT VLM)r   z
Gemini VLMissuesz- (z) fix_encritiqueTfix_skippedu   ] 결함 0 — 승자 그대로z

zISSUES TO FIX:
r   ut   The attached MASTER photograph is the ground truth for the property's structure — align every fixed feature to it._fix_uL   MASTER photograph — ground truth; align the edited photo's building to it.Fu	   ] 결함 u   건 수정 완료)'F	load_planLPLAN
setdefaultLABELSOUTPREFIXlowerimg_nb2WMASTER_REF_LABELMASTERappendpng_data_urlzipllm	JUDGE_SYSTJUDGE_SCHEMAsummaxvaluesitemsminupdateprintCRITIQUE_SYSCRITIQUE_SCHEMAexistsunlinkshutilcopyjoinFIX_HEADPRESERVE_TAIL	FIX_LABELlen	save_plan)tag	bg_promptplanreccandsr   partspr   mtagr#   r2   bestttiedselsel_pathr(   parts2r:   t2i	fix_linesfinalfpr.   r)   s             `              @@r$   chainrw   D   s   ;;qvvD
//-
,
7
7R
@CEee#a		}D99			D#a		}5y&&/0v	  	S  o	&AB&IJ^^F#%E fe$Qf
3%q.ABCQ^^A&' % E$vhk# ?@%fX['FGItuuT9eQ^^#(*eI 4:;39C 3 (&( ( (39  ; v}}D$lln:nFCT	CnD:\"9-H
d ) *Cuu&3%qT::HJJ&cV&+-&+ a 44&+-. / 
AcU/&se
45'BC';<nnV$'?@nnX&	(F
 H$vhj >?%fXZu'EFHt%%lF ! 1 1@H
#A5#AYUB"5/(3Q rd"Qx[M* 4 +#A  5 :BBAq(1+h//BC
OEEvhauD))E||~He$!M#567[[JJ*TYYy-AAIOO	 
 	
		DcU+RKK*/0689  &		7
 #M#iI//@ABKKc; ;-5 Cs$   6R%R*R*2R07"R5!R<ext_tagsext_bgbg_prompt_enDONE)(__doc__r\   syspathlibr   __file__parentHEREpathinsertstr
forest_libr=   s37_rooftop_rebuildrG   s38_lightconti_fullr?   
s29_top_v2rO   argparseArgumentParser_apadd_argument__name__
parse_args_ARGSmasterrI   r4   rD   rB   r^   rN   rX   rw   r>   r@   p37rd   rW   r    r0   r$   <module>r      s\    
 H~ 3t9      h   S5L<&(+EE&G  H   U  +$
2NN2 	ell			II  	, yy  FR z
!++aff
C:c3x=%n56 	&M	 r0   