§
    ’Þj$  ã                   óX   — d dl Z d dlmZ ddlmZmZmZmZ dZdZ	dZ
 G d„ d	¦  «        ZdS )
é    N)Úbuild_hf_urlé   )ÚCLASSICÚEDITÚ
STRUCTUREDÚSTRUCTURED_EDITzDeepBeepMeep/Flux3zDeepBeepMeep/Fibo2zQwen3-VL-4B-Instructc                   óV  — e Zd Zed„ ¦   «         Zed„ ¦   «         Ze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ej        fd„¦   «         Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Zd
S )Úfamily_handlerc                  ó
   — ddgS )NÚflux3_kleinÚflux3_klein_base© r   ó    úBC:\Users\johnn\OneDrive\Documents\AI\models\flux3\flux3_handler.pyÚquery_supported_typesz$family_handler.query_supported_types   s   € àÐ1Ð2Ð2r   c                  ó   — dS )NÚflux3r   r   r   r   Úquery_model_familyz!family_handler.query_model_family   s   € àˆwr   c                  ó
   — ddiS )Nr   )iN  zFlux 3r   r   r   r   Úquery_family_infosz!family_handler.query_family_infos   s   € àÐ)Ð*Ð*r   c                  ó   — i dgdgdœfS )Nr   r   )r   r   r   r   r   r   Úquery_family_mapsz family_handler.query_family_maps   s   € à M ?ÐI[ÐH\Ð]Ð]Ð]Ð]r   c                 ó   — | S ©Nr   )Úbase_model_types    r   Úget_lora_dirzfamily_handler.get_lora_dir   s   € àÐr   c                 ó.   — ddl m}  || |||||¦  «        S )Nr   )Úrender_prompt_helper)Úprompt_helperr   )Ú
model_typeÚ	model_defÚ	prompt_idÚpopup_idÚprompt_elem_idÚresolution_elem_idr   s          r   r   z#family_handler.render_prompt_helper    s1   € à7Ð7Ð7Ð7Ð7Ð7Ø#Ð# J°	¸9ÀhÐP^Ð`rÑsÔsÐsr   c                  ó"   — ddl m}   | ¦   «         S )Nr   ©Úget_prompt_helper_css)r   r(   r'   s    r   r(   z$family_handler.get_prompt_helper_css%   s#   € à8Ð8Ð8Ð8Ð8Ð8Ø$Ð$Ñ&Ô&Ð&r   c                  ó"   — ddl m}   | ¦   «         S )Nr   ©Úget_prompt_helper_javascript)r   r+   r*   s    r   r+   z+family_handler.get_prompt_helper_javascript*   s#   € à?Ð?Ð?Ð?Ð?Ð?Ø+Ð+Ñ-Ô-Ð-r   c                 óB  — | dk    }|rdnd}i dd“dd“ddg“d	d“d
d“dd“d| g“dd“d|rdnd“dd“d|“dd“dd“dd“dd“dd“dd“t           d„ d D ¦   «         g d!¢d"d#d$œdd%œ¥|rd&d'ini ¥d(|› d)�d*d+|› d,�d-g d.¢d/d0d1d2d.œd#d3œt          t          t          t          ddd4œ¥S )5Nr   z16 steps, no CFGz50 steps, guidance_scale=3.5Úimage_outputsTÚdevice_explicitÚcuda_graphsÚtransformerÚskip_prompt_templateÚpreserve_empty_prompt_linesÚgroupr   Úprofiles_dirÚinference_stepsÚguidance_max_phasesr   r   Úembedded_guidanceFÚno_negative_promptÚno_background_removalÚvae_block_sizeé   Úresolution_budgetÚ	4096x4096Ú	max_widthé   Ú
max_heightÚtiny_vae_architectureÚflux2_klein_4bc           	      óL   — g | ]!}t          t          t          d |› d�¦  «        ‘Œ"S )zQwen3-VL-4B-Instruct_z.safetensors)r   ÚENCODER_REPOÚTEXT_FOLDER)Ú.0Úfmts     r   ú
<listcomp>z2family_handler.query_model_def.<locals>.<listcomp><   sD   € ð  "Zð  "Zð  "ZÐy|¥,­|½[ÐJsÐbeÐJsÐJsÐJsÑ"tÔ"tð  "Zð  "Zð  "Zr   )Úbf16Úint8_convrot))ÚNoneÚ )zIMain Image Ref - First Reference Sets Output Dimensions (up to 10 Images)ÚKI)z#Ordered Reference Images (up to 10)ÚIrM   rL   )ÚchoicesÚletters_filterÚdefault)Útext_encoder_folderÚtext_encoder_URLsÚimage_ref_choicesÚfit_into_canvas_image_refsÚacceleratedÚnativeae  Generate from a Text Prompt, or combine the prompt with up to 10 ordered Reference Images for edits and compositions. Main Image Ref uses the first reference to set output dimensions through the selected resolution and canvas fitting mode; later images remain additional references. Ordered Reference Images keeps the selected output dimensions. Start with uÿ  . References anchor content but do not lock composition. For a new composition, describe the complete desired image. For a bounded edit, identify the exact change and what must remain untouched. Bounding boxes in the prompt guide placement; they are not pixel masks, and edits may affect surrounding content. Prompt enhancement is optional and off by default. The upstream model supports sides from 64 to 4096 pixels, aligned to 16 pixels; start at 1024Ã—1024. Large images and many references need more memory.u  Use Prompt Helper to draw, move and resize layout boxes. For reference edits, select a Content Source and use the Source view to mark its region, then place its Output Box; removing a reference element sets a null target. The editor saves the caption and element list together, preserving comments and extra fields. For generation, write a complete scene caption: framing, subject, background, lighting and style. For a bounded edit, specify the change and retained details, e.g. "Add a wicker basket to the bicycle handlebars, matching the side-view perspective and afternoon light. Keep the bicycle, white brick wall and framing unchanged." Quote exact visible lettering. Identify references as `<ref_image_0>`, `<ref_image_1>`, etc. For layout, tag elements with `<id>` in the caption and append a JSON array: `[{"id":"title","bbox":[80,100,220,900],"desc":"Navy title reading \"NIGHT GARDEN\""}]`. Coordinates are `[top,left,bottom,right]` on a 0â€“1000 grid, with the origin at top left. Reference edits use `from`, `src_bbox` and `tgt_bbox` instead of `bbox`; a null target removes an element. Review enhancer-generated coordinates: some LLMs may swap the vertical and horizontal axes. Keep caption and JSON together in one prompt. Text accuracy, exact placement and preservation are not guaranteed.aƒ  Text-to-image or editing: `prompt` plus optional ordered `image_refs` (maximum 10). Use `video_prompt_type="KI"` for a main image reference: `image_refs[0]` sets output dimensions through `resolution` and `fit_canvas`; later images remain additional references. Use `video_prompt_type="I"` to keep the requested `resolution` with references, or empty for text-only generation. Defaults: uÇ   . `resolution` dimensions must be multiples of 16, each 64â€“4096. Bounding boxes are prompt guidance, not hard masks. No native inpainting mask workflow is declared. `prompt_enhancer=""` by default.u¨  For generation or a new composition, describe the finished scene. For a bounded edit, specify the changed object, concrete end state and retained details; avoid recaptioning the unchanged scene. Reference IDs are zero-based `<ref_image_0>`, etc. Quote exact visible strings. Optional layout: caption with `<id>` tags followed by JSON elements {id,desc,bbox:[top,left,bottom,right]}, integer 0â€“1000 corners. Editing elements use {id,desc,from,src_bbox,tgt_bbox}; from is ref_image_0, ref_image_1, etc. or target; null tgt_bbox removes. Use multi_prompts_gen_type="FG" for a multiline caption and JSON. Review enhancer boxes for Y/X swaps; boxes guide placement, not exact pixels.)ÚTÚTIÚT1ÚTI1zA Complete Scene Captionz*A Detailed Image Edit using {image_inputs}z#A Scene Caption with Bounding Boxesz5A Scene Edit with Bounding Boxes using {image_inputs})Ú	selectionÚlabelsrQ   )ÚinfosÚprompt_infosÚdeepy_infosÚdeepy_prompt_infosÚprompt_enhancer_defÚ!text_prompt_enhancer_instructionsÚ"image_prompt_enhancer_instructionsÚ"text_prompt_enhancer_instructions1Ú#image_prompt_enhancer_instructions1Ú text_prompt_enhancer_max_tokens1Ú!image_prompt_enhancer_max_tokens1)rE   r   r   r   r   )r   r!   Ú	distilledÚsettingss       r   Úquery_model_defzfamily_handler.query_model_def/   s*  € à# }Ò4ˆ	Ø)2ÐVÐ%Ð%Ð8Vˆð
Ø˜Tð
Ø#4°dð
Ø<IÈMÈ?ð
à" Dð
à*GÈð
ð �Wð
ð -¨Ð.?ð
ð BSÐTXð
ð "¨	Ð#8 1 1°qð	
ð ;NÈuð	
ð
 ! )ð
ð
 .EÀdð
ð ˜bð
ð #6°{ð
ð EPÐQUð
ð XdÐeið
ð $Ð%5ð
õ $/ð "Zð  "Zð  AYð  "Zñ  "Zô  "ZðJð Jð Jð #'°2ð	"ð "ð +,ð!
ð 
ð 
ð" -6Ð=�˜xÐ(Ð(¸2ð#
ð$ Gð  ~Fð  Gð  Gð  Gð zð s	ð  bjð  s	ð  s	ð  s	ð #MØ1IÐ1IÐ1IÐ[uð  ~jð  rWð  `Wð  VXð  VXð  egð  $hð  $hÝ18Õ`dÝ2<ÕetØ04Ð[_ð3
ð 
ð 
ð 	
r   Nc                 ó2   — t           t          dgg d¢dggdœgS )Nr   )zconfig.jsonztokenizer.jsonztokenizer_config.jsonzchat_template.jinjazflux2-vae.safetensors)ÚrepoIdÚsourceFolderListÚfileList)ÚREPOrE   )ÚcomputeListr   r!   s      r   Úquery_model_filesz family_handler.query_model_filesO   sA   € åµkÀ7Ð5KØoÐoÐoð  sJð  rKð  LðMð Mð Nð 	Nr   Fc           	      ó^   — ddl m}  || ||||||¦  «        }	|	|	j        |	j        |	j        dœfS )Nr   )Úload_pipeline)r0   Útext_encoderÚvae)Úpipelinert   r0   ru   rv   )
Úmodel_filenamer    r   r!   Útext_encoder_filenameÚsave_quantizedÚdtypeÚkwargsrt   rw   s
             r   Ú
load_modelzfamily_handler.load_modelT   s]   € à+Ð+Ð+Ð+Ð+Ð+Ø �= Ð1FÈÐYbÐdnÐp~ð  AFñ  Gô  GˆØ¨Ô)=ÈxÔOdÐmuÔmyÐzÐzÐzÐzr   c                 ó`   — | dk    }|                      ddd|rdnd|rdnddddd	d
œ	¦  «         d S )Nr   r   Ú	1024x1024r;   é2   g      @rL   r   ÚFG)	Ú
image_modeÚ
resolutionÚ
batch_sizeÚnum_inference_stepsÚguidance_scaleÚprompt_enhancerÚvideo_prompt_typeÚremove_background_images_refÚmulti_prompts_gen_type)Úupdate)r   r!   Úui_defaultsri   s       r   Úupdate_default_settingsz&family_handler.update_default_settingsZ   sr   € à# }Ò4ˆ	Ø×Ò¨!¸;ÐVWÐvð  qHÐprÐprð  FHØ3<Ð.E¨a¨aÀ#ÐZ\Ðsuð  XYØ6:ð<ð <ñ 	=ô 	=ð 	=ð 	=ð 	=r   c                 óö   — t          |                     d¦  «        pg ¦  «        dk    rdS t          t          |d                              d¦  «        ¦  «        \  }}t          d„ ||fD ¦   «         ¦  «        rdS d S )NÚ
image_refsé
   z2Flux 3 Klein supports at most 10 Reference Images.rƒ   Úxc              3   ó8   K  — | ]}|d k     p
|dk    p|dz  V — ŒdS )é@   r?   r;   Nr   )rF   Úsides     r   ú	<genexpr>z>family_handler.validate_generative_settings.<locals>.<genexpr>f   s8   è è € ÐQÐQ¸ˆt�bŠyÐ4˜D 4šKÐ4¨4°"©9ÐQÐQÐQÐQÐQÐQr   zFFlux 3 dimensions must be multiples of 16, between 64 and 4096 pixels.)ÚlenÚgetÚmapÚintÚsplitÚany)r   r!   ÚinputsÚwidthÚheights        r   Úvalidate_generative_settingsz+family_handler.validate_generative_settingsa   sˆ   € åˆv�zŠz˜,Ñ'Ô'Ð-¨2Ñ.Ô.°Ò3Ð3ØGÐGÝ�C ¨Ô!5×!;Ò!;¸CÑ!@Ô!@ÑAÔA‰ˆˆvÝÐQÐQÀ%ÈÀÐQÑQÔQÑQÔQð 	\Ø[Ð[ð	\ð 	\r   c                 ó(   — ddl m}  |dd¬¦  «        S )Nr   )Úget_rgb_factorsÚfluxÚflux2)Ú
sub_family)Úshared.RGB_factorsr¡   )r   r¡   s     r   r¡   zfamily_handler.get_rgb_factorsi   s)   € à6Ð6Ð6Ð6Ð6Ð6Øˆ˜v°'Ð:Ñ:Ô:Ð:r   r   )Ú__name__Ú
__module__Ú__qualname__Ústaticmethodr   r   r   r   r   r   r(   r+   rk   rr   ÚtorchÚbfloat16r}   r�   rŸ   r¡   r   r   r   r
   r
      s»  € € € € € Øð3ð 3ñ „\ð3ð ðð ñ „\ðð ð+ð +ñ „\ð+ð ð^ð ^ñ „\ð^ð ðð ñ „\ðð ðtð tñ „\ðtð ð'ð 'ñ „\ð'ð ð.ð .ñ „\ð.ð ð
ð 
ñ „\ð
ð> ðNð Nð Nñ „\ðNð ØaeÐv{ð  DIô  DRð {ð {ð {ñ „\ð{ð
 ð=ð =ñ „\ð=ð ð\ð \ñ „\ð\ð ð;ð ;ñ „\ð;ð ;ð ;r   r
   )rª   Úshared.utils.hfr   Úpromptsr   r   r   r   rp   rD   rE   r
   r   r   r   ú<module>r®      s�   ðà €€€Ø (Ð (Ð (Ð (Ð (Ð (Ø ?Ð ?Ð ?Ð ?Ð ?Ð ?Ð ?Ð ?Ð ?Ð ?Ð ?Ð ?à€Ø#€Ø$€ða;ð a;ð a;ð a;ð a;ñ a;ô a;ð a;ð a;ð a;r   