+
    „°ñj„(  ã                   ó
  € ^ RI t ^ RIt^ RIt^ RIt^ RIHt ^ RIt^ RIt^ RI	t	^ RI
HtHt  ! R R]P                  4      t ! R R]P                  4      tRRR	RR
R/t ! R R]P                  4      t ! R R]4      tR R ltR# )é    N)Úoverride)ÚComfyExtensionÚioc                   óP   a € ] tR t^t o ]R 4       t]RV 3R lR ll4       tRtV tR# )ÚMOSSImageLayoutPromptc                óÐ  € \         P                  ! R RRR\         P                  P                  RRRRR7      \         P                  P                  RR	R
7      \         P
                  P                  RR^R^RR7      \         P
                  P                  RR^R^RR7      \         P                  P                  RRRR7      .\         P                  P                  RR7      .RR7      # )r   zMOSS-Image Layout Promptúmodel/conditioning/moss_imagez[Builds a MOSS-Image layout prompt from the prompt and the boxes from Create Bounding Boxes.ÚpromptTzDescription of the whole image.)Ú	multilineÚdynamic_promptsÚtooltipÚelementz}Prompt elements from the node Create Bounding Boxes. The description is the box's caption, text boxes also render their text.)r   Úwidthi   i @  zAWidth of the generated image; the boxes are placed in its pixels.©ÚdefaultÚminÚmaxÚstepr   ÚheightzBHeight of the generated image; the boxes are placed in its pixels.Úcharacter_boxesÚ zƒNumbers of the object boxes to label as characters instead of objects, as tagged in the Create Bounding Boxes preview, e.g. "1, 3".)r   r   ©Údisplay_name©Únode_idr   ÚcategoryÚdescriptionÚinputsÚoutputsÚis_experimental)r   ÚSchemaÚStringÚInputÚArrayÚIntÚOutput©Úclss   &ÚAC:\Ai_Coding\apps\studio\ComfyUI\comfy_extras\nodes_moss_image.pyÚdefine_schemaÚ#MOSSImageLayoutPrompt.define_schema   sÜ   € ä�yŠyØ+Ø3Ø4Øuä—	‘	—‘ °DÈ$ÐXy�ÓzÜ—‘—‘˜yð  3r�ó  sÜ—‘—‘˜W¨d¸ÀÈBð  Y\�ó  ]Ü—‘—‘˜X¨t¸ÀÈRð  Z^�ó  _Ü—	‘	—‘Ð 1¸2ð  HO�ó  Pðô —Y‘Y×%Ñ%°8Ð%Ó<Ð=Ø ô
ð 	
ó    c                ó4   <€ V ^8„  d   QhRS[ P                  /# ©é   Úreturn©r   Ú
NodeOutput)ÚformatÚ__classdict__s   "€r)   Ú__annotate__Ú"MOSSImageLayoutPrompt.__annotate__"   s   ø€ ÷ \ñ \ÉBÏMÉMñ \r,   c           
     ó´  € \         P                  ! R V4       Uu0 uF  p\        V4      kK  	  pp. p\        \	        V\
        4      '       d   TM. 4       EF–  w  riV	P                  R4      R8X  d   RMV^,           V9   d   RMRp
RV
RV	P                  RR4      /pVR,          R8X  d   V	P                  RR4      VR&   V	P                  R	4      '       d   V	R	,          VR
&   V	R,          w  rÍrï\        P                  ! \        WÄ,          R,          ^	4      4      V^,          ,
          \        P                  ! \        WÓ,          R,          ^	4      4      V^,          ,
          \        P                  ! \        Wä,          R,          ^	4      4      V^,          ,
          \        P                  ! \        Wó,          R,          ^	4      4      V^,          ,
          .VR&   VP                  V4       EK™  	  V'       g   \        P                  ! V4      # RRVP                  4       /RVRRRR/p\        P                  ! \        P                   ! VRRR7      4      # u upi )z\d+ÚtypeÚtextÚ	characterÚobjectÚlabelÚcaptionÚdescr   Úcolor_paletteÚpaletteÚbboxiè  ÚsummaryÚitemsÚbbox_coord_spaceÚabs_centralizedÚbbox_formatÚyxyxF)Úensure_asciiÚ
separators)Ú,Ú:)ÚreÚfindallÚintÚ	enumerateÚ
isinstanceÚlistÚgetÚmathÚfloorÚroundÚceilÚappendr   r2   ÚstripÚjsonÚdumps)r(   r
   r   r   r   r   ÚiÚ
charactersrC   Úelr<   ÚitemÚy0Úx0Úy1Úx1Úlayouts   &&&&&&           r)   ÚexecuteÚMOSSImageLayoutPrompt.execute!   s  € ä&(§j¢j°¸Ô&IÓJÑ&I ”c˜!–fÑ&Iˆ
ÐJØˆÜ¬*°W¼d×*CÒ*C™wÈ×L‰EˆAØ Ÿf™f V›n°Ô6‘FÈAÐPQÍEÐU_ÔL_¹[ÐemˆEØ˜U I¨r¯v©v°f¸bÓ/AÐBˆDØ�G�} Ô&Ø!Ÿv™v f¨bÓ1��V‘Ø�v‰v�o×&Ò&Ø"$ _Õ"5��Y‘à �Z‰NˆB�BÜ ŸJšJ¤u¨R­[¸4Õ-?ÀÓ'CÓDÀvÐQRÅ{ÕRÔTX×T^ÒT^Ô_dÐegÕeoÐrvÕevÐxyÓ_zÓT{ð  Dð  HIõ  Iõ  UIÜ ŸIšI¤e¨B­K¸$Õ,>ÀÓ&BÓCÀfÐPQÅkÕQÔSW×S\ÒS\Ô]bÐceÕcmÐptÕctÐvwÓ]xÓSyð  }Bð  FGõ  }Gõ  TGðHˆD�‰Là�L‰L˜×ñ M÷ Ü—=’= Ó(Ð(Ø˜i¨¯©«Ð8¸'À5ÐJ\Ð^oÐq~ð  AGð  HˆÜ�}Š}œTŸZšZ¨¸UÈzÔZÓ[Ð[ùò# Ks   šI© N)r   ©	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Úclassmethodr*   rd   Ú__static_attributes__Ú__classdictcell__©r4   s   @r)   r   r      s3   ø‡ € Øñ
ó ð
ð" ÷\ñ \ó ö\r,   r   c                   óP   a € ] tR t^7t o ]R 4       t]RV 3R lR ll4       tRtV tR# )ÚMOSSImageControlc                óÈ  € \         P                  ! R RRR\         P                  P                  R4      \         P                  P                  R4      \         P                  P                  R4      \         P
                  P                  RRR	R
7      \         P
                  P                  RRRR
7      \         P                  P                  RRRRRRR7      \         P                  P                  RRRRRRR7      \         P                  P                  RRRRRRR7      .\         P                  P                  RR7      \         P                  P                  RR7      .RR7      # )rq   zMOSS-Image Color/Depth Controlr	   zlAdds the color region and depth maps for a MOSS-Image color/depth control adapter loaded with a LoRA loader.ÚpositiveÚnegativeÚvaeÚ	color_mapTzNOne flat color per region, at the output size. The colors are only region IDs.©Úoptionalr   Ú	depth_mapz,Depth map at the output size, near is white.Ústrengthç      ð?ç        g      $@g{®Gáz„?zkScales the maps' contribution to the image tokens. 0.0 is the same as no maps, 1.0 is the trained strength.r   Ústart_percentgü©ñÒMbP?z-Sampling percent at which the control starts.Úend_percentz‚Sampling percent at which the control ends. Ending early keeps the layout and depth while the rest of the steps loosen the shapes.r   r   )r   r!   ÚConditioningr#   ÚVaeÚImageÚFloatr&   r'   s   &r)   r*   ÚMOSSImageControl.define_schema8   s1  € ä�yŠyØ&Ø9Ø4ð Gä—‘×%Ñ% jÓ1Ü—‘×%Ñ% jÓ1Ü—‘—‘˜UÓ#Ü—‘—‘˜{°Tð  DT�ó  UÜ—‘—‘˜{°TÐCq�ÓrÜ—‘—‘˜z°3¸CÀTÐPTð  _L�ó  MÜ—‘—‘˜¸ÀÈ#ÐTYð  dS�ó  TÜ—‘—‘˜}°c¸sÈÐRWð  bf�ó  gð	ô —_‘_×+Ñ+¸Ð+ÓDÄbÇoÁo×F\ÑF\ÐjtÐF\ÓFuÐvØ ô!
ð 	
r,   Nc                ó4   <€ V ^8„  d   QhRS[ P                  /# r.   r1   )r3   r4   s   "€r)   r5   ÚMOSSImageControl.__annotate__N   s*   ø€ ÷ Eñ Eñ  DF÷  DQñ  DQñ Er,   c	           
     ó:  € WE3 U	u. uF   q™e   VP                  V	R,          4      MR NK"  	  p
p	\        R V
 4       R 4      pVf   \        P                  ! W4      # \	        R V
 4       4      pV
 Uu. uF„  pVf   \
        P                  ! V4      MfVP                  RR  VP                  RR  8X  d   TMC\        P                  P                  WÛP                  R	,          VP                  R,          RR4      NK†  	  p
p\
        P                  ! V
 Uu. uF"  p\        P                  P                  WÜ4      NK$  	  up^R7      V,          pRV/p\        P                  ! \        P                  ! WWx4      \        P                  ! W/Wx4      4      # u up	i u upi u upi )
Nc              3   ó0   "  € T F  qf   K  Vx € K  	  R # 5i©Nrf   ©Ú.0Úlatents   & r)   Ú	<genexpr>Ú+MOSSImageControl.execute.<locals>.<genexpr>P   s   é € ÐG©˜v—F’F«ùs   ‚Œ
c              3   óR   "  € T F  qf   K  VP                   ^ ,          x € K  	  R # 5irˆ   )Úshaper‰   s   & r)   rŒ   r�   S   s   é € ÐP±'¨”O�F—L‘L —O’O³'ùs   ‚'Œ'ÚbilinearÚcenter)ÚdimÚconcat_latent_image©ºNNNr•   r•   :Né   Néþÿÿÿéÿÿÿÿ)ÚencodeÚnextr   r2   r   ÚtorchÚ
zeros_liker�   ÚcomfyÚutilsÚcommon_upscaleÚcatÚresize_to_batch_sizeÚnode_helpersÚ+conditioning_set_values_with_timestep_range)r(   rs   rt   ru   rv   ry   rz   r}   r~   ÚmÚlatentsÚrefÚbatchr‹   ÚcontrolÚvaluess   &&&&&&&&&       r)   rd   ÚMOSSImageControl.executeM   s�  € àS\ÑRhÓiÑRhÈQ²�3—:‘:˜a �nÔ-ÀDÒHÑRhˆÐiÜÑG©ÓGÈÓNˆØŠ;Ü—=’= Ó4Ð4ÜÑP±'ÓPÓPˆñ ~EóFñ ~EÐsyð -3ªN”5×#Ò# CÔ(È&Ï,É,ÐWYÐWZÐJ[Ð_b×_hÑ_hÐikÐilÐ_mÔJmÁÜŸ™×2Ñ2°6¿9¹9ÀR½=È#Ï)É)ÐTVÍ-ÐYcÐemÓnòoñ ~Eð 	ð Fô —)’)Ñ[bÓcÑ[bÐQWœUŸ[™[×=Ñ=¸fÖLÑ[bÑcÐijÔkÐnvÕvˆØ'¨Ð1ˆÜ�}Š}œ\×UÒUÐV^Ðhuó  DÜ)×UÒUÐV^Ðhuó  DóEð 	Eùò jùòFùò ds   †&FÁ1B
FÄ(Frf   )NNr{   r|   r{   rg   ro   s   @r)   rq   rq   7   s3   ø‡ € Øñ
ó ð
ð( ÷Eñ Eó öEr,   rq   z
ai-toolkitzai-toolkit (kv_cache off)zMoss-Image-Editc                   óP   a € ] tR t^ft o ]R 4       t]RV 3R lR ll4       tRtV tR# )ÚTextEncodeMOSSImageEditc                ó–  € \         P                  ! R RRR\         P                  P                  R4      \         P                  P                  RRRR7      \         P
                  P                  RRR	R
7      \         P                  P                  R\        \        4      RR7      \         P                  P                  R\         P                  P                  \         P                  P                  R4      R^R7      R7      \         P                  P                  RRRRRRRR7      .\         P                  P                  4       .RR7      # )r¬   zText Encode MOSS-Image Editr	   zìEncodes an edit instruction with reference images for a MOSS-Image edit LoRA, use it for the negative prompt too. The references are used at the size they come in, scale them first. Without a VAE, the images only go to the text encoder.Úclipr
   T)r   r   ru   z:Encodes the images as reference latents for the edit LoRA.rw   Úedit_formatzòThe layout the edit LoRA was trained with: ai-toolkit's MOSS-Image Edit Training (its kv_cache option on or off) or Moss-Image-Edit. With kv_cache off the references also attend to the image being generated, so they are recomputed every step.)Úoptionsr   ÚimagesÚimageÚimage_)ÚinputÚprefixr   )ÚtemplateÚimage_strengthr{   r|   g      Y@gš™™™™™©?zŸScales how much the model attends to the images the text encoder sees (ai-toolkit formats, or no VAE): 0 ignores them, 1 is unchanged, above 1 emphasizes them.)r   r   r   r   Úadvancedr   r   )r   r!   ÚClipr#   r"   r€   ÚComborQ   ÚEDIT_FORMATSÚAutogrowÚTemplatePrefixr�   r‚   r   r&   r'   s   &r)   r*   Ú%TextEncodeMOSSImageEdit.define_schemag   s  € ä�yŠyØ-Ø6Ø4ð Gä—‘—‘˜fÓ%Ü—	‘	—‘ °DÈ$�ÓOÜ—‘—‘˜U¨TÐ;w�ÓxÜ—‘—‘˜}´d¼<Ó6Hð  SG�ó  HÜ—‘×!Ñ! (´R·[±[×5OÑ5OÔVX×V^ÑV^×VdÑVdÐelÓVmÐv~ð  EFÐ5Oó  6GÐ!ó  HÜ—‘—‘Ð/¸À#È5ÐW[Ðfjð  uV�ó  Wðô —_‘_×+Ñ+Ó-Ð.Ø ô
ð 	
r,   Nc                ó4   <€ V ^8„  d   QhRS[ P                  /# r.   r1   )r3   r4   s   "€r)   r5   Ú$TextEncodeMOSSImageEdit.__annotate__{   s   ø€ ÷ Rñ RÑY[×YfÑYfñ Rr,   c                ó|  € \         V,          w  rx\        V4       U	u. uF  q”V	,          f   K  WI,          NK  	  pp	. p
V'       g   VEf'   V^ 8”  Ed   V Fç  p\        R\        P                  ! RVP
                  ^,          VP
                  ^,          ,          ,          4      4      pV
P                  \        P                  P                  VP                  R^4      \        VP
                  ^,          V,          4      \        VP
                  ^,          V,          4      RR4      P                  ^R4      4       Ké  	  RP                  R \        \        V
4      4       4       4      V,           pVP                  W*R7      pVP!                  V4      p\        V
4      ^ 8”  Ed!   VR8w  Ed   \        P"                  ! V4      p. p\%        \'        VP)                  4       4      4      ^ ,           F¥  p\+        V^ ,          \,        4      '       du   \        P.                  P0                  P3                  V^ ,          R,          ^R7      w  ppVV.\5        VR,          VR,          ,          4      ^,          ,          ,          pK”  VP                  R	4       K§  	  \6        P8                  ! VR
\:        P<                  ! V.4      /4      pVf   \>        P@                  ! V4      # V Uu. uF  qµPC                  VR,          4      NK  	  pp\>        P@                  ! \6        P8                  ! VRVRV/4      4      # u up	i u upi )Nr{   ÚareaÚdisabledr   c              3   óR   "  € T F  pR P                  V^,           4      x € K  	  R# 5i)z7Picture {}: <|vision_start|><|image_pad|><|vision_end|>N)r3   )rŠ   r[   s   & r)   rŒ   Ú2TextEncodeMOSSImageEdit.execute.<locals>.<genexpr>„   s)   é € Ð}Ñn|ÐijÐV×]Ñ]Ð^_ÐbcÕ^c×dÐdÓn|ùs   ‚%')r±   Údata)Ú
patch_sizer|   Úcontext_attention_biasÚreference_latentsÚreference_latents_methodi @ r˜   )r   é   )r   r/   r”   )"r»   Úsortedr   rS   Úsqrtr�   rW   r�   rž   rŸ   ÚmovedimrU   ÚjoinÚrangeÚlenÚtokenizeÚencode_from_tokens_scheduledÚlogrš   Úiterr©   rP   ÚdictÚtext_encodersÚqwen_vlÚprocess_qwen2vl_imagesrN   r¢   Úconditioning_set_valuesr›   Útensorr   r2   r™   )r(   r®   r
   r¯   r±   ru   r·   ÚmethodÚvisionÚnameÚvlr²   ÚscaleÚtokensÚconditioningÚweightÚbiasÚtÚ_ÚgridÚrefss   &&&&&&&              r)   rd   ÚTextEncodeMOSSImageEdit.executez   sÏ  € ä% kÕ2‰ˆÜ+1°&¬>ÓV©> 4ÀD½\”,�&—,�,©>ˆÐVØˆß�c“k ~¸Õ'9ã�Ü˜C¤§¢¨9¸¿¹ÀA½ÈÏÉÐUVÍÕ8WÕ+XÓ!YÓZ�Ø—	‘	œ%Ÿ+™+×4Ñ4°U·]±]À2ÀqÓ5IÌ5ÐQV×Q\ÑQ\Ð]^ÕQ_ÐbgÕQgÓKhÔjoÐpu×p{Ñp{Ð|}Õp~ð  BGõ  qGó  kHð  JPð  R\ó  ]÷  eñ  eð  fgð  ikó  lö  mñ  ð —W‘WÑ}ÔnsÔtwÐxzÓt{Ôn|Ó}Ó}ð  AGõ  GˆFØ—‘˜v�Ó1ˆØ×8Ñ8¸Ó@ˆÜˆr‹7�Q�;˜>¨SÕ0ä—X’X˜nÓ-ˆFØˆDÜœ$˜vŸ}™}›Ó/Ó0°×3Ð3�Ü˜a �d¤D×)Ò)Ü#×1Ñ1×9Ñ9×PÑPÐQRÐSTÕQUÐV\ÕQ]ÐjlÐPÓm‘G�A�tØ˜V˜H¬¨D°­J¸¸d½Õ,CÓ(DÈÕ(IÕJÕJ’Dà—K‘K Ö$ñ 4ô (×?Ò?ÀÐOgÔin×iuÒiuÐw{Ðv|Ói}ÐN~ÓˆLØŠ;Ü—=’= Ó.Ð.Ù<BÓC¹F°5—
‘
˜5 Õ-Ö.¹FˆÐCÜ�}Š}œ\×AÒAÀ,ÐQdÐfjð  mGð  IOð  QPó  Qó  Rð  	Rùò1 Wùò. Ds   �L4®L4Ë# L9rf   )Nr{   rg   ro   s   @r)   r¬   r¬   f   s3   ø‡ € Øñ
ó ð
ð$ ÷Rñ Ró öRr,   r¬   c                   ó<   a € ] tR t^˜t o ]V 3R lR l4       tRtV tR# )ÚMOSSImageExtensionc                óT   <€ V ^8„  d   QhRS[ S[S[P                  ,          ,          /# r.   )rQ   r8   r   Ú	ComfyNode)r3   r4   s   "€r)   r5   ÚMOSSImageExtension.__annotate__š   s"   ø€ ÷ 
ñ 
¡T©$©r¯|©|Õ*<Õ%=ñ 
r,   c              ƒ  ó,   "  € \         \        \        .# 5irˆ   )r   rq   r¬   )Úselfs   &r)   Úget_node_listÚ MOSSImageExtension.get_node_list™   s   é € ô "ÜÜ#ð
ð 	
ùs   ‚rf   N)rh   ri   rj   rk   r   rñ   rm   rn   ro   s   @r)   rë   rë   ˜   s   ø‡ € Ø÷
ó ö
r,   rë   c                ó$   € V ^8„  d   QhR\         /# r.   ©rë   )r3   s   "r)   r5   r5   ¢   s   € ÷  ñ  Ô 2ñ  r,   c               ƒ   ó   "  € \        4       # 5irˆ   rô   rf   r,   r)   Úcomfy_entrypointrö   ¢   s   é € ÜÓÐùs   ‚)Úindex_timestep_zero_isolatedT)Úindex_timestep_zeroT)Úindex_timestep_zero_text_startF)rY   rS   rL   r›   Útyping_extensionsr   Úcomfy.text_encoders.qwen_vlr�   Úcomfy.utilsr¢   Úcomfy_api.latestr   r   rí   r   rq   r»   r¬   rë   rö   rf   r,   r)   Ú<module>rþ      s…   ðÛ Û Û 	ã Ý &ã "Û Û ß /ô&\˜BŸL™Lô &\ôR$E�r—|‘|ô $EðR Ð8ØÐ!>ØÐ@ð€ô/R˜bŸl™lô /Rôd
˜ô 
÷ r,   