o
    f~#g                     @   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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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( D e)d" e*d ej+dd eD 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 Z0eD ]Z1e02ej3d*e1 d' qW d   n	1 sw   Y  ej+d+d eD d,d'Z4ej/d-dd) g Z5eD ]Z1e52ej3d.e1 d' q<W d   n	1 sWw   Y  ej+d/d eD d0d'Z6ej/d1dd) g Z7eD ]Z1e72ej3d2e1 d' qtW d   n	1 sw   Y  W d   n	1 sw   Y  e)d3 e*d4 ej+d5d eD d6d'Z8ej/d7dd) g Z9eD ]Z1e92ej:d8e1 d' qW d   n	1 sw   Y  ej+d9d eD d:d'Z;ej/d;dd) g Z<eD ]Z1e<2ej:d<e1 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 ]Z1e>2ej:d@e1 d' q7W d   n	1 sRw   Y  W d   n	1 sbw   Y  e)dA e*dB e*dC g g Z?Z@eAdDD ]3Z1e# # ej:dEe1d  d'ZBejCdFd'ZDe?2eB e@2eD W d   n	1 sw   Y  qg g ZEZFe*dG eAdDD ]3Z1e# # ej:dEe1d  d'ZBejCdFd'ZDeE2eB eF2eD W d   n	1 sw   Y  qW d   n	1 sw   Y  g ZGdHd eD dId eD  dJd eD  ZHeHdd eHdd dKd eD dLd eD dMd eD dNd eD g dOdPgg dQ	ZIeD ]!ZJeJKdRrTqJeID ]ZLeLeJv rheIeL 2dSeJ   nqVqJeIdT eIdU eMeHd  eIdU eIdT eMeHd  eIdT< eIdU< eD ]^\ZNZOZPe)eNJ e*eOdV  ePD ]8ZJg ZQeID ] ZLeLeJv reIeL dd ZQdSeJ eQv reQRdSeJ   nqej+eJeeJeQdWdXZSeG2eS qW d   n	1 sw   Y  qW d   n	1 sw   Y  W d   n	1 s	w   Y  ej$dYdZd[ ej$d\d] e*d^ ej/d_dd` ejTdadbZUW d   n	1 s<w   Y  ej/dcdd`@ e*dd e#  ej:ded'ZVej:dfd'ZWej:dgdhdiZXW d   n	1 sqw   Y  e%dcZYej*ddjZZW d   n	1 sw   Y  e*dk W d   n	1 sw   Y  ej:dldmdndndWdoZ[e\dpdq drds e#  ej]dtd'Z^ej]dud'Z_W d   n	1 sw   Y  ej`g dvdwd' e#  ej$d\ddx3 e*dy ejag dvdzd{d|Zbej+g d}dd~Zcej+g ddWdgddWdZdejCdd'ZeW d   n	1 s&w   Y  ej$d\ddxz ejfddddZge# 3 ej%ddd]Zhej%ddd]Zidd Zjehjkejebecedeee[gegdd dd Zleikeldeg W d   n	1 svw   Y  e#  ej%dddZmejnddZoej%ddddZpW d   n	1 sw   Y  W d   n	1 sw   Y  W d   n	1 sw   Y  ejqdddgdWgddddgdggebecedeegdd e# 6 ejrg dg dg dgdd ejsdddg ddddd ejtddddd eu  W d   n	1 sw   Y  e#  e3  evd ejwg dddd W d   n	1 sDw   Y  e#  ej$dd' ejxdgdd'ZyejzdWddZ{e%dZ|e|jkddq eyeydd W d   n	1 sw   Y  ej$dd5 e/d e*d ej}dd' ej}dd' ej}dd' 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j:ddjZ~ejsddjZe"jdddddd e.e4e6ge0 e5 e7 e8e;e=g e9 e< e> e? e@ eE eF eG Zdd! Zdd Zeg ZedZdd Zdd Zdd Zee.jee.e0ddj ee4jee4e5ddj ee6jee6e7ddj e0e5e7fD ]ZeD ]Zeej qiqeddĄ Zee8jee8e9ddj ee;jee;e<ddj ee=jee=e>ddj ee-jkee,eddj e9e< e> e? eE D ]Zeej eej qeGD ]Zeej eej qe@eF D ]Zeej qe'jkdddddd ddǄ Zee&jkeegee,ge ddj ddɄ ZeYjkddq deYddjeeeVeWeXheZeYgdd W d   n	1 s#w   Y  W d   n	1 s3w   Y  edkrCe"  dS dS )    N)Iterable)document_fn)2   d      i,    i  iX  i  i   i  i  )xxsxssmmdlgxl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   ~/var/www/static.ux5.de/https/Moving-Object-Detection-with-OpenCV/env/lib/python3.10/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 Builderz<style id='theme_css'></style>)themecsstitleheadcontrolsr   )scaleelem_id	min_widthUndor
   sizez	Dark Modeprimary)variantr:   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__.0r0   r   r   r   
<listcomp>e       rB   r!   FTheme)value
show_labellabelz
Load Theme
load_theme)r6   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   r=   r   r   rA   colorr   r   r   rB   r   rC   zPrimary Hue)rG   zPrimary Hue Palette)rG   openprimary_c                 C   r=   r   rI   rJ   r   r   r   rB   ~   rC   zSecondary HuezSecondary Hue Palette
secondary_c                 C   r=   r   rI   rJ   r   r   r   rB      rC   zNeutral huezNeutral Hue Palette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%   rA   r:   r   r   r   rB      s    z	Text SizezText Size RangerQ   c                 C   rP   )spacing_rR   rS   r   r   r   rB          
zSpacing SizezSpacing Size RangerT   c                 C   rP   )radius_rR   rS   r   r   r   rB      rU   zRadius SizezRadius Size RangerV   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   rA   ir   r   r   rB          c                 C   rX   )z*secondary_r   rY   r   r   r   rB      r[   c                 C   rX   )z	*neutral_r   rY   r   r   r   rB      r[   c                 C   rX   )z*text_r   rY   r   r   r   rB      r[   c                 C   rX   )z*radius_r   rY   r   r   r   rB      r[   c                 C   rX   z	*spacing_r   rY   r   r   r   rB      r[   c                 C   rX   r\   r   rY   r   r   r   rB      r[   )100200300400500600700800none)	fillrK   	text_sizeradiuspaddinggapweightshadowborder_width_dark*rf   rK   z^
You can set these to one of the dropdown values, or clear the dropdown to set a custom value.T)rG   infochoicesallow_custom_value   app)r5   r6   panel)r<   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)rL   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.)rG   placeholder)visiblez3Below this panel is a dummy app to demo your theme.Namez8Full name, including middle name. No special characters.zJohn Doe)rG   rp   rz   rE   interactivec                 C   s   | S )Nr   xr   r   r   <lambda>M      r   numbertextboxzSlider 1zSlider 2)ABCzCheckbox Group)r<   r5   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.)rG   rp   )Option 1Option 2zOption 3)rF   )Option AOption BOption Cr   Dropdown)multiselectrE   rG   r}   Gor   Ghttps://gradio-static-files.s3.us-west-2.amazonaws.com/header-image.jpgImagei@  )rG   heightClear	secondaryc                  G   s   t d dS )N   r   timesleep)_argsr   r   r   goq  s   
r   show_apic                   C   s   t d d S )N皙?r   r   r   r   r   clear|  s   r   zButton 1Stopstopr   r   r   r   r   r   Examples)examplesinputsrG   )r   r   r   )rW      rs   )      	   	Dataframe)rE   rG   a)testtest2)r   bcJSONgffffff?r   g?)catdogfish)rE   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.jpglion)z?https://gradio-static-files.s3.us-west-2.amazonaws.com/logo.pnglogo)z@https://gradio-static-files.s3.us-west-2.amazonaws.com/tower.jpgtower200px)r   columns)r5   )HelloHiChatbot)r}   rF   zAdd messagesc                 C   s   | ddgg t dpg  S )NzHow are you?z
I am good.r   r   )historyr   r   r   r     s
    zAdvanced Settingsr   zChatbot control 1zChatbot control 2zChatbot control 3a  () => {
                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
                );
            }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   r>   r@   
theme_namer   r   rB         zload_theme.<locals>.<listcomp>r   primary_huesecondary_hueneutral_huerg   spacing_sizeradius_sizerW   c                 S      g | ]	}t |tjjqS r   
isinstancer   r    
GoogleFontrA   fr   r   r   rB     r   c                 S   r   r   r   r   r   r   r   rB     s    c                 S   s   | d gdt |    S )NrW   )lenr~   r   r   r   pad_to_4  s   zload_theme.<locals>.pad_to_4rn   c                 S   r=   r   rI   r   r   r   r   rB     rC   c                 S   r=   r   rI   r   r   r   r   rB   !  rC   )r    r   	signature__init__r   default_font
_font_monor-   getattrendswithr&   r   expand)r   r0   r   r   r   r   rg   r   r   font	font_monofont_is_googlefont_mono_is_googler   
var_outputvariable	theme_valr   r   r   rH     s`   






	
c           0         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dD ]\}}}|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i }| D ].\}}|drd|dd  }|||< q|dr|dd }|||< q|||< q||f||< qi }dd |D }dd |D }|d d }|d d }||d
f||dffD ]'\} }!}"t| t|!ksctdd t| |!ddD rldd |!D ||"< qFd }#d!}$t|t| dkr|D ]J}%|%|v r||% \}&}'|$d"|% d#|&j d$d%d&d |' D  d'7 }$q|%|v r||% }(|%d(r|(dd }(|$d"|% d)|( d*7 }$qd!})t|dkrd!d+d | D })i }*tD ]-}+t |+},t||+}-|,d u r|+d,rt |+d d- },|,|-krt||+|*|+< qd }#d!}.t|*dkr0d.d/|# d" d0d |* D  d1}.d2| d$|$s:|)r<|#nd! |$ |) d3|. d4	}/|/S )5Nc                    r   r   r>   r@   )
base_themer   r   rB   *  r   z'generate_theme_code.<locals>.<listcomp>r   r   r   r   rg   r   r   r   c                 S   *   g | ]}t |tjjstj|n|qS r   r   r   r    Fontr   r   r   r   rB   7      r   c                 S   r   r   r   r   r   r   r   rB   ?  r   )r   r   r   rg   r   r   Fstrictc                    r   r   rI   )rA   obj)final_valuer   r   rB   e  s    )allr   r   _r   T)rM   rN   rO   r   )rQ   rT   rV   c                 S      g | ]}|d  r|qS r   r   rA   r   r   r   r   rB         c                 S   r   r   r   r   r   r   r   rB     r   rW   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   )rA   	base_font
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   )rA   	font_nameis_google_fontr   r   r   rB     s    

     z=gr.themes.(, c                 s   s$    | ]\}}| d | dV  qdS )=""Nr   rA   kvr   r   r   r     s   " z),
_sizer   z",
c                 S   s(   g | ]\}}d | dd | dqS )r   z=[r   z],
)join)rA   font_set_namefontsr   r   r   rB     s    rn   r   z
.set(
    ,c                 S   s    g | ]\}}| d | dqS )z='r   r   r   r   r   r   rB     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   itemsr   anyr?   r   r   r-   )0r   final_themecore_variablesfinal_main_fontsfinal_mono_fontsbase_theme_namer   r   r   r   rg   r   r   r   r   
core_diffsspecific_core_diffscore_var_names
value_name
base_valuesource_class
source_objfinal_attr_valuesdiffattrfinal_theme_attrnew_final_attr_valueskeyval	color_keysize_key
font_diffsbase_font_settheme_font_setr   newlinecore_diffs_codevar_nameclsvalsvar_valfont_diffs_code	var_diffsr   base_theme_valfinal_theme_valvars_diff_codeoutputr   )r   r   r   generate_theme_code&  s$  







	







6



r-  c           $      G   s4  |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
D ]\}}d|v rr|
| qdt|}t||d	d
D ]\}}|sq|rtjj||d}|| qg } t||d	d
D ]\}!}|!sq|rtjj|!|d}!| |! qtjj|||||||| d}"|"jdi ttt	|d	d
 ||f}#t | dkst| d t|#kr| |# | |" |"jt||"||||	|
|ftt||d	d
tt||d	d
|"fS )Nr   r   r   rs   rW   r         Fr   rk   )weights)r   r   r   rg   r   r   r   r   r   r   )r   palette_range
size_ranger   r    r  r  r"   r  r-   addsortedr   r&   r!   dictstr_get_theme_css_stylesheetsr-  list)$r   r   argsr   r   r   primary_huessecondary_huesneutral_huesrg   r   r   
text_sizesspacing_sizesradius_sizes
main_fontsmain_is_google
mono_fontsmono_is_googleremaining_argsfinal_primary_colorfinal_secondary_colorfinal_neutral_colorfinal_text_sizefinal_spacing_sizefinal_radius_sizer  font_weightsr  r  	main_font	is_googler  	mono_fontr0   new_stepr   r   r   render_variables  s    $







 

 

 

"

$
rQ  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   )	rQ  r   base_theme_dropdowntheme_inputs
secret_csssecret_fontoutput_codecurrent_themethen)evt_listenerr   r   r   attach_rerenderH  s   
rZ  c                    (   fddt D d   fddtD S )Nc                    r   r   rI   rJ   
color_namer   r   rB   g  r   zload_color.<locals>.<listcomp>r   c                    s   g | ]
}t  d | qS )r   r   rY   )rK   r   r   rB   h  s    )colorsr1  r\  r   )rK   r]  r   
load_colorf     r`  c                    r[  )Nc                    r   r   rI   rS   	size_namer   r   rB   ~  r   zload_size.<locals>.<listcomp>r   c                    s   g | ]}t  |qS r   r^  rY   r9   r   r   rB     r[   )sizesr2  rb  r   )r:   rc  r   	load_size}  ra  re  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popr9  )history_varoldr   r   r   undo  s
   rj  c              
   C   s   z2| t  j| t | t pd | t | t d}d|ddd  }tjd| d| dddd	fW S  t	yP } ztjd
| ddd	fW  Y d }~S d }~ww )N)	repo_nameversionhf_tokenr   /zTheme uploaded [here!](z )! Load it as `gr.Blocks(theme='z')`T)rE   r{   rx   zError: )
rW  push_to_hubr   theme_versiontheme_hf_tokenr   r'   r   Markdown	Exception)data	theme_url
space_nameer   r   r   upload_to_hub  s.   
ry  c                   C   s   dS )NzUploading...r   r   r   r   r   r     r   __main__)r   r   collections.abcr   gradio_client.documentationr   gradior   r    r!   DefaultSoft
MonochromeGlassOriginCitrusOceanr  r   r_  r  rd  r1  r2  r   r   r"   r   r   r/   variable_groupsr-   r1   BlocksdemoRowColumnButtonundo_btndark_mode_btnTabsTabItemrs  r   rR  load_theme_btnr   	Accordionr;  rZ   r&   ColorPickerr   r<  r   r=  rg   r>  Textboxr   r?  r   r@  rA  rB  ranger   Checkboxr   rC  rD  theme_var_inputcore_color_suggestionsvariable_suggestionsr   r   
style_typer   r*   r+   r,   suggestionsremovedropdownCoderV  r   rr  rq  upload_to_hub_btntheme_upload_statusr   	InterfaceSliderslider1slider2CheckboxGroupr   radiodropdrop_2checkr   imggo_btn	clear_btnr   clickr   btn1UploadButtonbtn2stop_btnr   r   r   LabelFileVideoGalleryr   chatbotMultimodalTextbox
multimodalchat_btnNumberrT  rU  loadrS  rH   r-  Stater   rW  rQ  rZ  r`  selectrX  hue_sethueblurre  change	theme_boxsubmitcheckboxrj  ry  r?   launchr   r   r   r   <module>   s4   




		*		6












  O







2

 




  ,	
. 
,
t


	              
