
    ;3h;                       d 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Zddlm	Z	m
Z
 ddl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 dd	lmZ dd
lmZmZmZmZmZmZm Z m!Z! ddl"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- ddl.m/Z/ ddl0m1Z1m2Z2m3Z3m4Z4m5Z5 ddl6m7Z7m8Z8 ddl9m:Z; erddl<m=Z= ddl>m?Z?  eddddd       G d de             Z@ e        G d de             ZAdd dZBy)!zk
This file defines two useful high-level abstractions to build Gradio apps: Interface and TabbedInterface.
    )annotationsN)CallableSequence)Path)TYPE_CHECKINGAnyLiteral)document)Examplesutils
wasm_utils)Blocks)ButtonClearButton	ComponentDeepLinkButtonDuplicateButtonMarkdownStateget_component_instance)InterfaceTypes)
DependencyEventson)RenderError)	CSVLoggerFlaggingCallback
FlagMethod)I18nData)	AccordionColumnRowTabTabs)load_from_js_pipelineload_from_pipeline)
ThemeClass)DiffusionPipeline)Pipelinelaunchloadfrom_pipeline	integratequeuec            '          e Zd ZU dZ ej
                         Zded<   ed d       Z	e	 	 	 	 d!d       Z
	 d"dddddddddddd	dddd
dddddddddddddddddddddd%	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d# fdZd$dZd%dZ	 	 d&dZ	 	 	 	 d'dZd Z	 	 	 	 	 	 d( fdZ	 	 	 	 d)dZ	 	 	 	 	 	 d*dZd Zd Zd Z xZS )+	Interfaceaq  
    Interface is Gradio's main high-level class, and allows you to create a web-based GUI / demo
    around a machine learning model (or any Python function) in a few lines of code.
    You must specify three parameters: (1) the function to create a GUI for (2) the desired input components and
    (3) the desired output components. Additional parameters can be used to control the appearance
    and behavior of the demo.

    Example:
        import gradio as gr

        def image_classifier(inp):
            return {'cat': 0.3, 'dog': 0.7}

        demo = gr.Interface(fn=image_classifier, inputs="image", outputs="label")
        demo.launch()
    Demos: hello_world, hello_world_2, hello_world_3
    Guides: quickstart, key-features, sharing-your-app, interface-state, reactive-interfaces, advanced-interface-features, setting-up-a-gradio-demo-for-maximum-performance
    zweakref.WeakSet	instancesc                4    t        t        j                        S )z9
        :return: list of all current instances.
        )listr0   r1   )clss    P/var/www/html/audio-gradio/venv/lib/python3.12/site-packages/gradio/interface.pyget_instanceszInterface.get_instancesD   s    
 I''((    c                |    t         j                  rt        |      }nt        |      }t	        |fi |} | di |}|S )aB  
        Class method that constructs an Interface from a Hugging Face transformers.Pipeline or diffusers.DiffusionPipeline object.
        The input and output components are automatically determined from the pipeline.
        Parameters:
            pipeline: the pipeline object to use.
        Returns:
            a Gradio Interface object from the given Pipeline
        Example:
            import gradio as gr
            from transformers import pipeline
            pipe = pipeline("image-classification")
            gr.Interface.from_pipeline(pipe).launch()
         )r   IS_WASMr%   r&   dict)r4   pipelinekwargsinterface_info	interfaces        r5   r,   zInterface.from_pipelineK   sA    " 28<N/9Nn//M&M	r7   N
   Fz.gradio/flagged   predictdefaultSubmitStopClearfull   g      ?)%cache_examples
cache_modeexamples_per_pageexample_labelslivetitledescriptionarticlethemeflagging_modeflagging_optionsflagging_dirflagging_callbackanalytics_enabledbatchmax_batch_sizeapi_name	_api_modeallow_duplicationconcurrency_limitcss	css_pathsjshead
head_pathsadditional_inputsadditional_inputs_accordion
submit_btnstop_btn	clear_btndelete_cacheshow_progress
fill_widthallow_flagging
time_limitstream_every	deep_linkc       %        ^   t        E|   d7|d|
xs d|||||||#|%d|* t        |)t              rt	        |)dd      })n|)du rt	        dd      })t        j                         r|)t	        dd      })t        j                  s|)du rd})|)| _	        |'| _
        |(| _        || _        t        j                  | _        ||g k(  r||g k(  rt!        d	      ||g k(  rg }t        j"                  | _        n||g k(  rg }t        j$                  | _        |g | _        n3t        |t(              s|g}|D +cg c]  }+t+        |+d
       c}+| _        t        |t(        t,        f      st/        d|       t        |t(        t,        f      st/        d|       t        |t        t,        f      r|g}t        |t        t,        f      r|g}|| _        || _        |D +cg c]  }+t+        |+d
       c}+| _        | j4                  | j&                  z   | _        |D ,cg c]  },t+        |,d
       c},| _        t;        | j6                        D -+cg c]  \  }-}+|+dk(  st        |+t<              r|- }.}-}+t;        | j8                        D -,cg c]  \  }-},|,dk(  st        |,t<              r|- }/}-},t?        |.      dk(  rt?        |/      dk(  rnt?        |.      dk7  st?        |/      dk7  rt!        d      |.d   }0|/d   }1| j6                  |0   dk(  r%t        j@                  |      |0   }2t=        |2      }3n| j6                  |0   }3|3| j6                  |0<   |3| j8                  |1<   |rtC        jD                  d       d| _        |ddd| _#        nft        |t              r
d|i| _#        nLt        |tH              r%|jK                  |jM                               | _#        nt!        dtO        |             | j6                  | j8                  z   D ]   }4t        |4t,              rt!        |4 d       t?        | j6                        t?        | j8                        k(  rVtQ        | j6                  | j8                  d      D +,cg c]	  \  }+},|+|,u  }5}+},tS        |5      rt        jT                  | _        | j                  t        j                  t        j$                  fv rL| j8                  D ]=  },t        |,t,              st/        dtO        |,             |,jV                  7d|,_+        ? || _,        || _-        ddg| _.        t_        |dd      | _0        |	| _1        |
| _2        t        jf                  |      | _4        || _5        |t        jl                  |      }|| _7        || _8        || _9        || _:        t        | tv              r%| jK                  | jM                               | _<        n2t        | t              r| dd| _<        nt!        dtO        |              t        |!tv              r%|!jK                  |!jM                               | _=        n3t        |!t              r|!ddd | _=        nt!        d!tO        |!             |"dd"d#| _>        ngt        |"tv              r%|"jK                  |"jM                               | _>        n2t        |"t              r|"d"d| _>        nt!        d$tO        |"             d| _?        |&tC        jD                  d%       |&}|t        j                  d&d'      | _B        n|d(v r|| _B        nt!        d)      |	d*g| _C        nmt        |t              st!        d+      tS        d, |D              r|D 6cg c]	  }6d-|6 |6f c}6| _C        n%tS        d. |D              r|| _C        nt!        d+      |
t               }|| _F        || _G        |$| _H        || _I        || _J        || _K        || _L        d| _M        d| _N        d| _O        d| _P        d| _Q        t        j                  j                  |        t        j                  | jZ                        }7g }8	 t        j                  | jZ                        d   }8t?        |8      dkD  r$t        j                  | jZ                        r|8dd }8|8j                         D ]*  }9t        j                  |9|7      s|8j                  |9       , 	 tQ        | j6                  |8d      D ]@  \  }4}9t        |4t,              st/        d/tO        |4             |4j                  :|9|4_]        B t;        | j8                        D ]c  \  }+}4t        |4t,              st/        dtO        |4             |4j                  :t?        | j8                        dk(  rd0|4_]        Zd1|+ |4_]        e | j                  d2k7  r| j                  t        jT                  k(  r1| j                  j                  | j6                  | j                         n[| j                  t        j"                  k(  rn=| j                  j                  | j6                  | j8                  z   | j                         | 5  | j                  r| j                  j                          | j                          d3\  }:};}<}=}>d}?t               5  | j                  t        j                  t        j"                  t        jT                  fv r| j                         \  }:};}<}=}?| j                  t        j                  t        j$                  fv r/| j                  |:      \  }@}A}>}B}C|:xs @}:|;xs A};|<xs B}<|=xs C}=ddd       |;t        d4      | j                  |:|<      }D| j                  |;|?       |>|>j                          | j                  |=|;D       |Dr.| j                  r"Dj                  d5 d| j                  gdd6       | j                          | j                          ddd       | j                         | _l        yc c}+w c c}+w c c},w c c}+}-w c c},}-w c c},}+w c c}6w # t.        t         f$ r t        j                         }8Y w xY w# 1 sw Y   xY w# 1 sw Y   |xY w)8a*  
        Parameters:
            fn: the function to wrap an interface around. Often a machine learning model's prediction function. Each parameter of the function corresponds to one input component, and the function should return a single value or a tuple of values, with each element in the tuple corresponding to one output component.
            inputs: a single Gradio component, or list of Gradio components. Components can either be passed as instantiated objects, or referred to by their string shortcuts. The number of input components should match the number of parameters in fn. If set to None, then only the output components will be displayed.
            outputs: a single Gradio component, or list of Gradio components. Components can either be passed as instantiated objects, or referred to by their string shortcuts. The number of output components should match the number of values returned by fn. If set to None, then only the input components will be displayed.
            examples: sample inputs for the function; if provided, appear below the UI components and can be clicked to populate the interface. Should be nested list, in which the outer list consists of samples and each inner list consists of an input corresponding to each input component. A string path to a directory of examples can also be provided, but it should be within the directory with the python file running the gradio app. If there are multiple input components and a directory is provided, a log.csv file must be present in the directory to link corresponding inputs.
            cache_examples: If True, caches examples in the server for fast runtime in examples. If "lazy", then examples are cached (for all users of the app) after their first use (by any user of the app). If None, will use the GRADIO_CACHE_EXAMPLES environment variable, which should be either "true" or "false". In HuggingFace Spaces, this parameter defaults to True (as long as `fn` and `outputs` are also provided).
            cache_mode: if "lazy", examples are cached after their first use. If "eager", all examples are cached at app launch. If None, will use the GRADIO_CACHE_MODE environment variable if defined, or default to "eager". In HuggingFace Spaces, this parameter defaults to "eager" except for ZeroGPU Spaces, in which case it defaults to "lazy".
            examples_per_page: if examples are provided, how many to display per page.
            live: whether the interface should automatically rerun if any of the inputs change.
            title: a title for the interface; if provided, appears above the input and output components in large font. Also used as the tab title when opened in a browser window.
            description: a description for the interface; if provided, appears above the input and output components and beneath the title in regular font. Accepts Markdown and HTML content.
            article: an expanded article explaining the interface; if provided, appears below the input and output components in regular font. Accepts Markdown and HTML content. If it is an HTTP(S) link to a downloadable remote file, the content of this file is displayed.
            theme: a Theme object or a string representing a theme. If a string, will look for a built-in theme with that name (e.g. "soft" or "default"), or will attempt to load a theme from the Hugging Face Hub (e.g. "gradio/monochrome"). If None, will use the Default theme.
            flagging_mode: one of "never", "auto", or "manual". If "never" or "auto", users will not see a button to flag an input and output. If "manual", users will see a button to flag. If "auto", every input the user submits will be automatically flagged, along with the generated output. If "manual", both the input and outputs are flagged when the user clicks flag button. This parameter can be set with environmental variable GRADIO_FLAGGING_MODE; otherwise defaults to "manual".
            flagging_options: if provided, allows user to select from the list of options when flagging. Only applies if flagging_mode is "manual". Can either be a list of tuples of the form (label, value), where label is the string that will be displayed on the button and value is the string that will be stored in the flagging CSV; or it can be a list of strings ["X", "Y"], in which case the values will be the list of strings and the labels will ["Flag as X", "Flag as Y"], etc.
            flagging_dir: path to the the directory where flagged data is stored. If the directory does not exist, it will be created.
            flagging_callback: either None or an instance of a subclass of FlaggingCallback which will be called when a sample is flagged. If set to None, an instance of gradio.flagging.CSVLogger will be created and logs will be saved to a local CSV file in flagging_dir. Default to None.
            analytics_enabled: whether to allow basic telemetry. If None, will use GRADIO_ANALYTICS_ENABLED environment variable if defined, or default to True.
            batch: if True, then the function should process a batch of inputs, meaning that it should accept a list of input values for each parameter. The lists should be of equal length (and be up to length `max_batch_size`). The function is then *required* to return a tuple of lists (even if there is only 1 output component), with each list in the tuple corresponding to one output component.
            max_batch_size: the maximum number of inputs to batch together if this is called from the queue (only relevant if batch=True)
            api_name: defines how the endpoint appears in the API docs. Can be a string, None, or False. If set to a string, the endpoint will be exposed in the API docs with the given name. If None, the name of the prediction function will be used as the API endpoint. If False, the endpoint will not be exposed in the API docs and downstream apps (including those that `gr.load` this app) will not be able to use this event.
            allow_duplication: if True, then will show a 'Duplicate Spaces' button on Hugging Face Spaces.
            concurrency_limit: if set, this is the maximum number of this event that can be running simultaneously. Can be set to None to mean no concurrency_limit (any number of this event can be running simultaneously). Set to "default" to use the default concurrency limit (defined by the `default_concurrency_limit` parameter in `.queue()`, which itself is 1 by default).
            css: Custom css as a code string. This css will be included in the demo webpage.
            css_paths: Custom css as a pathlib.Path to a css file or a list of such paths. This css files will be read, concatenated, and included in the demo webpage. If the `css` parameter is also set, the css from `css` will be included first.
            js: Custom js as a code string. The custom js should be in the form of a single js function. This function will automatically be executed when the page loads. For more flexibility, use the head parameter to insert js inside <script> tags.
            head: Custom html code to insert into the head of the demo webpage. This can be used to add custom meta tags, multiple scripts, stylesheets, etc. to the page.
            head_paths: Custom html code as a pathlib.Path to a html file or a list of such paths. This html files will be read, concatenated, and included in the head of the demo webpage. If the `head` parameter is also set, the html from `head` will be included first.
            additional_inputs: a single Gradio component, or list of Gradio components. Components can either be passed as instantiated objects, or referred to by their string shortcuts. These components will be rendered in an accordion below the main input components. By default, no additional input components will be displayed.
            additional_inputs_accordion: if a string is provided, this is the label of the `gr.Accordion` to use to contain additional inputs. A `gr.Accordion` object can be provided as well to configure other properties of the container holding the additional inputs. Defaults to a `gr.Accordion(label="Additional Inputs", open=False)`. This parameter is only used if `additional_inputs` is provided.
            submit_btn: the button to use for submitting inputs. Defaults to a `gr.Button("Submit", variant="primary")`. This parameter does not apply if the Interface is output-only, in which case the submit button always displays "Generate". Can be set to a string (which becomes the button label) or a `gr.Button` object (which allows for more customization).
            stop_btn: the button to use for stopping the interface. Defaults to a `gr.Button("Stop", variant="stop", visible=False)`. Can be set to a string (which becomes the button label) or a `gr.Button` object (which allows for more customization).
            clear_btn: the button to use for clearing the inputs. Defaults to a `gr.Button("Clear", variant="secondary")`. Can be set to a string (which becomes the button label) or a `gr.Button` object (which allows for more customization). Can be set to None, which hides the button.
            delete_cache: a tuple corresponding [frequency, age] both expressed in number of seconds. Every `frequency` seconds, the temporary files created by this Blocks instance will be deleted if more than `age` seconds have passed since the file was created. For example, setting this to (86400, 86400) will delete temporary files every day. The cache will be deleted entirely when the server restarts. If None, no cache deletion will occur.
            show_progress: how to show the progress animation while event is running: "full" shows a spinner which covers the output component area as well as a runtime display in the upper right corner, "minimal" only shows the runtime display, "hidden" shows no progress animation at all
            example_labels: a list of labels for each example. If provided, the length of this list should be the same as the number of examples, and these labels will be used in the UI instead of rendering the example values.
            fill_width: whether to horizontally expand to fill container fully. If False, centers and constrains app to a maximum width.
            time_limit: The time limit for the stream to run. Default is 30 seconds. Parameter only used for streaming images or audio if the interface is live and the input components are set to "streaming=True".
            stream_every: The latency (in seconds) at which stream chunks are sent to the backend. Defaults to 0.5 seconds. Parameter only used for streaming images or audio if the interface is live and the input components are set to "streaming=True".
            deep_link: a string or `gr.DeepLinkButton` object that creates a unique URL you can use to share your app and all components **as they currently are** with others. Automatically enabled on Hugging Face Spaces unless explicitly set to False.
        r?   Gradio)rV   moderN   rQ   r]   r^   r_   r`   ra   rg   ri   F)valuerenderinteractiveT)rr   rs   Nz2Must provide at least one of `inputs` or `outputs`)unrenderz1inputs must be a string, list, or Component, not z2outputs must be a string, list, or Component, not stater      zMIf using 'state', there must be exactly one state input and one state output.)rq   z\Cache examples cannot be used with state inputs and outputs.Setting cache_examples to False.zAdditional Inputs)labelopenrw   zRThe `additional_inputs_accordion` parameter must be a string or gr.Accordion, not z5 is not a valid input/output component for Interface.strictz*Output component must be a Component, not __name__fnprimary)rq   variantz<The submit_btn parameter must be a gr.Button or string, not stop)rq   r~   visiblez:The stop_btn parameter must be a gr.Button or string, not 	secondary)r   r~   zDThe clear_btn parameter must be a gr.Button, a string, or None, not zXThe `allow_flagging` parameter in `Interface` is deprecated.Use `flagging_mode` instead.GRADIO_FLAGGING_MODEmanual)r   neverautozRInvalid value for `flagging_mode` parameter.Must be: 'auto', 'manual', or 'never'.)FlagNzNflagging_options must be a list of strings or list of (string, string) tuples.c              3  <   K   | ]  }t        |t                y wN)
isinstancestr.0xs     r5   	<genexpr>z%Interface.__init__.<locals>.<genexpr>  s     >As#>   zFlag as c              3  <   K   | ]  }t        |t                y wr   )r   tupler   s     r5   r   z%Interface.__init__.<locals>.<genexpr>  s     @!Au%@r   z)Input component must be a Component, not outputzoutput r   )NNNNNzClear button not renderedc                     t        d      S NT)rs   r   r9   r7   r5   <lambda>z$Interface.__init__.<locals>.<lambda>4      Nt< r7   inputsoutputsr_   show_apir9   )msuper__init__r   r   r   r   	get_spacer   r:   rm   rk   rl   rY   r   STANDARDinterface_type
ValueError
INPUT_ONLYOUTPUT_ONLYadditional_input_componentsr   r   r   	TypeErrorrI   rJ   main_input_componentsinput_componentsoutput_components	enumerater   lenget_default_argswarningswarn"additional_inputs_accordion_paramsr    recover_kwargs
get_configtypezipallUNIFIEDrs   api_moder|   fn_durationsgetattrr{   rM   rN   remove_html_tagssimple_descriptionrO   download_if_urlrP   examplesrK   rL   r   submit_btn_parmsstop_btn_parmsclear_btn_paramssimple_serverosgetenvrR   rS   r3   r   rU   rT   rh   rW   rX   r[   r\   share	share_url	local_urlfavicon_pathi18n_instancer0   r1   addget_type_hintsinspectgetfullargspecismethodcopyis_special_typed_parameterremovedefault_input_labelsrw   setupactivaterender_title_descriptionr"   render_input_columnrender_output_columnr   attach_submit_eventsattach_clear_eventsattach_flagging_eventsthenrender_examplesrender_articleget_config_fileconfig)Fselfr|   r   r   r   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   r=   ioidxstate_input_indexesstate_output_indexesstate_input_indexstate_output_indexrC   state_variable	componentsame_componentsr   param_typesparam_names
param_name_submit_btn
_clear_btn	_stop_btn	flag_btnsduplicate_btninput_component_column_submit_btn_out_clear_btn_2_out_stop_btn_2_outflag_btns_out_submit_event	__class__sF                                                                        r5   r   zInterface.__init__d   s   | 	 	
/#8!%!	
 	
 i%&YuRWXI$&eGI??!2&eGIe!3I"$(5=,55NflGrMQRR_2G"0";";D^v|F"0"<"<D$/1D,/:%6$7!BS0=>&q480D, &8Y"78CF8L  'Hi#89DWIN  fsI./XFgY/0iG,;E ?E&
9:"1t4&
" &&)I)II 	
 "
 #1t4"
 $D$9$9:
QG|z!U3 
 
 $D$:$:; 
QG|z!U3  
  
 "#q(S1E-F!-K$%*c2F.G1.L_  !4A 6!5a!8$$%677B0045FG!&W!5!%!6!67H!I7ED!!"349GD""#567 #(D&.,7D3 3S947D3 3Y?+::/::< 3 dei  kF  fG  eH  I  ..1G1GG 	Iy)4  k!VW 	 t$$%T-C-C)DD  ))4+A+A%Aq QO  ?#&4&<&<###&&#
 
 ++ *!!Y/#DT!WIN  ==( %*AM* "FJ5	
"'"8"8"E&++G4G !2,j&)$.$=$=j>S>S>U$VD!
C(#$%D!
 NtT^O_N`a  h'"*"9"9(:M:M:O"PD#&!! #D LTRZ^L\]   &%D! 	6*$-$<$<Y=Q=Q=S$TD!	3'"&%D!
 VW[\eWfVgh  " %MM/ +M !#+A8!LD99!.D9 
 #%3$4D!-t4`  >-=>>BR$SQna%8$SD!@/?@@$4D!`  $ )!2(CP
,!2BS
 !%**4773	7!009!<K;!#(8(8(A)!"o)..0 3
33JL&&z23
 &)!!;u&
 	-!Iz i3?Y?PQ  &",		- &d&<&<= 		4LAyi3@i@QR  &t--.!3&.IO(/smIO		4 (""n&<&<<&&,,T-B-BDDUDUV$$(A(AA&&,,))D,B,BB%%  =	"~~'')))+LHKY	= &*" ;&&"++"--"**+  002#"!!.&&"++"..+  11+>'(%'%"-"@K!+!?/?J ) <_I ) :]I7;: !!"=>> 55k9MM$$Z1GH(&&(''	:}M""<!^^," #    "!{=	"~ **,g
0*&
"



 
tZ %TL :& 	7446K	7`; ;=	" =	"sj   2qqq!q!q;q!q' A=q, q, Ar#B-r:B.r#,#rrr 	r##r,c                    | j                   rt        d| j                    d       | j                  rt        | j                         y y )N4<h1 style='text-align: center; margin-bottom: 1rem'></h1>)rN   r   rO   r   s    r5   r   z"Interface.render_title_description?  s@    ::FtzzlRWX T%%& r7   c                ^    | j                   D cg c]  \  }}t        |       c}}S c c}}w r   )rS   r   )r   rw   _s      r5   render_flag_btnszInterface.render_flag_btnsG  s$    .2.C.CD(%uDDDs   )c                   d\  }}}}t               5  t               }|5  | j                  D ]  }|j                           | j                  r@t	        di | j
                  5  | j                  D ]  }|j                           	 d d d        d d d        t               5  | j                  t        j                  t        j                  fv rt        di | j                  }| j                  s| j                  r7| j                  t        j                  k(  r| j                  j                          t        di | j                   }t#        j$                  | j&                        s t#        j(                  | j&                        rt        di | j*                  }n| j                  t        j,                  k(  rt        di | j                  }t        di | j                   }| j                  r| j                  j                          t#        j$                  | j&                        st#        j(                  | j&                        r!| j                  st        di | j*                  }| j.                  dk(  r| j1                         }n| j.                  dk(  r|g}d d d        d d d        ||||fS # 1 sw Y   -xY w# 1 sw Y   2xY w# 1 sw Y   2xY w# 1 sw Y   6xY w)NNNNNr   r   r9   )r!   r   rr   r   r    r   r"   r   r   r   r   r   r   rM   rm   r   r   r   isgeneratorfunctionr|   isasyncgenfunctionr   r   rR   r   )r   r   r   r   r   r   r   s          r5   r   zInterface.render_input_columnJ  ss    9O5ZIX ,	2%+X"' /!%!;!; 'I$$&'33"MT%L%LM /)-)I)I /I%,,.//	/  #2&&"++"--+  "-!Et/D/D!EJ99 NN $ 3 3~7P7P P NN113&,&Et/D/D&E #66 GG$77@(.(E1D1D(EI((N,B,BB!,!Et/D/D!EJ"("A4+@+@"AK~~--/33DGG<"55dgg>"ii$*$AT-@-@$A	))X5$($9$9$;	++v5%0M	G#2,	2\ "
 	
O/ /	/ /#2 #2,	2 ,	2sT   KAJ=""J0J=KG:K
K0J:5J==K	K
K	KKc                <   |}d\  }}}}t               5  | j                  D ]#  }t        |t              r|j	                          % t               5  | j                  r| j                  j	                          | j                  t        j                  k(  rt        di | j                  }t        dd      }t        j                  | j                        st        j                   | j                        r!| j"                  st        di | j$                  }| j&                  dk(  r| j)                         }n| j&                  dk(  r|t+        d      |g}| j,                  rt/        dd	d
      }d d d        d d d        |||||fS # 1 sw Y   xY w# 1 sw Y   xY w)Nr   Generater}   )r~   r   r   Submit button not renderedrv   lgF)scalesize	_activater9   )r!   r   r   r   rr   r"   rm   r   r   r   r   r   r   r   r   r|   r  rM   r   rR   r   r   r[   r   )r   _submit_btn_inr   r   r   r   r   r   s           r5   r   zInterface.render_output_column  s    %;
7
M9i X 	Y!33 '	"9e4$$&'  Y>>NN))+&&.*D*DD!,!Et/D/D!EJ"(Y"GK33DGG<"55dgg>"ii %+$AT-@-@$A	%%1 $ 5 5 7I''61"*)*FGG!,I))$3!$RW$XM1Y		Y> 
 	
5Y Y		Y 	Ys)    FFDF/FF	FFc                H    | j                   rt        | j                          y y r   )rP   r   r   s    r5   r   zInterface.render_article  s    <<T\\" r7   c                ^   | j                   r| j                  t        j                  k(  r|t	        d      t
        |   | j                  d | j                         |j                  | j                  d | j                  | j                  | j                   | j                   | j                  | j                        S g }d}| j                  D ]j  }|j                  d      r*|j                   r|j#                  |j$                         d}>|j                  d      sP|j#                  |j&                         l t)        || j                  | j                  | j                  | j                  | j                   | j                   |rdn| j*                  |sdnd	| j,                  | j.                  
      S |t	        d      | j                  }g }|j                  g| j                  D cg c]-  }|j                  t0        j2                        r|j2                  / c}z   }| j                  D ]%  }t5        |dd       st7        j8                  d       ' |r||g}d }	t)        |t;        j<                  d       d ||gdd      j?                  | j                  | j                  | j                  | j                  d| j                   | j                   | j                  | j                  | j@                  | j*                        }
|
j?                  |	d |dd      }|j                  |	d ||g|
dd       |S t)        ||| j                  | j                  | j                  d| j                   | j                   | j                  | j                  | j@                  | j*                        S c c}w )Nr  )rY   
preprocesspostprocessrW   rX   FstreamTchangehiddenalways_lastmultiple)rY   r  r  rh   trigger_moderk   rl   	streamingz;Streaming components are only supported in live interfaces.c                 :   K   t        d      t        d      gS w)NTr   Fr   r9   r7   r5   cleanupz/Interface.attach_submit_events.<locals>.cleanup  s     "40&2GHHs   c                 2    t        d      t        d      fS )NFr  Tr  r9   r7   r5   r   z0Interface.attach_submit_events.<locals>.<lambda>  s    "51"40! r7   )r   r   r.   r   )rY   scroll_to_outputr  r  rW   rX   r\   rh   )r   r   cancelsr.   r   )!rM   r   r   r   r   r   r+   r|   r   clickrY   r   rW   rX   r   	has_eventr  appendr  r  r   rh   rk   rl   r   submitr   r   r   r   async_lambdar   r\   )r   r   r   eventsstreaming_eventr   r|   extra_outputtriggersr  predict_eventfinal_eventr   s               r5   r   zInterface.attach_submit_events  s    99""n&@&@@&%&BCCTWWdD,B,BC #((GG**!]]$(MM2%)]] 3**#'#6#6 ) 	 	 *,"'!%!6!6 8I **849L9Li&6&67*.",,X6i&6&678 GG))**!]]$(MM2%)]] 3.=(4CUCU6E:#!%!2!2  "!">??BL#))*!%!6!6.&&v}}5   . H "22 	9k48MMU  +Y7I !#&&  ()4"! $GG))**!]]%)$(MM2%)]] 3**#'#6#6&*&<&<"&"4"4   4 ,00(" 1  ()4)"    #"))**!]]%)$(MM2%)]] 3**#'#6#6&*&<&<"&"4"4 }.s   +2N*c                :   |j                  | j                  | j                  z          |j                  d g |r|gng dt	        j
                  | j                  t        j                  t        j                  t        j                  fv rd dddgng        d       y )Nz() => Tupdate)r~   r   __type__z
            )r_   )r   r   r   r  jsondumpsr   r   r   r   r   )r   r   r   s      r5   r   zInterface.attach_clear_eventsC  s    
 	t,,t/E/EEF)?$%R

**&//&11&.. "&$HMN 		 	 	
r7   c           	     P   |r;| j                   t        j                  t        j                  t        j                  fv sy | j
                  dk(  rHt        | j                  dd d      }|j                  || j                  | j                  z   d ddd       y | j                   t        j                  k(  r| j                  }n| j                  | j                  z   }t        || j                  d      D ]  \  }\  }}|t        |t              st        d|      t        | j                  ||      }|j!                  t#        j$                  d       d |dd	       |j!                  |||ddd       |j!                  t#        j$                  |j&                        d |dd	        y )
Nr    F)visual_feedback)r   r   r  r.   r   ry   z,Flagging option value must be a string, not c                     t        dd      S )Nz	Saving...F)rq   rs   r  r9   r7   r5   r   z2Interface.attach_flagging_events.<locals>.<lambda>  s    F%H r7   )r.   r   )r   r   r   r   r   rR   r   rU   successr   r   r   rS   r   r   r   r  r   r   reset)	r   r   r   r   flag_methodflag_componentsflag_btnrw   rq   s	            r5   r   z Interface.attach_flagging_events\  s    ##''**&& '$&&D%K !!,,t/E/EE  "  ."8"88"33O"33d6L6LLO(+t,,U)
 	$Hnue  E3)?B5)L  %T%;%;UEJKNN""H    NN&     "";#4#45  3	r7   c                d   | j                   r| j                  D cg c]  }t        |t              r| }}| j                  D cg c]  }t        |t              r| }}t        | j                   ||| j                  | j                  | j                  | j                  | j                  | j                  | j                  
      | _        | j                  rN| j                  j                  r7| j                  j                  j!                  d d | j                  gdd       y y y y c c}w c c}w )N)
r   r   r   r|   rI   rJ   rK   rZ   rW   rL   c                     t        d      S r   r   r9   r7   r5   r   z+Interface.render_examples.<locals>.<lambda>  r   r7   TFr   )r   r   r   r   r   r   r|   rI   rJ   rK   r   rW   rL   examples_handlerrm   cache_eventr   )r   cnon_state_inputsnon_state_outputss       r5   r   zInterface.render_examples  s   ==00 
1e8L     11!Au9M! ! %-')77#22??"&"8"8--jj#22%D! ~~$"7"7"C"C%%1166<!^^," 7  #D~'  !s   D(D(D-D-c                "    | j                         S r   )__repr__r   s    r5   __str__zInterface.__str__  s    }}r7   c                    d| j                    }|ddt        |      z   z  }|dz  }| j                  D ]
  }|d| z  } |dz  }| j                  D ]
  }|d| z  } |S )NzGradio Interface for: 
-z
inputs:z
|-z	
outputs:)r{   r   r   r   )r   reprr   s      r5   r=  zInterface.__repr__  s    '7"S3t9_%&&.. 	'Id9+&&D	'// 	'Id9+&&D	'r7   )returnzlist[Interface])r<   zPipeline | DiffusionPipelinerC  r0   r   )Rr|   r   r   2str | Component | Sequence[str | Component] | Noner   rD  r   z(list[Any] | list[list[Any]] | str | NonerI   bool | NonerJ   zLiteral['eager', 'lazy'] | NonerK   intrL   list[str] | NonerM   boolrN   zstr | I18nData | NonerO   
str | NonerP   rI  rQ   Theme | str | NonerR   =Literal['never'] | Literal['auto'] | Literal['manual'] | NonerS   z(list[str] | list[tuple[str, str]] | NonerT   r   rU   zFlaggingCallback | NonerV   rE  rW   rH  rX   rF  rY   zstr | Literal[False] | NonerZ   rH  r[   rH  r\   zint | None | Literal['default']r]   rI  r^   (str | Path | Sequence[str | Path] | Noner_   str | Literal[True] | Noner`   rI  ra   rL  rb   rD  rc   zstr | Accordion | Nonerd   str | Buttonre   rN  rf   zstr | Button | Nonerg   ztuple[int, int] | Nonerh   z$Literal['full', 'minimal', 'hidden']ri   rH  rj   rK  rk   z
int | Nonerl   floatrm   z"str | DeepLinkButton | bool | None)rC  None)rC  zlist[Button])rC  zTtuple[Button | None, ClearButton | None, Button | None, list[Button] | None, Column])r	  Button | NonerC  z\tuple[Button | None, ClearButton | None, DuplicateButton | None, Button | None, list | None])r   rQ  r   rQ  rC  r   )r   r   r   zColumn | None)r   zlist[Button] | Noner   r   r   r   )r{   
__module____qualname____doc__weakrefWeakSetr1   __annotations__classmethodr6   r,   r   r   r   r   r   r   r   r   r   r   r>  r=  __classcell__r   s   @r5   r0   r0   ,   se   ( "1!2I2) ) 3	 : >BY- '+6:!#+/'+"&"$( EI-59)-09"'=F>B)-?CPT>B#+!')0/3>D  !#!8<cY-Y- CY- D	Y-
 ;Y- $Y- 4Y- Y- )Y- Y- %Y-  Y- Y- "Y- !Y-( C)Y-* +Y-, 3-Y-. '/Y-0 1Y-2 3Y-4 .5Y-6 7Y-8  9Y-: ;;Y-< =Y-> <?Y-@ 'AY-B CY-D =EY-F NGY-H &<IY-J !KY-L MY-N 'OY-P -QY-R <SY-T UY-VWY-^ _Y-` aY-b 6cY-v'E>

>
@6
%6

6
p#{({5B{	{z

 !.
2C&C  C "	CJ:	r7   r0   c                  R     e Zd ZdZ	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZ xZS )TabbedInterfaceah  
    A TabbedInterface is created by providing a list of Interfaces or Blocks, each of which gets
    rendered in a separate tab. Only the components from the Interface/Blocks will be rendered in the tab.
    Certain high-level attributes of the Blocks (e.g. custom `css`, `js`, and `head` attributes) will not be loaded.

    Demos: tabbed_interface_lite
    c	           
        t         |   |xs d||d|||d       |$t        t        |            D 	cg c]  }	d|	 	 }}	| 5  |rt	        d| d       t               5  t        ||d	
      D ]9  \  }
}t        ||
j                  rdnd      5  |
j                          ddd       ; 	 ddd       ddd       yc c}	w # 1 sw Y   \xY w# 1 sw Y   #xY w# 1 sw Y   yxY w)aI  
        Parameters:
            interface_list: A list of Interfaces (or Blocks) to be rendered in the tabs.
            tab_names: A list of tab names. If None, the tab names will be "Tab 1", "Tab 2", etc.
            title: The tab title to display when this demo is opened in a browser window.
            theme: A Theme object or a string representing a theme. If a string, will look for a built-in theme with that name (e.g. "soft" or "default"), or will attempt to load a theme from the Hugging Face Hub (e.g. "gradio/monochrome"). If None, will use the Default theme.
            analytics_enabled: Whether to allow basic telemetry. If None, will use GRADIO_ANALYTICS_ENABLED environment variable or default to True.
            css: Custom css as a string or path to a css file. This css will be included in the demo webpage.
            js: Custom js as a string or path to a js file. The custom js should in the form of a single js function. This function will automatically be executed when the page loads. For more flexibility, use the head parameter to insert js inside <script> tags.
            head: Custom html to insert into the head of the demo webpage. This can be used to add custom meta tags, multiple scripts, stylesheets, etc. to the page.
        Returns:
            a Gradio Tabbed Interface for the given interfaces
        ro   tabbed_interfaceT)rN   rQ   rV   rp   r]   r_   r`   fill_heightNzTab r   r   Fry   rv   )rw   r  )
r   r   ranger   r   r$   r   r#   r_  rr   )r   interface_list	tab_namesrN   rQ   rV   r]   r_   r`   r   r?   tab_namer   s               r5   r   zTabbedInterface.__init__  s   0 	#8/# 	 		
 -23~3F-GH4sHIH 	+J5'QVW  ++.~yQV+W +'Ix&#,#8#8ad + "((*	+ +++	+ 	+ I+ ++ +	+ 	+sA   B>C!0CC	"
C-CCCC	CC$)NNNNNNN)ra  zSequence[Blocks]rb  rG  rN   rI  rQ   rJ  rV   rE  r]   rI  r_   rM  r`   rI  )r{   rR  rS  rT  r   rY  rZ  s   @r5   r\  r\    sw     '+ $()-)-/+(/+ $/+ 	/+
 "/+ '/+ /+ '/+ /+ /+r7   r\  c                X    t         j                         D ]  }|j                  |         y r   )r0   r6   close)verboseios     r5   	close_allrh  	  s&    %%' 
r7   )T)rf  rH  rC  rP  )CrT  
__future__r   r   r*  r   r   rU  collections.abcr   r   pathlibr   typingr   r   r	   gradio_client.documentationr
   gradior   r   r   gradio.blocksr   gradio.componentsr   r   r   r   r   r   r   r   gradio.data_classesr   gradio.eventsr   r   r   gradio.exceptionsr   gradio.flaggingr   r   r   gradio.i18nr   gradio.layoutsr    r!   r"   r#   r$   gradio.pipelinesr%   r&   gradio.themesr'   Theme	diffusersr(   transformers.pipelines.baser)   r0   r\  rh  r9   r7   r5   <module>r|     s    #   	   .  . . 0 . .  	 	 	 / 0 0 ) C C   < < F -+4 
(FO['B] ] C]@ 
8+f 8+ 8+vr7   