§
     ’Þj˜6  ã                   óx   — d dl Zd dlZd dlmZ d dlmZmZ dZdZ	dZ
dZdZd	Zd
ZdZdZdZdZ G d„ d¦  «        ZdS )é    N)Úbuild_hf_url)Úquery_vae_filesÚvae_configszDeepBeepMeep/krea-2zDeepBeepMeep/Fibo2zQwen3-VL-4B-Instructz%Qwen3-VL-4B-Instruct_bf16.safetensorsz-Qwen3-VL-4B-Instruct_int8_convrot.safetensorsÚ	krea2_rawÚkrea2_turboÚkrea2_raw_editÚkrea2_turbo_editÚkrea2Úkrea2_presetsc                   ób  — e Zd Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Z	edd„¦   «         Z
edddd	dej        ej        d	d	dddfd
„¦   «         Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Zd„ ZdS )Úfamily_handlerc                 ó¶  — | t           t          fv }g d¢}i | t          t          fv rddini ¥i dd“ddg“dd“d	t          ¦   «         “d
d“d| t          t           fv rdnd“dd“dddddœ“dddddœ“dddddœ“dd“dd“dd“dd“d g d!¢d"d#d$d%d&œ“d'|d(d)d(gd*œ“d+d“¥t
          gt          gt          t          t          t          t          ¦  «        t          t          t          t          ¦  «        gd%dd,d-dgd.dgid/gd0œ¥}|s|                     d1d2d3d4d5œ¦  «         |r>|                     d6d7gd8œd9d:igd;d<d=d>dd?g d@¢dAdAdBœd%d%dCdd(gd-dDg|z   dd)d(gd*œdEœ¦  «         |S )FN))z)LanPaint (2 steps): ~2x slower, easy taské   )z+LanPaint (5 steps): ~5x slower, medium taské   )z+LanPaint (10 steps): ~10x slower, hard taské   )z0LanPaint (15 steps): ~15x slower, very hard taské   ÚacceleratedÚnativeÚdevice_explicitTÚcuda_graphsÚtransformerÚimage_outputsÚsystem_configsÚtiny_vae_architectureÚt2vÚguidance_max_phasesé   r   ÚNAGÚ	NAG_scaleç      ð?g      ø?g{®Gáz„?)ÚminÚmaxÚstepÚNAG_taug      @gš™™™™™©?Ú	NAG_alphag        Úinference_stepsÚinpaint_supportÚinpaint_video_prompt_typeÚVAÚinpaint_colorÚFFFFFFÚguide_custom_choices_image))zNo Control ImageÚ )úControl ImageÚV)z#Control Image with Masked DenoisingÚVGr/   r-   r.   F)ÚchoicesÚletters_filterÚdefaultÚlabelÚvisibleÚmodel_modesr   zInpainting Method)r1   r3   r4   Úimage_modesÚfit_into_canvas_image_refsÚ	2048x2048é   zqwen_vae_pid(1.5)zqwen_pid(1.5))Úpreset_profiles_dirÚprofiles_dirÚtext_encoder_folderÚtext_encoder_URLsÚno_negative_promptÚno_background_removalÚresolution_budgetÚvae_block_sizeÚvae_upsamplerÚvae_upsamplersÚexcluded_spatial_upsamplerszœText-to-image from `prompt`. Inpainting combines a Control Image, mask and prompt through the selected LanPaint method; the retained image supplies context.zÿDescribe the finished image in natural language: subject/action, framing, setting, lighting and style. Add detail for precise composition and quote exact lettering. For inpainting, describe the desired content in the masked area within the finished scene.a'  Generate an image from the Text Prompt (`prompt`). In Inpainting mode, a Control Image and mask provide the surrounding context while the prompt describes the replacement content; WanGP uses the selected LanPaint method. The text, retained context and masked region jointly determine the result.a•  Describe the image you want in natural language, including subject, pose or action, framing, environment, lighting and style. Start with a short concrete idea; add detail when precise composition matters. Put literal lettering in quotes. For inpainting, describe the finished scene and the desired content inside the mask, for example: "A man in a green jacket sits at the cafe table, warm evening light.")Údeepy_infosÚdeepy_prompt_infosÚinfosÚprompt_infoszidentity-preserving editszidentity preservation)ÚnameÚaliasesrJ   zsubject placementa  Edit images with the built-in Identity Edit LoRA by combining the Text Prompt (`prompt`) with Reference Images (`image_refs`). One reference supplies the image to edit; with two, use the scene first and the person or object second, and identify their roles in the prompt. Reference mode `KI` keeps the first image as the main scene; `I` treats references as people or objects. Text-only generation is also available.

Inpainting combines a Control Image and mask with the prompt; choose Masked Denoising or a LanPaint method. A Control Image is placed before other references, so it becomes image 1 in the prompt. Outpainting extends the source canvas using the selected margins. Enable background removal only for references whose surrounding scene should be discarded.aÖ  Use a short, direct editing instruction and name what must remain unchanged. For example: "Change the car to matte black; keep its shape, camera angle, lighting and surroundings." For two-image composition: "Place the person from image 2 at the table in image 1; preserve their face and clothing, and match the scene lighting." Image numbers follow input order, including a Control Image placed first.

State identity, pose, clothing or background constraints explicitly when they matter. For inpainting, identify the replacement inside the mask; for outpainting, describe the scene continuing into the new area. Quote exact visible text. For text-only generation, describe the finished image instead of referring to a source.a`  Identity Edit combines `prompt` and ordered `image_refs`: one source, or scene first + person/object second. `KI` keeps the first image as the main scene; `I` uses people/objects. A Control Image is prepended as image 1. Inpainting uses source + mask with Masked Denoising or LanPaint; outpainting extends the canvas. Text-only generation is supported.ah  Give a direct edit instruction and preservation constraints: 'Place the person from image 2 at the table in image 1; keep their face/clothing and match scene lighting.' Number inputs in order, including any Control Image first. Describe masked replacements or continuation into outpainted margins; quote exact lettering. Text-only: describe the finished image.ÚVAG))ÚNoner-   )z[Conditional Image is first Main Subject / Landscape and may be followed by People / ObjectsÚKI)z'Conditional Images are People / ObjectsÚIrN   )r1   r2   r3   zORemove Backgrounds only behind People / Objects except main Subject / Landscape)z9Masked Denoising: inpainted area may reuse masked contentr   )ÚspecialitiesrH   rI   rF   rG   r'   r(   Úimage_ref_choicesÚat_least_one_image_ref_neededr@   Úbackground_removal_labelÚvideo_guide_outpaintingÚoutpainting_quantize_marginsr6   )Ú_RAW_EDIT_MODEL_TYPEÚ_TURBO_EDIT_MODEL_TYPEÚ_TURBO_MODEL_TYPEr   Ú_RAW_MODEL_TYPEÚ_PRESET_PROFILE_DIRÚ_PROFILE_DIRÚ_TEXT_ENCODER_FOLDERr   Ú_ENCODER_REPOÚ_TEXT_ENCODER_BF16_FILENAMEÚ_TEXT_ENCODER_INT8_FILENAMEÚupdate)Úbase_model_typeÚ	model_defÚeditÚlanpaint_choicesÚresults        úBC:\Users\johnn\OneDrive\Documents\AI\models\krea2\krea2_handler.pyÚquery_model_defzfamily_handler.query_model_def   s	  € àÕ#7Õ9OÐ"PÐPˆð
ð 
ð 
Ðð-
Ø,;Õ@QÕSiÐ?jÐ,jÐ,j�˜xÐ(Ð(Ðprð-
ð -
à˜tð-
ð ˜M˜?ð-
ð ˜Tð	-
ð
 �k™mœmð-
ð $ Uð-
ð "¨½OÕMaÐ;bÐ(bÐ(b 1 1Ðhið-
ð �4ð-
ð  ¨S¸$Ð?Ð?ð-
ð ˜s¨3¸Ð=Ð=ð-
ð  ¨S¸$Ð?Ð?ð-
ð ˜tð-
ð ˜tð-
ð (¨ð-
ð ˜Xð-
ð  )Ø|Ð|Ð|Ø"%ØØ(Ø ð+ð +ð!-
ð. à+ØØ,Ø !˜sðð ð/-
ð< )¨!ð=-
ð -
õ> %8Ð#8Ý)˜NÝ#7å�]Õ,@ÕB]Ñ^Ô^Ý�]Õ,@ÕB]Ñ^Ô^ð"ð #(Ø%)Ø!,Ø Ø˜SØ2°Q°CÐ8Ø,;Ð+<ðY-
ð -
ð -
ˆð\ ð 	Ø�MŠMð  ~ð 'hð Cð !xð	ð ñ ô ð ð ð 	Ø�MŠMØ*EÐSjÐRkÐ!lÐ!lÐouð  xKð  oLð  !Mð `ð !{ð  Bð 'QØ#'Ø-2ð ð  ð  ð
 '+Ø#ð&ð &ð 27Ø).Ø,}Ø,-¨q¨6Ø02à `ÐaÐdtÑtØ Ø0Ø$% 3ð	 ð  ð-ð ñ ô ð ð: ˆó    c                  ó6   — t           t          t          t          gS ©N©rY   rX   rV   rW   © rh   rf   Úquery_supported_typesz$family_handler.query_supported_typesu   s   € åÕ!2Õ4HÕJ`ÐaÐarh   c                  óX   ‡ — t           t          t          t          gŠ i ˆ fd„‰ D ¦   «         fS )Nc                 ó   •— i | ]}|‰“ŒS rl   rl   )Ú.0Ú
model_typeÚ
compatibles     €rf   ú
<dictcomp>z4family_handler.query_family_maps.<locals>.<dictcomp>|   s   ø€ ÐHÐHÐH¨z�J 
ÐHÐHÐHrh   rk   )rr   s   @rf   Úquery_family_mapsz family_handler.query_family_mapsy   s4   ø€ å%Õ'8Õ:NÕPfÐgˆ
ØÐHÐHÐHÐH¸ZÐHÑHÔHÐHÐHrh   c                  ó   — dS ©Nr
   rl   rl   rh   rf   Úquery_model_familyz!family_handler.query_model_family~   ó   € àˆwrh   c                  ó
   — ddiS )Nr
   )i~  zKrea 2rl   rl   rh   rf   Úquery_family_infosz!family_handler.query_family_infos‚   s   € àÐ)Ð*Ð*rh   c                 ó   — dS rv   rl   )ra   s    rf   Úget_lora_dirzfamily_handler.get_lora_dir†   rx   rh   Nc                 óL   — t           t          gg d¢gdœgt          |¦  «        z   S )N)zconfig.jsonztokenizer.jsonztokenizer_config.jsonzchat_template.jinjazpreprocessor_config.json)ÚrepoIdÚsourceFolderListÚfileList)Ú_PROJECT_REPOr\   r   )ÚcomputeListra   rb   s      rf   Úquery_model_filesz family_handler.query_model_filesŠ   sJ   € õ (Ý%9Ð$:ð Bð  Bð  Bððð ð
õ ˜IÑ&Ô&ñ'ð 	'rh   Fc                 ó¼   — ddl m}  |d| ||||||||	¬¦
  «
        }|j        |j        j        |j        dœ}t          |j        d¦  «        r|j        j        |d<   ||fS )Nr   )Úmodel_factoryÚckpts)
Úcheckpoint_dirÚmodel_filenamerq   rb   ra   Útext_encoder_filenameÚdtypeÚ	VAE_dtypeÚVAE_upsamplingÚsave_quantized)r   Útext_encoderÚvaeÚvisualÚvision_encoder)Ú
krea2_mainr…   r   rŽ   Úlanguage_modelr�   Úhasattrr�   )rˆ   rq   ra   rb   ÚquantizeTransformerÚtext_encoder_quantizationrŠ   r‹   Úmixed_precision_transformerr�   Úsubmodel_no_listr‰   rŒ   Úkwargsr…   Úpipe_processorÚpipes                    rf   Ú
load_modelzfamily_handler.load_model–   s¡   € ð" 	.Ð-Ð-Ð-Ð-Ð-à&˜Ø"Ø)Ø!ØØ+Ø"7ØØØ)Ø)ð
ñ 
ô 
ˆð *Ô5Ø*Ô7ÔFØ!Ô%ð
ð 
ˆõ
 �>Ô.°Ñ9Ô9ð 	HØ%3Ô%@Ô%GˆDÐ!Ñ"Ø˜tÐ#Ð#rh   c                 óV  — | t           t          fv }|                     dd|rdnddddœ¦  «         | t          t          fv r|                     ddddœ¦  «         n3|                     | t           k    rd	nd
| t           k    rdndddœ¦  «         |r|                     dddœ¦  «         d S d S )Nr   r   r   r    )Ú
image_modeÚ
batch_sizeÚ
model_modeÚdenoising_strengthÚmasking_strengthé   Ú	1024x1024)Únum_inference_stepsÚguidance_scaleÚ
resolutioné   é4   g      @rN   )Úvideo_prompt_typeÚremove_background_images_ref)rV   rW   r`   rX   )ra   rb   Úui_defaultsrc   s       rf   Úupdate_default_settingsz&family_handler.update_default_settings¾   s2  € àÕ#7Õ9OÐ"PÐPˆØ×Ò¨!¸1ÐQUÐL\ÈAÈAÐ[\Ðtwð  NQð  Rð  Rñ  	Sô  	Sð  	SØÕ0Õ2HÐIÐIÐIØ×Ò°qÈAÐ]hÐiÐiÑjÔjÐjÐjà×Ò¸_ÕPdÒ=dÐ=d°r°rÐjlð  FUõ  Ymò  Fmð  Fmð  ABð  ABð  svð  FQð   Rð   Rñ  Sô  Sð  SØð 	_Ø×Ò°TÐ[\Ð]Ð]Ñ^Ô^Ð^Ð^Ð^ð	_ð 	_rh   c                 ó”   — |                      dd¦  «         |dk     r
d|d<   d|d<   |dk     r|d         dk    r|d         |d	<   d S d S d S )
Nrž   r   gHáz®G@r    r¡   r¢   r   r(   rª   )Ú
setdefault)ra   Úsettings_versionrb   r¬   s       rf   Úfix_settingszfamily_handler.fix_settingsÉ   sx   € à×Ò˜|¨QÑ/Ô/Ð/Ø˜dÒ"Ð"Ø03ˆKÐ,Ñ-Ø.1ˆKÐ*Ñ+Ø˜dÒ"Ð" {°<Ô'@ÀAÒ'EÐ'EØ/8Ð9TÔ/UˆKÐ+Ñ,Ð,Ð,ð #Ð"Ð'EÐ'Erh   c                 ó¨   — |                       d¦  «        }d }|�*	 t          |¦  «        }n# t          t          f$ r d }Y nw xY w|dv r
d| d<   d| d<   |S )Nr    )r   r   r   r   r    r¡   r¢   )ÚgetÚintÚ	TypeErrorÚ
ValueError)Úinputsr    Úmodel_mode_ints      rf   Únormalize_lanpaint_strengthsz+family_handler.normalize_lanpaint_strengthsÒ   s€   € à—Z’Z Ñ-Ô-ˆ
ØˆØÐ!ð&Ý!$ Z¡¤��øÝ�zÐ*ð &ð &ð &Ø!%���ð&øøøà˜\Ð)Ð)Ø+.ˆFÐ'Ñ(Ø),ˆFÐ%Ñ&ØÐs   ›+ «AÁ Ac                 ó:   — t                                |¦  «         d S rj   )r   r¹   )ra   rb   r·   Úprompts       rf   Úvalidate_generative_promptz)family_handler.validate_generative_promptà   s   € å×3Ò3°FÑ;Ô;Ð;Ð;Ð;rh   c                 óX  — | t           t          fv rG|                     d¦  «        dk    rdnd}t          |                     d¦  «        pg ¦  «        |k    rdS t                               |¦  «        }|                     dd¦  «        dk     r|dk    rt          j        d¦  «         d S d S d S )	Nrž   r   r   Ú
image_refsz2Krea 2 Edit supports at most two Reference Images.r¡   r   zBDenoising Strength will be ignored if Masked Denoising is not used)rV   rW   r³   Úlenr   r¹   ÚgrÚInfo)ra   rb   r·   Úmax_refsr¸   s        rf   Úvalidate_generative_settingsz+family_handler.validate_generative_settingsä   s¹   € àÕ3Õ5KÐLÐLÐLØ"ŸJšJ |Ñ4Ô4¸Ò9Ð9�q�q¸qˆHÝ�6—:’:˜lÑ+Ô+Ð1¨rÑ2Ô2°XÒ=Ð=ØKÐKÝ'×DÒDÀVÑLÔLˆØ�:Š:Ð*¨AÑ.Ô.°Ò2Ð2°~ÈÒ7JÐ7JÝŒGÐXÑYÔYÐYÐYÐYð 3Ð2Ð7JÐ7Jrh   c                 ó$   — ddl m}  |d¦  «        S )Nr   )Úget_rgb_factorsÚqwen)Úshared.RGB_factorsrÅ   )ra   rÅ   s     rf   rÅ   zfamily_handler.get_rgb_factorsî   s$   € Ø6Ð6Ð6Ð6Ð6Ð6àˆ˜vÑ&Ô&Ð&rh   rj   )Ú__name__Ú
__module__Ú__qualname__Ústaticmethodrg   rm   rt   rw   rz   r|   rƒ   ÚtorchÚbfloat16Úfloat32rœ   r­   r±   r¹   r¼   rÃ   rÅ   rl   rh   rf   r   r      sÈ  € € € € € Øð[ð [ñ „\ð[ðz ðbð bñ „\ðbð ðIð Iñ „\ðIð ðð ñ „\ðð ð+ð +ñ „\ð+ð ðð ñ „\ðð ð	'ð 	'ð 	'ñ „\ð	'ð ð ØØØ!Ø"&ØŒnØ”-Ø$)ØØØ"Øð%$ð %$ð %$ñ „\ð%$ðN ð_ð _ñ „\ð_ð ðVð Vñ „\ðVð ðð ñ „\ðð ð<ð <ñ „\ð<ð ðZð Zñ „\ðZð'ð 'ð 'ð 'ð 'rh   r   )ÚgradiorÀ   rÌ   Úshared.utils.hfr   Úmodels.qwen.vae_variantsr   r   r�   r]   r\   r^   r_   rY   rX   rV   rW   r[   rZ   r   rl   rh   rf   ú<module>rÒ      sÂ   ðð Ð Ð Ð Ø €€€à (Ð (Ð (Ð (Ð (Ð (Ø AÐ AÐ AÐ AÐ AÐ AÐ AÐ Að &€Ø$€Ø-Ð ØEÐ ØMÐ Ø€Ø!Ð Ø'Ð Ø+Ð Ø€Ø%Ð ð['ð ['ð ['ð ['ð ['ñ ['ô ['ð ['ð ['ð ['rh   