o
    e                      @   s`  d dl Z d dlZd dlmZ d dlmZ d dlZejj	ejj
ejjejjejjgZejjjZejjjZg dZg dZeejj	jejj	d Zeejj	jejj	d Zdd Zd	d
 Ze \ZZdZejej	 eddZe   ej!dddd{ e   ej"dddZ#ej"ddddZ$W d   n1 sw   Y  e% B e&d! e'd ej(dd eD dddZ)ej"ddd Z*W d   n1 sw   Y  e&d! e'd" ej(d#d eD d$d%Z+ej,d&dd' g Z-eD ]Z.e-/ej0d(e. d% qW d   n	1 sw   Y  ej(d)d eD d*d%Z1ej,d+dd' g Z2eD ]Z.e2/ej0d,e. d% q0W d   n	1 sKw   Y  ej(d-d eD d.d%Z3ej,d/dd' g Z4eD ]Z.e4/ej0d0e. d% qhW d   n	1 sw   Y  W d   n	1 sw   Y  e&d1 e'd2 ej(d3d eD d4d%Z5ej,d5dd' g Z6eD ]Z.e6/ej7d6e. d% qW d   n	1 sw   Y  ej(d7d eD d8d%Z8ej,d9dd' g Z9eD ]Z.e9/ej7d:e. d% qW d   n	1 sw   Y  ej(d;d eD d<d%Z:ej,d=dd' g Z;eD ]Z.e;/ej7d>e. d% q+W d   n	1 sFw   Y  W d   n	1 sVw   Y  e&d? e'd@ e'dA g g Z<Z=e>dBD ]3Z.e  # ej7dCe.d  d%Z?ej@dDd%ZAe</e? e=/eA W d   n	1 sw   Y  qtg g ZBZCe'dE e>dBD ]3Z.e  # ej7dCe.d  d%Z?ej@dDd%ZAeB/e? eC/eA W d   n	1 sw   Y  qW d   n	1 sw   Y  g ZDdFd eD dGd eD  dHd eD  ZEeEdd eEdd dId eD dJd eD dKd eD dLd eD g dMdNgg dO	ZFeD ]!ZGeGHdPrHq>eFD ]ZIeIeGv r\eFeI /dQeG   nqJq>eFdR eFdS eJeEd  eFdS eFdR eJeEd  eFdR< eFdS< eD ]^\ZKZLZMe&eKJ e'eLdT  eMD ]8ZGg ZNeFD ] ZIeIeGv reFeI dd ZNdQeG eNv reNOdQeG   nqej(eGeeGeNdUdVZPeD/eP qW d   n	1 sw   Y  qW d   n	1 sw   Y  W d   n	1 sw   Y  ej!dWdXdY ej!dZd[ e'd\ ej,d]dd^ ejQd_d`ZRW d   n	1 s0w   Y  ej,dadd^@ e'db e   ej7dcd%ZSej7ddd%ZTej7dedfdgZUW d   n	1 sew   Y  e"daZVej'ddhZWW d   n	1 sw   Y  e'di W d   n	1 sw   Y  ej7djdkdldldUdmZXe   ejYdnd%ZZejYdod%Z[W d   n	1 sw   Y  ej\g dpdqd% e   ej!dZddr3 e'ds ej]g dpdtdudvZ^ej(g dwddxZ_ej(g dydUdzgd{dUd|Z`ej@d}d%ZaW d   n	1 sw   Y  ej!dZd~dr} ejbddddZce  5 ej"d}dddZdej"ddddZedd Zfedjgefe^e_e`eaeXgecdd dd Zheegehdec W d   n	1 scw   Y  e   ej"dddZiejjddZkej"dddddZlW d   n	1 sw   Y  W d   n	1 sw   Y  W d   n	1 sw   Y  ejmdddgdUgddddgdgge^e_e`eagdd e  6 ejng dg dg dgdd ejodd~dg ddddd ejpddddd eq  W d   n	1 s
w   Y  e   e0  erd ejsg ddd~d W d   n	1 s2w   Y  e   ej!d~d$ ejtdgdd%Zue"dZvdd Zwevjgdd eueudd W d   n	1 sjw   Y  ej!dd5 e,d e'd ejxdd% ejxdd% ejxdd% W d   n	1 sw   Y  W d   n	1 sw   Y  W d   n	1 sw   Y  W d   n	1 sw   Y  ej7ddhZyejoddhZzej{dddddd e+e1e3ge- e2 e4 e5e8e:g e6 e9 e; e< e= eB eC eD Z|dd Z}dd Z~eg ZedZdd Zdd ZddÄ Zee+jee+e-ddj ee1jee1e1ddj ee3jee3e4ddj e-e2e4fD ]ZeD ]Zeej qTqPddń Zee5jee5e6ddj ee8jee8e9ddj ee:jee:e;ddj ee*jge}e)e|ddj e6e9 e; e< eB D ]Zeej eej qeDD ]Zeej eej qe=eC D ]Zeej qe$jgdddddd ddȄ Zee#jgeegee)ge| ddj ddʄ ZeVjgdd deVddjeeeSeTeUheWeVgdd W d   n	1 sw   Y  W d   n	1 sw   Y  edkr.e  dS dS )    N)Iterable)document_fn)2   d      i,    i  iX  i  i   i  i  )ZxxsZxssmmdZlgZxlZxxl   c                 C   s6   t t D ]}|d | kr|d   S qtd|  d)Nnamedocz	Variable z" not found in theme documentation.)docs_theme_coredocs_theme_vars
ValueError)var
parameters r   ID:\Projects\ConvertPro\env\Lib\site-packages\gradio/themes/builder_app.py
get_docstr   s
   r   c                  C   s   t tjjj} g }d d g g f\}}}}|  D ]A}| }|dr% n5|drD|d ur6|	|||f |dd  
d\}}g }qd|v rY|
dd }|	| |	| q|	|||f ||fS )N)z#    z: =r   )inspect	getsourcegrthemesBaseset
splitlinesstrip
startswithappendsplit)sourcegroupsgroupdesc	variablesflat_variablesliner   r   r   r   get_doc_theme_var_groups    s&   



r*   a  
.gradio-container {
    overflow: visible !important;
    max-width: none !important;
}
#controls {
    max-height: 100vh;
    flex-wrap: unset;
    overflow-y: scroll;
    position: sticky;
    top: 0;
}
#controls::-webkit-scrollbar {
  -webkit-appearance: none;
  width: 7px;
}

#controls::-webkit-scrollbar-thumb {
  border-radius: 4px;
  background-color: rgba(0, 0, 0, .5);
  box-shadow: 0 0 1px rgba(255, 255, 255, .5);
}
zGradio Theme Builder)themecsstitleZcontrolsr   )scaleelem_id	min_widthZUndor   sizez	Dark Modeprimary)variantr2   zSource Themez
                    Select a base theme below you would like to build off of. Note: when you click 'Load Theme', all variable values in other tabs will be overwritten!
                    c                 C      g | ]}|j qS r   __name__.0r+   r   r   r   
<listcomp>a       r:   r   F)value
show_labelz
Load Theme
load_theme)r/   zCore Colorsa  Set the three hues of the theme: `primary_hue`, `secondary_hue`, and `neutral_hue`.
                        Each of these is a palette ranging from 50 to 950 in brightness. Pick a preset palette - optionally, open the accordion to overwrite specific values.
                        Note that these variables do not affect elements directly, but are referenced by other variables with asterisks, such as `*primary_200` or `*neutral_950`.c                 C   r5   r   r   r9   colorr   r   r   r:   m   r;   zPrimary Hue)labelzPrimary Hue Palette)rB   openZprimary_c                 C   r5   r   r?   r@   r   r   r   r:   y   r;   zSecondary HuezSecondary Hue PaletteZ
secondary_c                 C   r5   r   r?   r@   r   r   r   r:      r;   zNeutral huezNeutral Hue PaletteZneutral_zCore Sizinga  Set the sizing of the theme via: `text_size`, `spacing_size`, and `radius_size`.
                        Each of these is set to a collection of sizes ranging from `xxs` to `xxl`. Pick a preset size collection - optionally, open the accordion to overwrite specific values.
                        Note that these variables do not affect elements directly, but are referenced by other variables with asterisks, such as `*spacing_xl` or `*text_sm`.
                        c                 C      g | ]}|j d r|j qS )text_r   r    r9   r2   r   r   r   r:      s    z	Text SizezText Size RangerE   c                 C   rD   )spacing_rF   rG   r   r   r   r:          
zSpacing SizezSpacing Size RangerH   c                 C   rD   )radius_rF   rG   r   r   r   r:      rI   zRadius SizezRadius Size RangerJ   z
Core Fontsa	  Set the main `font` and the monospace `font_mono` here.
                        Set up to 4 values for each (fallbacks in case a font is not available).
                        Check "Google Font" if font should be loaded from Google Fonts.
                        z### Main Font   zFont zGoogle Fontz### Monospace Fontc                 C      g | ]}d | qS )z	*primary_r   r9   ir   r   r   r:          c                 C   rL   )z*secondary_r   rM   r   r   r   r:      rO   c                 C   rL   )z	*neutral_r   rM   r   r   r   r:      rO   c                 C   rL   )z*text_r   rM   r   r   r   r:      rO   c                 C   rL   )z*radius_r   rM   r   r   r   r:      rO   c                 C   rL   z	*spacing_r   rM   r   r   r   r:      rO   c                 C   rL   rP   r   rM   r   r   r   r:      rO   )100Z200Z300Z400500Z600Z700Z800none)	fillrA   	text_sizeZradiuspaddinggapweightZshadowZborder_width_dark*rT   rA   z^
You can set these to one of the dropdown values, or clear the dropdown to set a custom value.T)rB   infochoicesZallow_custom_value   Zapp)r.   r/   panel)r4   ai  
                    # Theme Builder
                    Welcome to the theme builder. The left panel is where you create the theme. The different aspects of the theme are broken down into different tabs. Here's how to navigate them:
                    1. First, set the "Source Theme". This will set the default values that you can override.
                    2. Set the "Core Colors", "Core Sizing" and "Core Fonts". These are the core variables that are used to build the rest of the theme.
                    3. The rest of the tabs set specific CSS theme variables. These control finer aspects of the UI. Within these theme variables, you can reference the core variables and other theme variables using the variable name preceded by an asterisk, e.g. `*primary_50` or `*body_text_color`. Clear the dropdown to set a custom value.
                    4. Once you have finished your theme, click on "View Code" below to see how you can integrate the theme into your app. You can also click on "Upload to Hub" to upload your theme to the Hugging Face Hub, where others can download and use your theme.
                    z	View Code)rC   python)languageUpload to HubzYou can save your theme on the Hugging Face Hub. HF API write token can be found [here](https://huggingface.co/settings/tokens).z
Theme NamezHugging Face Write TokenVersionz,Leave blank to automatically update version.)rB   placeholder)visiblez3Below this panel is a dummy app to demo your theme.Namez8Full name, including middle name. No special characters.zJohn Doe)rB   r[   rc   r<   interactivezSlider 1zSlider 2)ABCzCheckbox Group)r4   r.   z
## Panel 1RadiozLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.)rB   r[   )Option 1Option 2zOption 3)r=   )Option AOption BOption Crm   Dropdown)Zmultiselectr<   rB   rf   Gor   Ghttps://gradio-static-files.s3.us-west-2.amazonaws.com/header-image.jpgImagei@  )rB   heightzPrimary Button)rB   r4   ZClearzSecondary ButtonZ	secondaryc                  G   s   t d dS )N   rr   timesleep)argsr   r   r   gon     
rz   api_namec                   C   s   t d d S )N皙?rv   r   r   r   r   cleary  r{   r   zButton 1ZStopzStop Buttonstop)rB   r4   r2   rg   rk   rn   rh   rl   ro   Examples)ZexamplesZinputsrB   )r
   r   ru   )rK      r]   )      	   	Dataframe)r<   rB   a)testZtest2)r   bcJSONgffffff?r~   g?)catdogfish)r<   z@https://gradio-static-files.s3.us-west-2.amazonaws.com/world.mp4))z?https://gradio-static-files.s3.us-west-2.amazonaws.com/lion.jpgZlion)z?https://gradio-static-files.s3.us-west-2.amazonaws.com/logo.pngZlogo)z@https://gradio-static-files.s3.us-west-2.amazonaws.com/tower.jpgZtowerZ200px)rt   columns)r.   )HelloZHiChatbotzAdd messagesc                 c   s    t d ddggV  d S )Nr   How are you?
I am good.rv   historyr   r   r   chat  s   
r   c                 C   s   | ddgg t dpg  S )Nr   r   r   rv   r   r   r   r   <lambda>  s
    r   zAdvanced Settingsr   zChatbot control 1zChatbot control 2zChatbot control 3a  () => {
                document.head.innerHTML += "<style id='theme_css'></style>";
                let evt_listener = window.setTimeout(
                    () => {
                        load_theme_btn = document.querySelector('#load_theme');
                        if (load_theme_btn) {
                            load_theme_btn.click();
                            window.clearTimeout(evt_listener);
                        }
                    },
                    100
                );
            }Z_jsr}   c                    st   fddt D d }t|jj}|d j}|d j}|d j}|d j}|d j}|d	 j}| }|jd d
 }	|jd d
 }
dd |	D }dd |
D }dd }g }tD ]}t	||}|d u rp|
drpt	||d d }|| qW|j|j|jg|  |  |  |j|j|jg |  |  |  |dd |	D  || |dd |
D  || | S )Nc                       g | ]	}|j  kr|qS r   r6   r8   
theme_namer   r   r:         zload_theme.<locals>.<listcomp>r   primary_huesecondary_hueneutral_huerU   spacing_sizeradius_sizerK   c                 S      g | ]	}t |tjjqS r   
isinstancer   r   
GoogleFontr9   fr   r   r   r:   	  r   c                 S   r   r   r   r   r   r   r   r:   
  s    c                 S   s   | d gdt |    S )NrK   )len)xr   r   r   pad_to_4  s   zload_theme.<locals>.pad_to_4rY   c                 S   r5   r   r?   r   r   r   r   r:   !  r;   c                 S   r5   r   r?   r   r   r   r   r:   #  r;   )r   r   	signature__init__r   defaultZ_fontZ
_font_monor(   getattrendswithr!   r   expand)r   r+   r   r   r   r   rU   r   r   font	font_monofont_is_googleZfont_mono_is_googler   Z
var_outputvariableZ	theme_valr   r   r   r>     s`   






	
c           *         s   } fddt D d   t jj}|d j}|d j}|d j}	|d j}
|d j}|d	 j}|d
 j}t|ts@|gn|}dd |D }|d j}t|tsV|gn|}dd |D }i }i }g d}t||||	|
||gt	j j
t	j j
t	j j
t	j jt	j jt	j jg|D ]a\}}}|jkr||< fdd|jD d }i }d}t|D ]5}|dv s|drq|dd d |t	j j
kr|dd  n| }t||||< t|||| krd}q|r||f||< qi }dd |D }dd |D }|d d }|d d }||d
f||dffD ]%\}}}t|t|ks)tdd t||D r2dd |D ||< qd}d}t|t| dkr|D ];} | |v rm||  \}!}"|d|  d|!j dd d!d |" D  d"7 }qE| |v r|d|  d#||   d$7 }qEd}#t|dkrdd%d | D }#i }$tD ]-}%t |%}&t||%}'|&d u r|%d&rt |%d d' }&|&|'krt||%|$|%< qd}d}(t|$dkrd(d)| d d*d |$ D  d+}(d,| d|s|#r|nd | |# d-|( d.	})|)S )/Nc                    r   r   r6   r8   )
base_themer   r   r:   ,  r   z'generate_theme_code.<locals>.<listcomp>r   r   r   r   rU   r   r   r   c                 S   *   g | ]}t |tjjstj|n|qS r   r   r   r   ZFontr   r   r   r   r:   9      r   c                 S   r   r   r   r   r   r   r   r:   A  r   )r   r   r   rU   r   r   c                    r   r   r?   )r9   obj)final_valuer   r   r:   f  s    F)allr   r   _r
   Tc                 S      g | ]}|d  r|qS r   r   r9   r   r   r   r   r:   }      c                 S   r   r   r   r   r   r   r   r:   ~  r   rK   c                 s   s8    | ]\}}|j |d  kpt|tjj|d kV  qdS )r   r
   N)r   r   r   r   r   )r9   Z	base_fontZ
theme_fontr   r   r   	<genexpr>  s    
z&generate_theme_code.<locals>.<genexpr>c                 S   s,   g | ]\}}|rd | dnd| dqS )zgr.themes.GoogleFont('z')'r   )r9   Z	font_nameZis_google_fontr   r   r   r:     s    

     z=gr.themes.(, c                 s   s$    | ]\}}| d | dV  qdS )=""Nr   r9   kvr   r   r   r     s   " z),
r   z",
c                 S   s(   g | ]\}}d | dd | dqS )r   z=[r   z],
)join)r9   font_set_nameZfontsr   r   r   r:     s    rY   r   z
.set(
    ,c                 S   s    g | ]\}}| d | dqS )z='r   r   r   r   r   r   r:     s     z
)z(
import gradio as gr

theme = gr.themes.r   z.

with gr.Blocks(theme=theme) as demo:
    ...)r   r   r   r   r   r   r   r   zipr   ColorSizer   r   dirr    r"   r   r   anyr7   r   itemsr(   r   )*r   Zfinal_themeZcore_variablesfinal_main_fontsfinal_mono_fontsZbase_theme_namer   r   r   r   rU   r   r   r   r   Z
core_diffsZspecific_core_diffsZcore_var_namesZ
value_nameZ
base_valueZsource_classZ
source_objZfinal_attr_valuesdiffattrZfinal_theme_attrZ
font_diffsZbase_font_setZtheme_font_setr   newlineZcore_diffs_codevar_nameclsvalsZfont_diffs_codeZ	var_diffsr   Zbase_theme_valZfinal_theme_valZvars_diff_codeoutputr   )r   r   r   generate_theme_code(  s  







	




6



r   c           $      G   s  |dd \}}}|ddt t  }|dt t ddt t   }|ddt t  ddt t   }|ddt t  ddt t   \}	}
}|ddt t  ddt t  t t  }|ddt t  t t ddt t  dt t   }|ddt t  dt t  ddt t  dt t   }|ddt t  dt t  ddt t  dt t  d  }|ddt t  dt t  d ddt t  dt t  d  }|ddt t  dt t  d ddt t  dt t  d  }|ddt t  dt t  d ddt t  dt t  d  }|ddt t  dt t  d d  }tjj| }tjj| }tjj| }tjj| }tjj| }tjj| }g }t }tt	|D ]\}}d	|v rp|
| qbt|}t||D ]\}}|sq{|rtjj||d
}|| q{g } t||D ]\}!}|!sq|rtjj|!|d
}!| |! qtjj|||||||| d}"|"jdi ttt	| ||f}#t | dkst| d t|#kr| |# | |" |"jt||"||||	|
|ftt||tt|||"fS )Nr   ru   r   r]   rK   r         rX   )weights)r   r   r   rU   r   r   r   r   r   )r   palette_range
size_ranger   r   r   r   r   r   r(   addsortedr   r!   r   dictstrZ_get_theme_cssZ_stylesheetsr   list)$r   r   ry   r   r   r   primary_huessecondary_huesneutral_huesrU   r   r   
text_sizesspacing_sizesradius_sizes
main_fontsmain_is_google
mono_fontsmono_is_googleZremaining_argsZfinal_primary_colorZfinal_secondary_colorZfinal_neutral_colorZfinal_text_sizeZfinal_spacing_sizeZfinal_radius_sizer   Zfont_weightsr   valZ	main_fontZ	is_googler   Z	mono_fontr+   Znew_stepr   r   r   render_variables  sV   $

















	



	



	"

$
r   c                 C   s6   | t ttgt tttttgddjd ttgd dddS )NFr|   aS  (css, fonts) => {
                    document.getElementById('theme_css').innerHTML = css;
                    let existing_font_links = document.querySelectorAll('link[rel="stylesheet"][href^="https://fonts.googleapis.com/css"]');
                    existing_font_links.forEach(link => {
                        if (fonts.includes(link.href)) {
                            fonts = fonts.filter(font => font != link.href);
                        } else {
                            link.remove();
                        }
                    });
                    fonts.forEach(font => {
                        let link = document.createElement('link');
                        link.rel = 'stylesheet';
                        link.href = font;
                        document.head.appendChild(link);
                    });
                }r   )	r   r   base_theme_dropdowntheme_inputs
secret_csssecret_fontoutput_codecurrent_themethen)Zevt_listenerr   r   r   attach_rerenderH  s   
r   c                    (   fddt D d   fddtD S )Nc                    r   r   r?   r@   
color_namer   r   r:   g  r   zload_color.<locals>.<listcomp>r   c                    s   g | ]
}t  d | qS )r   r   rM   )rA   r   r   r:   h  s    )colorsr   r  r   )rA   r  r   
load_colorf     r  c                    r   )Nc                    r   r   r?   rG   	size_namer   r   r:   ~  r   zload_size.<locals>.<listcomp>r   c                    s   g | ]}t  |qS r   r  rM   r1   r   r   r:     rO   )sizesr   r  r   )r2   r  r   	load_size}  r  r
  a  () => {
            if (document.querySelectorAll('.dark').length) {
                document.querySelectorAll('.dark').forEach(el => el.classList.remove('dark'));
            } else {
                document.querySelector('body').classList.add('dark');
            }
        }c                 C   s@   t | dkrtt iS |   |  }| |d gt|d  S )Nr
   r   )r   r   r   skippopr   )Zhistory_varoldr   r   r   undo  s
   r  c              
   C   s   z3| t  j| t | t pd | t | t d}d|ddd  }tjj	d| d| dddd	fW S  t
yR } ztjj	d
| ddd	fW  Y d }~S d }~ww )N)	repo_nameversionZhf_tokenr   /zTheme uploaded [here!](z )! Load it as `gr.Blocks(theme='z')`T)r<   rd   ra   zError: )r   Zpush_to_hubr   theme_versiontheme_hf_tokenr   r"   r   Markdownupdate	Exception)dataZ	theme_urlZ
space_nameer   r   r   upload_to_hub  s.   
r  c                   C   s   dS )NzUploading...r   r   r   r   r   r     s    __main__)r   rw   typingr   Zgradio_client.documentationr   Zgradior   r   r   ZDefaultZSoftZ
MonochromeZGlassr   r   r  r   r	  r   r   r   r   r   r   r   r*   Zvariable_groupsr(   r,   ZBlocksdemoRowColumnZButtonZundo_btnZdark_mode_btnZTabsZTabItemr  rp   r   Zload_theme_btnr   Z	Accordionr   rN   r!   ZColorPickerr   r   r   r   rU   r   ZTextboxr   r   r   r   r   r   ranger   ZCheckboxr   r   r   Ztheme_var_inputZcore_color_suggestionsZvariable_suggestionsr   r   Z
style_typer   r%   r&   r'   ZsuggestionsremoveZdropdownZCoder   r   r  r  Zupload_to_hub_btnZtheme_upload_statusr   ZSliderZslider1Zslider2ZCheckboxGrouprj   radioZdropZdrop_2checkrs   ZimgZgo_btnZ	clear_btnrz   Zclickr   Zbtn1ZUploadButtonZbtn2Zstop_btnr   r   r   LabelFileZVideoZGalleryr   ZchatbotZchat_btnr   Numberr   r   loadr   r>   r   Stater   r   r   r   r  selectr   Zhue_sethueZblurr
  ZchangeZ	theme_boxsubmitZcheckboxr  r  r7   Zlaunchr   r   r   r   <module>   s2   



		*		6












  N







9

 




  2	
. 

 


	              
"