a
    Ad?&                    @   s\  d dl Z d dlZd dlZd dlZd dlmZ d dlZd dlZd dl	Zd dl
Zd dlmZmZ d dlmZmZmZ d dlmZ d dlmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z( d dl)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/ d dl0m1Z1 d d	l2m3Z3 d d
l4m5Z5 d dl6m7Z7m8Z8 d dl9m:Z; d dl<m=  m>Z? d dl@mA  m>ZB d dlCmA  mAZA d dl6mDZD d dlEZd dlmFZF d dlGmHZH d dl9mIZI e jJZJejKe7jLrdndeMd ejKe7jNrdndejOjPd eQ  eRdd eRdd e8jSs(e8jTs(dd ejU_Vdd ejU_We8jXdurld dlYmXZX eZd eX[e8jXe8j\durbe8j\nde8j] dNddZ^dZ_ej`ae_re_ndZ_dZbd Zcd!Zdd"Zed#Zfd$Zgd%Zhd&Zid'Zjd(Zkd)ZlejmZmd*d+ Znd,d- Zod.d/ Zpd0d1 Zqd2d3 Zrd4d5 Zsd6d7 Ztd8d9 ZuG d:d; d;Zvd<d= Zwd>d? Zxd@dA ZydBdC ZzdDdE Z{dFdG Z|dHdI Z}dJdK Z~dLdM ZdS )O    N)reduce)ImagePngImagePlugin)wrap_gradio_gpu_callwrap_queued_callwrap_gradio_call)gradio_extensons)	sd_hijack	sd_modelsscript_callbacksui_extensions	deepbooruextra_networks	ui_commonui_postprocessingprogressui_loadsaveshared_itemsui_settingstimersysinfoui_checkpoint_mergerui_prompt_stylesscriptssd_samplers
processingui_extra_networks)FormRow	FormGroup
ToolButtonFormHTMLInputAccordionResizeHandleRow)script_path)create_refresh_button)reload_javascript)optscmd_opts)prompt_parser)model_hijack)image_from_url_textdefaultignore)categoryzapplication/javascriptz.jsz
image/webpz.webpc                   C   s   d S N r/   r/   r/   2/var/www/html/stable-diffusion-webui/modules/ui.py<lambda>/       r1   c                   C   s   dS )Nz	127.0.0.1r/   r/   r/   r/   r0   r1   0   r2   z.ngrok authtoken detected, trying to connect...i  Tc                 C   s
   | ddS )Nupdate)visible__type__r/   r4   r/   r/   r0   gr_show<   s    r7   z8assets/stable-samples/img2img/sketch-mountains-input.jpgu   🎲️u   ♻️u   ↙️u   🔄u   💾u   📋u   🗑️u   🎴u   ⇅u   🌀u   📐c                 C   s   t | dkrd S t| d S Nr   )lenr*   xr/   r/   r0   send_gradio_gallery_to_imageU   s    r<   c              	   C   sX   | sdS t j||d|||d}|  d|j d|j d|jpB|j d|jpP|j d	S )N T)widthheight	enable_hrhr_scalehr_resize_xhr_resize_yzfrom <span class='resolution'>r;   $</span> to <span class='resolution'></span>)	r    StableDiffusionProcessingTxt2Imgcalculate_target_resolutionr>   r?   rB   hr_upscale_to_xrC   hr_upscale_to_y)enabler>   r?   rA   rB   rC   pr/   r/   r0   calc_resolution_hires[   s
    rL   c              	   C   sB   t | | }t || }|r |s$dS d|  d| d| d| d	S )Nzno image selectedz&resize: from <span class='resolution'>r;   rD   rE   )int)r>   r?   scale_bytarget_widthtarget_heightr/   r/   r0   resize_from_to_htmle   s
    rQ   c              	   G   s   |dv r| || d gS |dkr4| || d d gS |dkrt jjrLJ dt |}tdt| d |dkrtj|d	d
 n|}|D ]T}t	|}tj
|}tj
|\}	}
t| |t	tj
||	 ddddd qt d gS d S )N>   r               image   z:Launched with --hide-ui-dir-config, batch img2img disabledzWill process z images.r=   T)exist_ok.txtazutf-8)encoding)file)sharedr'   hide_ui_dir_config	listfilesprintr9   osmakedirsr   openpathbasenamesplitextjoingrr3   )Zinterrogation_functionmodeZii_input_dirZii_output_dirZ
ii_singlesimagesrV   imgfilenameleft_r/   r/   r0   process_interrogateo   s"    

,ro   c                 C   s&   t j| d}|d u r"t S |S )NRGB)r]   interrogatorinterrogateconvertrh   r3   rV   promptr/   r/   r0   rr      s    rr   c                 C   s    t j| }|d u rt S |S r.   )r   modeltagrh   r3   rt   r/   r/   r0   interrogate_deepbooru   s    rx   c                 C   s   | j ddg g d dS )z\Given clear button, prompt, and token_counter objects, setup clear prompt button click eventZclear_promptN)_jsfninputsoutputs)click)buttonr/   r/   r0   connect_clear_prompt   s    r   c           	      C   s   z0t | \} }t| g\}}}t||}W n tyN   || ggg}Y n0 tdd |}dd |D }tdd |D dd d\}}d| d	| d
S )Nc                 S   s   | | S r.   r/   )list1list2r/   r/   r0   r1      r2   z&update_token_counter.<locals>.<lambda>c                 S   s   g | ]\}}|qS r/   r/   ).0stepprompt_textr/   r/   r0   
<listcomp>   r2   z(update_token_counter.<locals>.<listcomp>c                 S   s   g | ]}t |qS r/   )r)   get_prompt_lengths)r   ru   r/   r/   r0   r      r2   c                 S   s   | d S r8   r/   argsr/   r/   r0   r1      r2   keyz#<span class='gr-box gr-text-input'>/rE   )r   parse_promptr(   get_multicond_prompt_list)get_learned_conditioning_prompt_schedules	Exceptionr   max)	textstepsrn   prompt_flat_listprompt_schedulesZflat_promptspromptstoken_count
max_lengthr/   r/   r0   update_token_counter   s    r   c                   @   s   e Zd ZdZdd ZdS )ToprowzCreates a top row UI with prompts, generate button, styles, extra little buttons for things, and enables some functionality related to their operationc                 C   sP  |rdnd}|| _ tj| ddd tj| dddj t  tjd	d
t t L tjd| dddddgd| _tjd| ddddd| _W d    n1 s0    Y  W d    n1 s0    Y  W d    n1 s0    Y  t  tjd	d
Z t 0 tjd| dddddgd| _W d    n1 sR0    Y  W d    n1 sr0    Y  W d    n1 s0    Y  W d    n1 s0    Y  d | _	d | _
|rtjddd0 tjddd| _	tjd d!d| _
W d    n1 s0    Y  tjd| d"d# tj| d$d%d& tjd'| d(d)d&| _tjd*| d+d,d&| _tjd-| d.d/d| _| jjd0d1 g g d2 | jjd3d1 g g d2 W d    n1 s0    Y  tj| d4d ttd5d6| _tt| d7d6| _tt| d8dd9| _tjd:| d;d<gd=| _tjd| d>d?| _tjd:| d@d<gd=| _tjd| dAd?| _| jjdBd1 dC| j| jg| j| jgdD W d    n1 s0    Y  t|| j| j| _W d    n1 s0    Y  W d    n1 s0    Y  | jjt j!j"| jg| j| jgddE d S )FNimg2imgtxt2imgZ_toprowcompactelem_idvariantZ_prompt_container   r   scaleP   r   PromptZ_promptFrS   z2Prompt (press Ctrl+Enter or Alt+Enter to generate)ru   labelr   
show_labellinesplaceholderelem_classesr=   Z_prompt_imagesinglebinary)r   r   
file_counttyper4   Negative promptZ_neg_promptz;Negative prompt (press Ctrl+Enter or Alt+Enter to generate)rR   zinterrogate-col)r   r   zInterrogate
CLIPrr   r   zInterrogate
DeepBoorur   Z_actions_column)r   r   Z_generate_boxzgenerate-boxr   r   	InterruptZ
_interruptzgenerate-box-interruptSkip_skipzgenerate-box-skipGenerate	_generateprimaryc                   S   s
   t j S r.   )r]   stateskipr/   r/   r/   r0   r1      r2   z!Toprow.__init__.<locals>.<lambda>rz   r{   r|   c                   S   s
   t j S r.   r]   r   	interruptr/   r/   r/   r0   r1      r2   _toolspastevaluer   Z_clear_promptZ_restore_progress)r   r   r4   z<span>0/75</span>Z_token_counterztoken-counter)r   r   r   Z_token_buttonr4   r   Z_negative_token_counterZ_negative_token_buttonc                  W   s   | S r.   r/   r:   r/   r/   r0   r1      r2   Zconfirm_clear_promptrz   ry   r{   r|   rz   r{   r|   show_progress)#id_partrh   RowColumnTextboxru   FileZ
prompt_imgnegative_promptbutton_interrogatebutton_deepbooruButtonr   r   submitr}   r   paste_symbolr   clear_prompt_symbolZclear_prompt_buttonrestore_progress_symbolrestore_progress_buttonHTMLtoken_countertoken_buttonnegative_token_counternegative_token_buttonr   ZUiPromptStyles	ui_styleschangemodulesrj   
image_data)self
is_img2imgr   r/   r/   r0   __init__   sn    

 v

0&

&T
zToprow.__init__N)__name__
__module____qualname____doc__r   r/   r/   r/   r0   r      s   r   c                  O   s   d S r.   r/   )r   kwargsr/   r/   r0   setup_progressbar   s    r   c                 C   s  |d u rt  S tjjr t  S | dkr6tjr6t  S | dkr`t|}|d urX|j	}nt  S tj
|  j}|rt|tr|ddu rd S ttj
|  j}tj| d }|td kr||n|tj| < ||krtj
|  jd urtj
|    ttj tt| S )Nsd_model_checkpointr4   F)rh   r3   r]   r'   freeze_settingsr&   disable_weights_auto_swapr
   get_closet_checkpoint_matchtitledata_labelscomponent_args
isinstancedictgetr   r+   dataonchangesaveconfig_filenamegetattr)r   r   Z	ckpt_info	comp_argsvaltypeoldvalr/   r/   r0   apply_setting   s*    
r   c                 C   s   t | |S r.   )r   create_output_panel)tabnameoutdirr/   r/   r0   r     s    r   c              	   C   s   t jrptd| dH tjd| d| | d d}tjddd| d	d
dd}W d    q1 sd0    Y  nhtd| dH tjddd| d	d
dd}tjd| d| | d d}W d    n1 s0    Y  ||fS )NZsampler_selection_r   zSampling methodZ	_samplingr   r   r   choicesr   rR      _stepszSampling steps   )minimummaximumr   r   r   r   )r&   samplers_in_dropdownr   rh   DropdownSliderr   Radio)r   r   sampler_namer   r/   r/   r0   "create_sampler_and_steps_selection  s    <:r  c                  #   sF   dd t tjjD  tt t  fdddD ]\} }|V  q2d S )Nc                 S   s"   i | ]\}}|  |d  d qS )rU   rR   )strip)r   ir;   r/   r/   r0   
<dictcomp>+  r2   z)ordered_ui_categories.<locals>.<dictcomp>c                    s     | d | d d d S )NrR   r   rU   r   r:   Z
user_orderr/   r0   r1   -  r2   z'ordered_ui_categories.<locals>.<lambda>r   )	enumerater]   r&   ui_reorder_listsortedr   ui_reorder_categories)rn   r-   r/   r  r0   ordered_ui_categories*  s    $r  c                 C   s6   t jg dd|  ddd}|jdd |g|gd |S )	NzOverride settingsFZ_override_settingsT)r   r4   r   multiselectc                 S   s   t jjt| dS )Nr6   )rh   r  r3   boolr:   r/   r/   r0   r1   5  r2   z3create_override_settings_dropdown.<locals>.<lambda>r   )rh   r  r   )r   rowdropdownr/   r/   r0   !create_override_settings_dropdown1  s    r  c               +      sR-  dd l dd lt  t  tjt_tjjdd t	j
dd	} tdd}t	jdd}t	jdd}|  t	jdd	d
	}tdd t	jdddL tj  t D ](}|dkrtt d\}}n|dkrt  t	jddd< t	jddddddd}t	jddddddd}	W d    n1 s:0    Y  t	jddd d! ttd"d#d$}
W d    n1 sz0    Y  tjrt	jd%d: t	jddd&dd'd(}t	jdddd)dd*d}W d    n1 s0    Y  W d    n1 s0    Y  n|d+krVt	 & t	jd,d-d.d/d0d1d}W d    n1 sH0    Y  np|d2krtd3dd4 W d    n1 s0    Y  n4|d5krt	jd6d5d7 tdd8d9d:}| " t d;d<d=ddd>}W d    n1 s0    Y  td?dd@f t	j!dAdBg t"j#dCdD t"j$D t"j%dE}t	jddFddGddHd}t	jdId,dJdKdLdMd}W d    n1 sv0    Y  tdNdd@R t	jd,dOdPdQdRdSd}t	jddddTddUd}t	jddddVddWd}W d    n1 s0    Y  tdXdtj&dYh}t	j!dZd[d\gj'j(d]d^ d\dE}t)|j'j*fd_d`da t	j!dbdcddgt  dddE}W d    n1 sp0    Y  tdedtj+dY}t	jdfdgR t	 ( t	j,dhdiddjdkdlgdm}W d    n1 s0    Y  W d    n1 s0    Y  t	jdfdgR t	 ( t	j,dndoddjdpdlgdm}W d    n1 sB0    Y  W d    n1 sb0    Y  W d    n1 s0    Y  W d    n1 s0    Y  tj-| W d    n1 s0    Y  n|dqkrDtjstd%d: t	jddd&dd'd(}t	jdddd)dd*d}W d    n1 s80    Y  n|drkrtdsd}t.d|}W d    n1 sz0    Y  n@|dtkrt/dud tj0 }W d    n1 s0    Y  |dvvrtj-| qW d    n1 s0    Y  |||	|||g}|D ]D} t1| t	jr(| j2n| j3}!|!t4||gddw |!d dx|g ddy qt5dtj6\}"}#}$}%t7t8j9j9g dzd{d|||j:|j;|j<j=||||||	|||||||||||||g| |"|#|$|%gdd}}&|j:j>f i |& |j>j?f i |& |
j?d d~d d dd} |j@j?tAjBd|g|"|#|$|%gdd} |j:df|j;df|df|df|df|df|	df|d)f|j<j=dd` f|dKf|dd` f|df|df|dGf|df|df|dZf|df|dd` f|dhf|dnf|dd` fgtjjC}'tDdd |'| tEtjF|jGd|j:d d |j:|j;|||tjHdjI||	g}(|jJj?tKtL|j:|g|jMgd |jNj?tKtL|j;|g|jOgd W d    n1 	st0    Y  W d    n1 	s0    Y  tPQ| |gd})tP0|)|" |R  W d    n1 	s0    Y  tjSt_tjSjd]d t	j
dd^}*td]d}t	jdd}|  t	jddd
}+tdd t	jddd0 g  i  fdd},t	jdd t	Td}-t	jUdddd8}.t	jVddddd]dddtjWd	}/|,d|/ W d    n1 
s0    Y  t	jUdddd<}0t	jVddddd]dddtjWtjXd
}1|,d|1 W d    n1 s60    Y  t	jUdddd<}2t	jVddddd]dddtjWtjYd
}3|,d|3 W d    n1 s0    Y  t	jUdddd`}4t	jVddddd]dddtjWtjZd
}5t	Td }6|,d|5 dd }7|53|7|5|6g|6 W d    n1 s0    Y  t	jUdddd<}8t	jVdddd]ddd}9t	jVddd]dddd}:W d    n1 st0    Y  t	jUddqdd};t"j[j\rdnd;}<t	]dd|< dÝ  t	j,f ddit"j^ddi}=t	j,f ddit"j^ddi}>t	j,f ddit"j^ddi}?t	j_ddd͍b t	j`f ddit"j^ddi}@t	j,f ddit"j^dddӜ}At	jag dԢddd׍}BW d    n1 s0    Y  W d    n1 s0    Y  |.|0|2|4|8|;g}Ctb|CD ]$\}D}E|Ejc|Dfdd`g |-gd qW d    n1 s
0    Y  ddڄ }F D ]H\}G}H}I|Gj?|F|Ig|H gd |Gj?dd` d|Hdddޡ g g dߍ q t ( t	jeddg dddd}JW d    n1 s0    Y  tjS  t D ]}|dkrtt d\}}n~|dkrt  t	jdddD t	jTdd}Kt	  t	jddd:}Lt  t	jddd< t	jddddddd}t	jddddddd}	W d    n1 s0    Y  t	jddd d!( ttdd}
ttfdd}MW d    n1 s0    Y  W d    n1 s0    Y  W d    n1 s0    Y  t	jddd:~}Nt	jdPdOdPdd,dd}Ot @ t tgdddIdd}Pt	jddd: t	jhddd}QW d    n1 s0    Y  W d    n1 s0    Y  t7tgd|||Og|Pdd}}R|Oj2f i |R |Qj?f i |R |/|1fD ]} | j3dd` dg g dd} qW d    n1 s00    Y  W d    n1 sP0    Y  |Ljcdd` g |Kgd |Njcdd` g |Kgd tjrt	jdd< t	jddd&ddd(}t	jdddd)dd d}W d    n1 s0    Y  W d    n1 s0    Y  nR|dkr6t	jdId,dJdKddd}n(|d+krt	 J t	jd,d-d.d/d0dd}t	jdddPddddd	}SW d    n1 s0    Y  n|d2krtd3dd4 W d    n1 s0    Y  nz|d5kr0t	jd
d5d7 tjS-| W d    n1 s"0    Y  n.|dqkrtjs^tdd< t	jddd&ddd(}t	jdddd)dd d}W d    n1 s0    Y  n|drkrtdd}t.d|}W d    n1 s0    Y  nz|dtkr*t/dd tjS0 }W d    n1 s0    Y  n4|dkr^t/ddd}Tt B t	jddddddd}Ut	jdddd}VW d    n1 s0    Y  t 4 t	jedddgdddd}WW d    n1 s0    Y  t 2 t	jedg ddddd}XW d    n1 s.0    Y  t  t	 4 t	jeddd gddd!d"}YW d    n1 s0    Y  t	jddg0 t	jd#dd$dd%d&d}ZW d    n1 s0    Y  W d    n1 s0    Y  d'd( tb|CD ],\}D}I|Ijc|Dffd)d`	g |T|Vgd qW d    n1 sT0    Y  |dvvrtjS-| qW d    n1 s0    Y  t5dtji\}[}#}$}%t7t8jjjjg dzd{d*|||j:|j;|j<j=|/|1|3|5|6|9|:|||U|V|X||||S||K|	||O|J|Y|Z|W|=|>|?||@|B|Ag%| |[|#|$|%gdd}}\t7d+||=|>|/|1|3|5|9g|j:|gd,}]|j:j>f i |\ |j>j?f i |\ |
j?d d-d d dd} |Mj?d.d` d|||g||	gdd} |j@j?tAjBd/|g|[|#|$|%gdd} |jkj?f d0d1d` i|] |jlj?f d0d2d` i|] |jJj?tL|j:|g|jMgd |jNj?tKtL|j;|g|jOgd |j:df|j;df|df|df|df|Sd3f|df|	df|d)f|j<j=d4d` f|dKf|UdfgtjSjC}^tDd|/|^| tDd|3|^| tEtjF|jGd|j:d d W d    n1 s0    Y  W d    n1 s(0    Y  tPQ|*|+gd}_tP0|_|[ |R  W d    n1 sl0    Y  d t_t	j
dd}`tmQ  W d    n1 s0    Y  t	j
ddd}at	jdd t	jd5d6* t	jVd7d8dd]dd9}bW d    n1 s0    Y  t	jd5d6 t	] }ct	j,dd:d}#t	] }dt	   tng d;}eW d    n1 s0    Y  |eo D ]"\}f}GtEtjF|G|f|#|bd qW d    n1 s0    Y  W d    n1 s0    Y  |bj3tpjqjr|bg|c|#|dgd W d    n1 s,0    Y  tst }gt	j
dd}ht	jdd t	j]d<d W d    n1 s0    Y  t	jddd= t	jd>df t	jd?d@dA t	j,dBdCd:}it	j,dDdEdFdG}jt	jdHddIdddJd}kt	j`ddKdLdM}lt	  t	jdjdg t	j]d;d W d    n1 s`0    Y  t	 ( t	jhd?dNdOdP}mW d    n1 s0    Y  W d    n1 s0    Y  W d    n1 s0    Y  t	jdQdRdA t	j,dBdSd:}nt	jadTg dUg dVdWdX}ot	j,dYdZd[d\d]}pt	j!d^d_tujvd`da}qt	j!dbdcg dddeda}rt	j`dfdgd:}st	j`dhdid:}tt	j,djdkdldm}ut	j`ddndodM}vt	  t	jdjdg t	j]d;d W d    n1 s0    Y  t	 ( t	jhdQdNdpdP}wW d    n1 s`0    Y  W d    n1 s0    Y  W d    n1 s0    Y  t	jdqdrdA t	j,dsdtd:}xt	j,dudvd:}yt	jddddddwd}zt	jddddddxd}{t	j!dydzg d{d|dX}|t	  t	j`d}d~d:}}t	j`ddd:}~t	j`ddd:}t	j`ddd:}t	j`ddd:}t	j`ddd:}t	j`dd]dd}W d    n1 s0    Y  t	jddL}t	jdd.dId,dPdd}t	jdddIddPdd}W d    n1  sB0    Y  t	jddz}t	jdddId,dPdd}t	jdddId,dPdd}t	jdd.dId,dPdd}t	j`ddd:}W d    n1  s0    Y  t	jddP}t	wd t	 H t	jddddddd}t	jddddddd}W d    n1 !sX0    Y  t	 P t	jddddddd}t	jddddddd}W d    n1 !s0    Y  t	 N t	jeddgddddM}t	jdddJdddd}W d    n1 "s*0    Y  W d    n1 "sJ0    Y  t	  t	jdjdg t	j]d;d W d    n1 "s0    Y  t	 d t	 " t	jhddd}W d    n1 "s0    Y  t	jhddNddP}W d    n1 #s0    Y  W d    n1 #s,0    Y  |j3dd` |g|gd |j3dd` |g|gd |j3dd` |g|gd W d    n1 #s0    Y  dd t	jdddA t	j]dd t  t	j!ddtxtyjzj{j|v d}t)|tyjzj{j}dd` d t	j!ddtxt"j~d}t)|t"jdd` dă W d    n1 $sh0    Y  t H t	j,dŐdŐdƐdǐdȍ}t	j,dɐdɐdʐdːdȍ}W d    n1 $s0    Y  t B t	j!d̐dg d΢dύ}t	j,dАdddҍ}W d    n1 %s"0    Y  t > t	jd)dddӐdԍ}t	jdddd֐dԍ}W d    n1 %sx0    Y  t	j,dאdؐdِd]}t	j,dڐdېdܐdݐdȍ}t H t	j!dސdߐd d}t)|tjfdd`d W d    n1 &s0    Y  t	jddddddd}t	jddddddd}t	j`ddddG}t	jdddddԍ}t D t	jdddddԍ}t	jdddddԍ}W d    n1 &s0    Y  t	j`ddddG}t	j`dd]ddG}t	j`ddddG}t	j`ddddG}t	jddddddd}t	jeddg dddX}t	 R t	jhddNddP}t	jhdd d}t	jhddNddP}W d    n1 's0    Y  W d    n1 's0    Y  t|(}t| W d    n1 (s0    Y  t	jdd` t	jdd;dd}t	jddddd t	j]d	d;d
 t	j]dd;d
}W d    n1 (s0    Y  W d    n1 (s0    Y  |mj?tj|i|j|k|lg|||gd |wj?tuj|n|o|v|p|q|r|s|t|ug	|||gd |j?t8tjt	 gd{d||x|y|z|{|||}|~|||||||||||||||||g||gdߍ |j?t8tjt	 gd{d||||||||||||||||||||||g|(||gdߍ |j?t8tujt	 gd{d|||||||||||||||||||||g|(||gdߍ |j?dd` g g d |j?dd` g g d W d    n1 *sZ0    Y  tt[j}t }|Q|| | ddf|*ddf|`ddf|addf|gjddf|hddfg}|t 7 }||jddfg7 }tQ }||ddfg7 }g t"_|D ]\}}}t"j| +qt	j
t"jddd}|  t  t	jdd}dd tbtjD tx|fdd`d}|D ]x\}}}|t"jjv +r+qt	jU||d | d |  W d    n1 +s0    Y  |d!v+r||| +q|d"|j | |0  W d    n1 ,sH0    Y  tjtjtd#,rt	jdtjtd#d$dd% t"d&}|jt t"j[j,rd'nd(d)}t	j]|d*d || d+d` }|jj3|g |Sgd |j|g |Sgd |gj0||jd, d- W d    n1 -s60    Y  |  ||_|S (.  Nr   F)r   )analytics_enabledr6   Ztxt2img_extra_tabsr   Z
GenerationZtxt2img_generation)id)equal_heightr   Ztxt2img_settingsr   r   samplerr   
dimensionsZtxt2img_column_sizerT   r   @   i      Widthi   Ztxt2img_width)r  r  r   r   r   r   HeightZtxt2img_heightZtxt2img_dimensions_rowrR   zdimensions-tools)r   r   r   Ztxt2img_res_switch_btnzSwitch dims)r   r   r   Ztxt2img_column_batchzBatch countZtxt2img_batch_count)r  r   r   r   r   z
Batch sizeZtxt2img_batch_sizecfgg      ?g      >@g      ?z	CFG Scaleg      @Ztxt2img_cfg_scale
checkboxeszcheckboxes-row)r   r   
accordionsZtxt2img_accordionsr   z
Hires. fixZ
txt2img_hr)r   r   r=   Ztxtimg_hr_finalreszUpscaled resolution)r   r   r   interactive	min_widthZtxt2img_hires_fix_row1r   UpscalerZtxt2img_hr_upscalerc                 S   s   g | ]
}|j qS r/   )namer   r;   r/   r/   r0   r   u  r2   zcreate_ui.<locals>.<listcomp>r   r   zHires stepsZtxt2img_hires_stepsg        g{Gz?Denoising strengthgffffff?Ztxt2img_denoising_strengthZtxt2img_hires_fix_row2g      @g?z
Upscale byg       @Ztxt2img_hr_scalezResize width toZtxt2img_hr_resize_xzResize height toZtxt2img_hr_resize_yZtxt2img_hires_fix_row3)r   r   r4   Hires checkpointZhr_checkpointUse same checkpointT	use_shortc                      s   ddg j jdd iS )Nr   r,  Tr-  )r
   checkpoint_tilesr/   )r   r/   r0   r1     r2   zcreate_ui.<locals>.<lambda>Zhr_checkpoint_refreshzHires sampling methodZ
hr_samplerUse same samplerZtxt2img_hires_fix_row4r   r   Hires promptZhires_promptrS   zOPrompt for hires fix pass.
Leave empty to use the same prompt as in first pass.ru   r   Hires negative promptZhires_neg_promptzaNegative prompt for hires fix pass.
Leave empty to use the same negative prompt as in first pass.batchoverride_settingsZtxt2img_override_settings_rowr   Ztxt2img_script_container>   r$  r   ZonCalcResolutionHires)ry   r{   r|   r   )Nr=   r=   )Zextra_outputsr   )rz   ry   r{   r|   r   z(function(){switchWidthHeight('txt2img')}ZrestoreProgressTxt2imgr   r   StepsSampler	CFG scalezSize-1zSize-2c                 S   s    t | dtr| d S t S NzStyles arrayr   r   listrh   r3   dr/   r/   r0   r1     r2   c                 S   s    d| v od| v pd| v pd| v S )Nr*  Hires upscaleHires upscalerHires resize-1r/   r;  r/   r/   r0   r1     r2   r=  r>  r?  zHires resize-2Hires samplerc                 S   s4   |  dddks |  dddkr,tjddS t S )Nr@  r0  r+  r,  Tr6   r   rh   r3   r;  r/   r/   r0   r1     r2   c                 S   s4   |  dddks |  dddkr,tjddS t S )Nr1  r=   r2  Tr6   rA  r;  r/   r/   r0   r1     r2   )paste_buttonr   source_text_componentsource_image_componentSeedr   Zimg2img_extra_tabsZimg2img_generationZimg2img_settingsc                    s   t jdd|  dz t jdd|  d tg dg dD ]B\}}|| krdt j|d	d
 ||< q<t |} |||f q<W d    n1 s0    Y  d S )Nr   Zimg2img_copy_to_r  zCopy image to: Zimg2img_label_copy_to_r   )r   sketchinpaintzinpaint sketch)r   rF  rG  inpaint_sketchF)r%  )rh   r   r   zipr   append)tab_nameelemr   r(  r~   )copy_image_buttonscopy_image_destinationsr/   r0   add_copy_image_controls-  s    
z*create_ui.<locals>.add_copy_image_controlsZmode_img2imgr   Zimg2img_img2img_tab)r  r   zImage for img2imgZimg2img_imageuploadpileditorRGBA)	r   r   r   sourcer%  r   tool
image_moder?   ZSketchZimg2img_sketchZimg2img_img2img_sketch_tabzcolor-sketchrp   )
r   r   r   rT  r%  r   rU  rV  r?   brush_colorrF  ZInpaintrG  Zimg2img_inpaint_tabzImage for inpainting with maskZimg2maskimg)
r   r   r   rT  r%  r   rU  rV  r?   rW  zInpaint sketchrH  Zimg2img_inpaint_sketch_tabzColor sketch inpaintingc                 S   s`   | d ur\|d uo|j | j k}ttjt| t|kdd}|oF|}|rT|d u rX| S |S d S )N)axis)sizenpanyallarray)rV   r   Z	same_sizeZhas_exact_matcheditedr/   r/   r0   update_origN  s
    $zcreate_ui.<locals>.update_origzInpaint uploadZinpaint_uploadZimg2img_inpaint_upload_tabZimg_inpaint_base)r   r   rT  r%  r   r   MaskZimg_inpaint_mask)r   rT  r%  r   rV  r   ZBatchZimg2img_batch_tabz5<br>Disabled when launched with --hide-ui-dir-config.z<p style='padding-bottom: 1em;' class="text-gray-500">Process images in a directory on the same machine where the server is running.<br>Use an empty output directory to save pictures normally instead of writing to the output directory.zH<br>Add inpaint batch mask directory to enable inpaint batch processing.z</p>r   zInput directoryr   img2img_batch_input_dirzOutput directoryimg2img_batch_output_dirzIInpaint batch mask directory (required for inpaint batch processing only)img2img_batch_inpaint_mask_dirzPNG info)rc   zAppend png info to promptsimg2img_batch_use_png_infozPNG info directoryz"Leave empty to use input directoryimg2img_batch_png_info_dir)r   r   )r   r   rE  r7  r6  r5  z Parameters to take from png infoz<Prompts from png info will be appended to prompts set in ui.)r   infoc                 S   s   | S r.   r/   )Ztabnumr/   r/   r0   r1   n  r2   c                 S   s   t | trd| v r| d S | S )NrV   )r   r   )rk   r/   r/   r0   
copy_imagep  s    zcreate_ui.<locals>.copy_imagec                   S   s   d S r.   r/   r/   r/   r/   r0   r1   }  r2   
switch_to_ rn   r   zResize moderesize_mode)Just resizezCrop and resizezResize and fillzJust resize (latent upscale)indexrl  )r   r   r   r   r   Zimg2img_column_size)r   z	Resize toZimg2img_tab_resize_toZimg2img_widthZimg2img_heightZimg2img_dimensions_rowZimg2img_res_switch_btnr   Zimg2img_detect_image_size_btnz	Resize byZimg2img_tab_resize_byScaleZimg2img_scaleZ img2img_scale_resolution_previewZUnusedZimg2img_unused_scale_by_sliderZimg2img_update_resize_tor   ZcurrentImg2imgSourceResolutionc                   S   s   d S r.   r/   r/   r/   r/   r0   r1     r2   Z+updateImg2imgResizeToTextAfterChangingImagec                   S   s   dS r8   r/   r/   r/   r/   r0   r1     r2   c                   S   s   dS )NrR   r/   r/   r/   r/   r0   r1     r2   Zimg2img_column_batchZimg2img_batch_countZimg2img_batch_size	denoisingg      ?Zimg2img_denoising_strengthZimg2img_cfg_scaleg      @zImage CFG Scaleg      ?Zimg2img_image_cfg_scale)r  r  r   r   r   r   r4   Zimg2img_accordionsZimg2img_override_settings_rowZimg2img_script_containerinpaint_controls)r   r4   z	Mask blurZimg2img_mask_blur)r   r  r  r   r   r   zMask transparencyZimg2img_mask_alpha)r   r4   r   z	Mask modezInpaint maskedzInpaint not maskedZimg2img_mask_mode)r   r   r   r   r   zMasked content)filloriginalzlatent noisezlatent nothingrr  Zimg2img_inpainting_fillzInpaint areazWhole picturezOnly maskedZimg2img_inpaint_full_res)r   r   r   r   r   zOnly masked padding, pixels       Z img2img_inpaint_full_res_paddingc                 S   s    t j| dv dt j| dkdfS )N)rU   rS   rT   r6   rS   rh   r3   tabr/   r/   r0   select_img2img_tab  s    z%create_ui.<locals>.select_img2img_tabc                    s    | S r.   r/   rv  )rx  r/   r0   r1     r2   Zsubmit_img2imgZget_img2img_tab_index)ry   r{   r|   z(function(){switchWidthHeight('img2img')}c                 S   s   | p
t  |pt  fS r.   ru  )whrn   r/   r/   r0   r1   D  r2   ZrestoreProgressImg2imgrz   c                  W   s   t tg| R  S r.   )ro   rr   r   r/   r/   r0   r1   Y  r2   c                  W   s   t tg| R  S r.   )ro   rx   r   r/   r/   r0   r1   ^  r2   zImage CFG scalec                 S   s    t | dtr| d S t S r8  r9  r;  r/   r/   r0   r1   o  r2   panel)r   Zpnginfo_imageSource)r   r   rT  r%  r   Zpnginfo_generation_info)r   r   rG  extrasz<p style='margin-bottom: 0.7em'>See <b><a href="https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Textual-Inversion">wiki</a></b> for detailed explanation.</p>)r   r  Z
train_tabszCreate embeddingcreate_embedding)r   r  NameZtrain_new_embedding_namezInitialization text*Ztrain_initialization_text)r   r   r   zNumber of vectors per tokenK   Z
train_nvptzOverwrite Old EmbeddingZtrain_overwrite_old_embedding)r   r   r   r   Ztrain_create_embedding)r   r   r   zCreate hypernetworkcreate_hypernetworkZtrain_new_hypernetwork_nameModules)7683206401280)r  Z1024r  r  r  Ztrain_new_hypernetwork_sizes)r   r   r   r   z1, 2, 1z"Enter hypernetwork layer structurez*1st and last digit must be 1. ex:'1, 2, 1'Z&train_new_hypernetwork_layer_structure)r   r   r   linearzNSelect activation function of hypernetwork. Recommended : Swish / Linear(none)Z&train_new_hypernetwork_activation_func)r   r   r   r   NormalzrSelect Layer weights initialization. Recommended: Kaiming for relu-like, Xavier for sigmoid-like, Normal otherwise)r  KaimingUniformKaimingNormalXavierUniformXavierNormalZ,train_new_hypernetwork_initialization_optionzAdd layer normalizationZ%train_new_hypernetwork_add_layer_normzUse dropoutZ"train_new_hypernetwork_use_dropoutz0, 0, 0zjEnter hypernetwork Dropout structure (or empty). Recommended : 0~0.35 incrementing sequence: 0, 0.05, 0.15zR1st and last digit must be 0 and values should be between 0 and 1. ex:'0, 0.01, 0')r   r   zOverwrite Old HypernetworkZ train_overwrite_old_hypernetworkZtrain_create_hypernetworkzPreprocess imagesZpreprocess_imageszSource directoryZtrain_process_srczDestination directoryZtrain_process_dstZtrain_process_widthZtrain_process_heightzExisting Caption txt Actionr,   )r,   copyprependrJ  Ztrain_preprocess_txt_actionzKeep original sizeZ train_process_keep_original_sizezCreate flipped copiesZtrain_process_flipzSplit oversized imagesZtrain_process_splitzAuto focal point cropZtrain_process_focal_cropzAuto-sized cropZtrain_process_multicropzUse BLIP for captionZtrain_process_captionzUse deepbooru for captionZtrain_process_caption_deepbooruzSplit image thresholdZtrain_process_split_threshold)r   r   r  r  r   r   zSplit image overlap ratiog?g?Ztrain_process_overlap_ratiozFocal point face weightZ$train_process_focal_crop_face_weightzFocal point entropy weightg333333?Z'train_process_focal_crop_entropy_weightzFocal point edges weightZ%train_process_focal_crop_edges_weightzCreate debug imageZtrain_process_focal_crop_debugzKEach image is center-cropped with an automatically chosen width and height.zDimension lower boundi  Ztrain_process_multicrop_mindimzDimension upper boundi   Ztrain_process_multicrop_maxdimi   i  @ zArea lower boundZtrain_process_multicrop_minareazArea upper boundi @ Ztrain_process_multicrop_maxareazMaximize areazMinimize errorzResizing objectiveZ!train_process_multicrop_objectivezError thresholdg?Z!train_process_multicrop_thresholdr   Ztrain_interrupt_preprocessingZ
PreprocessZtrain_run_preprocessc                 S   s   t | S r.   r7   showr/   r/   r0   r1     r2   c                 S   s   t | S r.   r  r  r/   r/   r0   r1     r2   c                 S   s   t | S r.   r  r  r/   r/   r0   r1     r2   c                   S   s
   t tjS r.   )r  textual_inversiontextual_inversion_templatesr/   r/   r/   r0   $get_textual_inversion_template_names  s    z7create_ui.<locals>.get_textual_inversion_template_namesTraintraina  <p style='margin-bottom: 0.7em'>Train an embedding or Hypernetwork; you must specify a directory with a set of 1:1 ratio images <a href="https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Textual-Inversion" style="font-weight:bold;">[wiki]</a></p>	Embeddingtrain_embedding)r   r   r   c                   S   s   dt tjjj iS Nr   )r  r	   r)   embedding_dbword_embeddingskeysr/   r/   r/   r0   r1     r2   Zrefresh_train_embedding_nameHypernetworktrain_hypernetworkc                   S   s   dt tjiS r  )r  r]   hypernetworksr/   r/   r/   r0   r1     r2   Zrefresh_train_hypernetwork_namezEmbedding Learning ratez0.005Ztrain_embedding_learn_rate)r   r   r   r   zHypernetwork Learning ratez0.00001Ztrain_hypernetwork_learn_ratedisabledzGradient Clipping)r  r   norm)r   r   r   zGradient clip valuez0.1)r   r   r   train_batch_size)r   r   	precisionr   zGradient accumulation stepsZtrain_gradient_stepzDataset directoryz#Path to directory with input imagesZtrain_dataset_directoryzLog directoryz(Path to directory where to write outputsr  Ztrain_log_directoryzPrompt templatezstyle_filewords.txtZtrain_template_file)r   r   r   r   c                      s
   d  iS r  r/   r/   )r  r/   r0   r1   !  r2   Zrefrsh_train_template_fileZtrain_training_widthZtrain_training_heightzDo not resize imagesZtrain_varsizez	Max stepsi Ztrain_stepsz:Save an image to log directory every N steps, 0 to disablei  Ztrain_create_image_everyzESave a copy of embedding to log directory every N steps, 0 to disableZtrain_save_embedding_everyz$Use PNG alpha channel as loss weight
use_weightz(Save images with embedding in PNG chunksZ&train_save_image_with_stored_embeddingzFRead parameters (prompt, etc...) from txt2img tab when making previewsZtrain_preview_from_txt2imgz*Shuffle tags by ',' when creating prompts.Ztrain_shuffle_tagsz$Drop out tags when creating prompts.Ztrain_tag_drop_outzChoose latent sampling methodonce)r  deterministicrandomZtrain_latent_sampling_methodzTrain EmbeddingZtrain_train_embeddingZtrain_interrupt_trainingzTrain HypernetworkZtrain_train_hypernetworkZti_gallery_container	ti_output)r   r   r   OutputZ
ti_gallery)r   r   r   columnsZti_progress)r   r   Zti_errorZ start_training_textual_inversionc                   S   s
   t j S r.   r   r/   r/   r/   r0   r1     r2   c                   S   s
   t j S r.   r   r/   r/   r/   r0   r1     r2   ZExtrasr}  zPNG InfopnginfozCheckpoint MergerZmodelmergerZSettingssettings
Extensions
extensionszStable Diffusion)themer  r   tabsc                 S   s   i | ]\}}||qS r/   r/   )r   r
  kr/   r/   r0   r    r2   zcreate_ui.<locals>.<dictcomp>c                    s     | d dS )NrR   i'  r  r:   )	tab_orderr/   r0   r1     r2   r   Ztab_)r  r  zwebui/Tabs@znotification.mp3Zaudio_notification)r%  r   r   r4   zfooter.htmlz/docsz@https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/API)versionsZapi_docsfooterc                   S   s   t jtjotjjdkdS )Neditr6   )rh   r3   r]   sd_modelcond_stage_keyr/   r/   r/   r0   r1     r2   r   )dummy_componentZsd_model_checkpoint_component)Zmodules.img2imgZmodules.txt2imgr%   parameters_copypasteresetr   scripts_txt2imgscripts_currentinitialize_scriptsrh   Blocksr   LabelTabs	__enter__Tabr"   r   
prepare_uir  r  r   visible_sampler_namesr   r  r   switch_values_symbolr&   dimensions_and_batch_togetherr   r!   extrar    r  r]   latent_upscale_modessd_upscalerslatent_upscale_default_modehires_fix_show_samplerr
   r/  r$   list_modelshires_fix_show_promptsr   setup_ui_for_sectionr  r   setup_uir   releaser   rL   r   outdir_txt2img_samplesr   r   r   ru   r   r   r  r   r}   r   r   Zrestore_progressinfotext_fieldsadd_paste_fieldsregister_paste_params_buttonParamBindingr   scriptseedr   r   r   r   r   r   r   	create_ui__exit__scripts_img2imgStateTabItemr   img2img_editor_height"img2img_sketch_default_brush_color img2img_inpaint_mask_brush_color*img2img_inpaint_sketch_default_brush_colorr'   r^   r   	hide_dirs	AccordionCheckboxCheckboxGroupr  selectreplacer  detect_image_size_symbolrQ   r   outdir_img2img_samplesr   r   r   r   create_buttonsitemsr   r}  Zrun_pnginfor   ZUiCheckpointMergerhypernetworks_uir  Markdownr  r	   r)   r  r  !load_textual_inversion_embeddingsr  reload_hypernetworksNumberr   list_textual_inversion_templatesr   UiTrainTabParamsui_train_tabs_callbackTextGallerytextual_inversion_uir~  r  
preprocessr3   r  r  r   Z
UiLoadsaveui_config_filer   Z
UiSettingsblocksui_tabs_callback	interfacer   	tab_namesrJ  gradio_themeZadd_quicksettingsconnect_paste_params_buttonsui_tab_orderhidden_tabsrenderZ	add_blockZadd_componentr   ra   rd   existsrg   r#   Audiohtmlformatversions_htmlapiZadd_functionalityZtext_settingsloadZcomponent_dictZdump_defaults)Ztxt2img_interfaceZtoprowr  Z
extra_tabsZtxt2img_generation_tabr-   r   r  r>   r?   Zres_switch_btnZbatch_count
batch_size	cfg_scaler@   Zhr_final_resolutionhr_upscalerhr_second_pass_stepsdenoising_strengthrA   rB   rC   Zhr_sampler_containerhr_checkpoint_namehr_sampler_nameZhr_prompts_container	hr_prompthr_negative_promptr  r4  Zcustom_inputsZhr_resolution_preview_inputs	componenteventZtxt2img_galleryZgeneration_infoZ	html_infoZhtml_logZtxt2img_argstxt2img_paste_fieldstxt2img_preview_paramsZextra_networks_uiZimg2img_interfaceZimg2img_generation_tabrO  Zimg2img_selected_tabZtab_img2imginit_imgZ
tab_sketchrF  Ztab_inpaintZinit_img_with_maskZtab_inpaint_colorZinpaint_color_sketchZinpaint_color_sketch_origr`  Ztab_inpaint_uploadZinit_img_inpaintZinit_mask_inpaintZ	tab_batchhiddenrb  rc  rd  re  rf  Zimg2img_batch_png_info_propsZimg2img_tabsr
  rw  rh  r~   r(  rL  rk  Zselected_scale_tabZtab_scale_toZdetect_image_size_btnZtab_scale_byrN   Zscale_by_htmlZbutton_update_resize_toZon_change_argsimage_cfg_scalerp  	mask_blurZ
mask_alphainpainting_mask_invertinpainting_fillinpaint_full_resinpaint_full_res_paddingZimg2img_galleryZimg2img_argsZinterrogate_argsimg2img_paste_fieldsZextra_networks_ui_img2imgZextras_interfaceZpnginfo_interfacerV   r  Zhtml2buttonsr   Zmodelmerger_uiZtrain_interfaceZnew_embedding_nameZinitialization_textnvptZoverwrite_old_embeddingr~  Znew_hypernetwork_nameZnew_hypernetwork_sizesZ new_hypernetwork_layer_structureZ new_hypernetwork_activation_funcZ&new_hypernetwork_initialization_optionZnew_hypernetwork_add_layer_normZnew_hypernetwork_use_dropoutZ"new_hypernetwork_dropout_structureZoverwrite_old_hypernetworkr  Zprocess_srcZprocess_dstZprocess_widthZprocess_heightZpreprocess_txt_actionZprocess_keep_original_sizeZprocess_flipZprocess_splitZprocess_focal_cropZprocess_multicropZprocess_captionZprocess_caption_deepbooruZprocess_split_extra_rowZprocess_split_thresholdZprocess_overlap_ratioZprocess_focal_crop_rowZprocess_focal_crop_face_weightZ!process_focal_crop_entropy_weightZprocess_focal_crop_edges_weightZprocess_focal_crop_debugZprocess_multicrop_colZprocess_multicrop_mindimZprocess_multicrop_maxdimZprocess_multicrop_minareaZprocess_multicrop_maxareaZprocess_multicrop_objectiveZprocess_multicrop_thresholdZinterrupt_preprocessingZrun_preprocessZtrain_embedding_nameZtrain_hypernetwork_nameZembedding_learn_rateZhypernetwork_learn_rateclip_grad_modeclip_grad_valuegradient_stepZdataset_directorylog_directorytemplate_filetraining_widthtraining_heightvarsizecreate_image_everysave_embedding_everyr   save_image_with_stored_embeddingpreview_from_txt2imgshuffle_tagstag_drop_outlatent_sampling_methodr  Zinterrupt_trainingr  paramsr  Z
ti_outcomeZloadsaver  
interfacesZextensions_interface
_interfacer   Z_ifiddemor  Zsorted_interfacesr  Zifidr  Z!update_image_cfg_scale_visibilityr/   )rM  rN  r  r   rx  r  r0   r  =  s&   
 


6.Z

:
$

2*66"<
X
.
8
,
*.
'


 `(
 
*"*"*"

26 T>
8



6lN\\

F
$
0
<
.
.
6DB
D`*
0&(3
 H((:
0L
&.
,
x$ 
,
x 
6@2
<
 @
"\
,

2X&$8<68<: 
X
*R$"!&	(("$

8r  c                  C   s   dd l } dd l}ddd tjdd D }| }| }tjrTdd l	}|j
}nd}d| d| d	tj d| d
t| d| j
 d| dtj
 dS )Nr   .c                 S   s   g | ]}t |qS r/   )strr)  r/   r/   r0   r   "  r2   z!versions_html.<locals>.<listcomp>rS   zN/AzR
version: <a href="https://github.com/AUTOMATIC1111/stable-diffusion-webui/commit/z">u.   </a>
&#x2000;•&#x2000;
python: <span title="u#   </span>
&#x2000;•&#x2000;
torch: __long_version__u   
&#x2000;•&#x2000;
xformers: u   
&#x2000;•&#x2000;
gradio: uD   
&#x2000;•&#x2000;
checkpoint: <a id="sd_checkpoint_hash">N/A</a>
)torchlaunchrg   sysversion_infocommit_hashgit_tagr]   xformers_availablexformers__version__versionr   rh   )r7  r8  python_versioncommitrw   r>  Zxformers_versionr/   r/   r0   r    s0    	r  c                    s   ddl m}m  ddlm} G  fddd|fdd}| jd|d	g| d
 | jddd d	gd | jddd d	gd ddd| jdd	gd | jdfddd	gd d S )Nr   )	BaseModelField)Listc                       s2   e Zd ZU  ddZeed<  ddZeed< dS )z'setup_ui_api.<locals>.QuicksettingsHintzName of the quicksettings field)r   r(  z Label of the quicksettings fieldr   N)r   r   r   r(  r5  __annotations__r   r/   )rD  r/   r0   QuicksettingsHint?  s   
rG  c                      s    fddt j D S )Nc                    s   g | ]\}} ||j d qS ))r(  r   )r   )r   r  vrG  r/   r0   r   D  r2   z<setup_ui_api.<locals>.quicksettings_hint.<locals>.<listcomp>)r&   r   r  r/   rI  r/   r0   quicksettings_hintC  s    z(setup_ui_api.<locals>.quicksettings_hintz/internal/quicksettings-hintGET)methodsresponse_modelz/internal/pingc                   S   s   i S r.   r/   r/   r/   r/   r0   r1   H  r2   zsetup_ui_api.<locals>.<lambda>)rL  z/internal/profile-startupc                   S   s   t jS r.   )r   startup_recordr/   r/   r/   r0   r1   J  r2   Fc                 S   sP   ddl m} t }dtj d d}||d| r:dnd d	| d
idS )Nr   )PlainTextResponsezsysinfo-z%Y-%m-%d-%H-%MrY   zContent-Disposition
attachmentinlinez; filename="")headers)fastapi.responsesrO  r   r   datetimeutcnowstrftime)rP  rO  r   rl   r/   r/   r0   download_sysinfoL  s    z&setup_ui_api.<locals>.download_sysinfoz/internal/sysinfoz/internal/sysinfo-downloadc                      s
    ddS )NT)rP  r/   r/   )rX  r/   r0   r1   U  r2   )F)pydanticrC  rD  typingrE  add_api_route)apprC  rE  rJ  r/   )rD  rG  rX  r0   setup_ui_api;  s    
r]  )T)rU  	mimetypesra   r9  	functoolsr   warningsgradiorh   Zgradio.utilsnumpyr[  PILr   r   modules.call_queuer   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Zmodules.ui_componentsr   r   r   r    r!   r"   Zmodules.pathsr#   Zmodules.ui_commonr$   Zmodules.ui_gradio_extensionsr%   Zmodules.sharedr&   r'   Z'modules.generation_parameters_copypastegeneration_parameters_copypaster  Zmodules.hypernetworks.uir  uir  Zmodules.textual_inversion.uir  r  +modules.textual_inversion.textual_inversionr]   modules.imagesr(   modules.sd_hijackr)   r*   Zcreate_setting_componentfilterwarningsshow_warningsUserWarning show_gradio_deprecation_warningsdeprecationGradioDeprecationWarninginitadd_typesharelistenutilsversion_checkget_local_ip_addressngrokZmodules.ngrokr`   connectportngrok_optionsr7   sample_img2imgrd   r  Zrandom_symbolZreuse_symbolr   Zrefresh_symbolZsave_style_symbolZapply_style_symbolr   Zextra_networks_symbolr  r   r  Zplaintext_to_htmlr<   rL   rQ   ro   rr   rx   r   r   r   r   r   r   r  r  r  r  r  r]  r/   r/   r/   r0   <module>   s   X 



H!       h