
    8P[ip                       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mZm	Z	 ddl
mZmZmZ ddlmZ ddlmZmZ 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l,m-Z-m.Z.m/Z/m0Z0m1Z1 ddl2m3Z3 erddl4m5Z5 ddl6m7Z7  eddddd       G d de             Z8 e        G d de             Z9dddZ:y)zk
This file defines two useful high-level abstractions to build Gradio apps: Interface and TabbedInterface.
    )annotationsN)CallableSequence)TYPE_CHECKINGAnyLiteral)document)Examples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_pipeline)DiffusionPipeline)Pipelinelaunchloadfrom_pipeline	integratequeuec            $          e Zd Z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  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
    c                D    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#   dict)clspipelinekwargsinterface_info	interfaces        ^/var/www/html/chatbot/Makanify-Chatbot-2/venv/lib/python3.12/site-packages/gradio/interface.pyr(   zInterface.from_pipeline>   s.    " ,H5n//M&M	    N
   r   Fz.gradio/flagged   publicdefaultSubmitStopClearfull   g      ?)"cache_examples
cache_modeexamples_per_pageexample_labelspreload_examplelivetitledescriptionarticleflagging_modeflagging_optionsflagging_dirflagging_callbackanalytics_enabledbatchmax_batch_sizeapi_visibilityapi_nameapi_description	_api_modeallow_duplicationconcurrency_limitadditional_inputsadditional_inputs_accordion
submit_btnstop_btn	clear_btndelete_cacheshow_progress
fill_width
time_limitstream_every	deep_link	validatorc       "   	        t        B|   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      }%|%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}(| _        | j6                  | j&                  z   | _        |D )cg c]  })t+        |)d
       c})| _        t=        | j8                        D *(cg c]  \  }*}(|(dk(  st        |(t>              r|* }+}*}(t=        | j:                        D *)cg c]  \  }*})|)dk(  st        |)t>              r|* },}*})tA        |+      dk(  rtA        |,      dk(  rntA        |+      dk7  stA        |,      dk7  rt!        d      |+d   }-|,d   }.| j8                  |-   dk(  r%t        jB                  |      |-   }/t?        |/      }0n| j8                  |-   }0|0| j8                  |-<   |0| j:                  |.<   |rtE        jF                  d       d| _        |ddd| _$        nft        |t              r
d|i| _$        nLt        |tJ              r%|jM                  |jO                               | _$        nt!        dtQ        |             | j8                  | j:                  z   D ]   }1t        |1t,              rt!        |1 d       tA        | j8                        tA        | j:                        k(  rVtS        | j8                  | j:                  d      D ()cg c]	  \  }(})|(|)u  }2}(})tU        |2      rt        jV                  | _        | j                  t        j                  t        j$                  fv rL| j:                  D ]=  })t        |)t,              st/        dtQ        |)             |)jX                  7d|)_,        ? || _-        || _.        |&| _/        ddg| _0        tc        |dd      | _2        |
| _3        || _4        t        jj                  |      | _6        || _7        |t        jp                  |      }|| _9        || _:        || _;        || _<        t        |tz              r%|jM                  |jO                               | _>        n2t        |t              r|dd| _>        nt!        dtQ        |             t        |tz              r%|jM                  |jO                               | _?        n3t        |t              r|ddd | _?        nt!        d!tQ        |             |dd"d#| _@        ngt        |tz              r%|jM                  |jO                               | _@        n2t        |t              r|d"d| _@        nt!        d$tQ        |             d| _A        |t        j                  d%d&      | _D        n|d'v r|| _D        nt!        d(      |	d)g| _E        nmt        |t              st!        d*      tU        d+ |D              r|D 3cg c]	  }3d,|3 |3f c}3| _E        n%tU        d- |D              r|| _E        nt!        d*      |
t               }|| _H        || _I        |!| _J        || _K        || _L        || _M        || _N        d| _O        d| _P        d| _Q        d| _R        d| _S        t        j                  | j\                        }4g }5	 t        j                  | j\                        d   }5tA        |5      dkD  r$t        j                  | j\                        r|5dd }5|5j                         D ]*  }6t        j                  |6|4      s|5j                  |6       , 	 tS        | j8                  |5d      D ]@  \  }1}6t        |1t,              st/        d.tQ        |1             |1j                  :|6|1_\        B t=        | j:                        D ]c  \  }(}1t        |1t,              st/        dtQ        |1             |1j                  :tA        | j:                        dk(  rd/|1_\        Zd0|( |1_\        e | j                  d1k7  r| j                  t        jV                  k(  r1| j                  j                  | j8                  | j                         n[| j                  t        j"                  k(  rn=| j                  j                  | j8                  | j:                  z   | j                         | 5  | j                  r| j                  j                          | j                          d2\  }7}8}9}:};d}<t               5  | j                  t        j                  t        j"                  t        jV                  fv r| j                         \  }7}8}9}:}<| j                  t        j                  t        j$                  fv r/| j                  |7      \  }=}>};}?}@|7xs |=}7|8xs |>}8|9xs |?}9|:xs @}:ddd       |8t        d3      | j                  |7|9      }A| j                  |8|<       |;|;j                          | j                  |:|8A       |Ar.| j                  r"Aj                  d4 d| j                  gdd56       | j                          | j                          ddd       | j                         | _k        yc c}(w c c}(w c c})w c c}(}*w c c})}*w c c})}(w c c}3w # t.        t         f$ r t        j                         }5Y 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).  Note that examples are cached separately from Gradio's queue() so certain features, such as gr.Progress(), gr.Info(), gr.Warning(), etc. will not be displayed in Gradio's UI for cached examples.
            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.
            preload_example: If an integer is provided (and examples are being cached eagerly and none of the input components have a developer-provided `value`), the example at that index in the examples list will be preloaded when the Gradio app is first loaded. If False, no example will be preloaded.
            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.
            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 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 prediction endpoint appears in the API docs. Can be a string or None. If set to a string, the endpoint will be exposed in the API docs with the given name. If None, the name of the function will be used.
            api_description: Description of the API endpoint. Can be a string, None, or False. If set to a string, the endpoint will be exposed in the API docs with the given description. If None, the function's docstring will be used as the API endpoint description. If False, then no description will be displayed in the API docs.
            api_visibility: Controls the visibility of the prediction endpoint. Can be "public" (shown in API docs and callable), "private" (hidden from API docs and not callable), or "undocumented" (hidden from API docs but callable).
            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).
            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.
            validator: a function that takes in the inputs and can optionally return a gr.validate() object for each input.

        r4   Gradio)rM   moderF   r[   r]   F)valuerenderinteractiveT)rf   rg   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.)re   z]Cache examples cannot be used with state inputs and outputs. Setting cache_examples to False.zAdditional Inputs)labelopenrk   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)re   variantz<The submit_btn parameter must be a gr.Button or string, not stop)re   rr   visiblez:The stop_btn parameter must be a gr.Button or string, not 	secondary)rt   rr   zDThe clear_btn parameter must be a gr.Button, a string, or None, not GRADIO_FLAGGING_MODEmanual)rw   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 rx   )NNNNNzClear button not renderedc                     t        d      S NT)rg   r   r.   r6   r5   <lambda>z$Interface.__init__.<locals>.<lambda>      Nt< r6   undocumentedinputsoutputsjsrP   r.   )lsuper__init__r}   r~   r   r   	get_spacer`   r^   r_   rQ   rR   rP   r   STANDARDinterface_type
ValueError
INPUT_ONLYOUTPUT_ONLYadditional_input_componentsr   r   r   	TypeErrorr@   rA   rD   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UNIFIEDrg   api_moderp   ra   fn_durationsgetattrro   rE   rF   remove_html_tagssimple_descriptionrG   download_if_urlrH   examplesrB   rC   r   submit_btn_parmsstop_btn_parmsclear_btn_paramssimple_serverosgetenvrI   rJ   listr   rL   rK   r\   rN   rO   rT   rU   share	share_url	local_urlfavicon_pathi18n_instanceget_type_hintsinspectgetfullargspecismethodcopyis_special_typed_parameterremovedefault_input_labelsrk   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)Cselfrp   r   r   r   r@   rA   rB   rC   rD   rE   rF   rG   rH   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   r2   ioidxstate_input_indexesstate_output_indexesstate_input_indexstate_output_indexr:   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__sC                                                                     r5   r   zInterface.__init__T   s   n 	 	
/#8%!	
 	
 i%&YuRWXI$&eGI??!2&eGII"$($,<K,,55NflGrMQRR_2G"0";";D^v|F"0"<"<D$/1D,/:%6$7! +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  "  !#+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""<!^^,#1 #    "!{=	"~ **,_
0.&
"



 
tP %TJ :& 	7446K	7`; ;=	" =	"sj   *ppp!p#!p):p/0p5.A=p: ,p: Aq1B-q$B.q1:#q! q!$q.	)q11q:c                    | j                   rt        d| j                    d       | j                  rt        | j                         y y )N4<h1 style='text-align: center; margin-bottom: 1rem'></h1>)rF   r   rG   r   s    r5   r   z"Interface.render_title_description   s@    ::FtzzlRWX T%%& r6   c                ^    | j                   D cg c]  \  }}t        |       c}}S c c}}w r|   )rJ   r   )r   rk   _s      r5   render_flag_btnszInterface.render_flag_btns(  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NNNNrw   ry   r.   )r   r   rf   r   r   r   r    r   r   r   r   r   r   rE   r`   r   r   r   isgeneratorfunctionrp   isasyncgenfunctionr   r   rI   r   )r   r   r   r   r   r   r   s          r5   r   zInterface.render_input_column+  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   Generaterq   )rr   rw   ry   Submit button not renderedrj   lgF)scalesize	_activater.   )r   r   r}   r   rf   r    r`   r   r   r   r   r   r   r   r   rp   r   rE   r   rI   r   r   rT   r   )r   _submit_btn_inr   r   r   r   r   r   s           r5   r   zInterface.render_output_columnk  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|   )rH   r   r   s    r5   r   zInterface.render_article  s    <<T\\" r6   c                h   | j                   r| j                  t        j                  k(  r|t	        d      t
        |   | j                  d | j                         |j                  | j                  d | j                  | j                  | j                  | 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                  | j                   | j                   |rdn| j0                  |sdnd	| j2                  | j4                  | j                   
      S |t	        d      | j                  }g }|j                  g| j"                  D cg c]-  }|j%                  t6        j8                        r|j8                  / c}z   }| j"                  D ]%  }t;        |dd       st=        j>                  d       ' |r ||g}d }	t/        |tA        jB                  d       d ||gdd      jE                  | j                  | j"                  | j                  | j                  | j                  | j                  d| j                   | j                   | j                  | j                  | jF                  | j0                  | j                         }
|
jE                  |	d |dd      }|j                  |	d ||g|
dd       |S t/        ||| j"                  | j                  | j                  | j                  | j                  d| j                   | j                   | j                  | j                  | jF                  | j0                  | j                         S c c}w )Nr   )rQ   rP   rR   
preprocesspostprocessrN   rO   ra   FstreamTchangehiddenalways_lastmultiple)
rQ   rR   rP   r  r  r\   trigger_moder^   r_   ra   	streamingz;Streaming components are only supported in live interfaces.c                 :   K   t        d      t        d      gS w)NTrt   Fr   r.   r6   r5   cleanupz/Interface.attach_submit_events.<locals>.cleanup  s     "40&2GHHs   c                 2    t        d      t        d      fS )NFr  Tr  r.   r6   r5   r   z0Interface.attach_submit_events.<locals>.<lambda>  s    "51"40! r6   r   )r   r   r*   rP   )rQ   rP   rR   scroll_to_outputr  r  rN   rO   rU   r\   ra   )r   r   cancelsr*   rP   )$rE   r   r   r   r   r   r'   rp   r   clickrQ   rP   rR   r   rN   rO   ra   r   	has_eventr	  appendr  r  r   r\   r^   r_   r   submitr   r   r   r   async_lambdar   rU   )r   r   r   eventsstreaming_eventr   rp   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**!]]#'#6#6$($8$8$(MM2%)]] 3**#'#6#6"nn )   *,"'!%!6!6 8I **849L9Li&6&67*.",,X6i&6&678 GG))**!]]$($8$8#'#6#6$(MM2%)]] 3.=(4CUCU6E:#!%!2!2"nn " "!">??BL#))*!%!6!6.&&v}}5   . H "22 	9k48MMU  +Y7I !#&&  ()4#1! $GG))**!]]#'#6#6$($8$8%)$(MM2%)]] 3**#'#6#6&*&<&<"&"4"4"nn   : ,00(#1 1  ()4)#1    #"))**!]]#'#6#6$($8$8%)$(MM2%)]] 3**#'#6#6&*&<&<"&"4"4"nn C.s   -2P/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)rr   rt   __type__z
            )r   )addr   r   r  jsondumpsr   r   r   r   r   )r   r   r   s      r5   r   zInterface.attach_clear_events0  s    
 	t,,t/E/EEF)?$%R

**&//&11&.. "&$HMN 		 	 	
r6   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 )Nry    F)visual_feedbackr   )r   r   r  r*   rP   rm   z,Flagging option value must be a string, not c                     t        dd      S )Nz	Saving...F)re   rg   r  r.   r6   r5   r   z2Interface.attach_flagging_events.<locals>.<lambda>w  s    F%H r6   )r*   rP   )r   r   r   r   r   rI   r   rL   successr   r   r   rJ   r}   r~   r   r  r   r  reset)	r   r   r   r   flag_methodflag_componentsflag_btnrk   re   s	            r5   r   z Interface.attach_flagging_eventsI  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	r6   c                ~   | j                   r&| j                  D cg c]  }t        |t              s| }}| j                  D cg c]  }t        |t              s| }}t        | j                   ||| j                  | j                  | j                  | j                  | j                  xs d| 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 )NF)r   r   r   rp   r@   rA   rB   rS   rN   rC   preloadc                     t        d      S r   r   r.   r6   r5   r   z+Interface.render_examples.<locals>.<lambda>  r   r6   Tr   r   )r   r   r}   r   r   r
   rp   r@   rA   rB   r   rN   rC   rD   examples_handlerr`   cache_eventr   )r   cnon_state_inputsnon_state_outputss       r5   r   zInterface.render_examples  s-   == .. !!U+     //!!!U+ ! !
 %-')77#22??"&"8"8--05jj#22,,%D! ~~$"7"7"C"C%%1166<!^^,#1 7  #D~1  
!s   D5D:c                "    | j                         S r|   )__repr__r   s    r5   __str__zInterface.__str__  s    }}r6   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:)ro   r   r   r   )r   reprr   s      r5   r4  zInterface.__repr__  s    '7"S3t9_%&&.. 	'Id9+&&D	'// 	'Id9+&&D	'r6   )r1   zPipeline | DiffusionPipelinereturnr,   r|   )Lrp   r   r   2str | Component | Sequence[str | Component] | Noner   r;  r   z(list[Any] | list[list[Any]] | str | Noner@   bool | NonerA   zLiteral['eager', 'lazy'] | NonerB   intrC   list[str] | NonerD   zint | Literal[False]rE   boolrF   zstr | I18nData | NonerG   
str | NonerH   r@  rI   z=Literal['never'] | Literal['auto'] | Literal['manual'] | NonerJ   z(list[str] | list[tuple[str, str]] | NonerK   r~   rL   zFlaggingCallback | NonerM   r<  rN   r?  rO   r=  rP   z,Literal['public', 'private', 'undocumented']rQ   r@  rR   zstr | None | Literal[False]rS   r?  rT   r?  rU   zint | None | Literal['default']rV   r;  rW   zstr | Accordion | NonerX   str | ButtonrY   rA  rZ   zstr | Button | Noner[   ztuple[int, int] | Noner\   z$Literal['full', 'minimal', 'hidden']r]   r?  r^   z
int | Noner_   floatr`   z"str | DeepLinkButton | bool | Nonera   zCallable | None)r:  None)r:  zlist[Button])r:  zTtuple[Button | None, ClearButton | None, Button | None, list[Button] | None, Column])r   Button | Noner:  z\tuple[Button | None, ClearButton | None, DuplicateButton | None, Button | None, list | None])r   rD  r   rD  r:  r   )r   r   r   zColumn | None)r   zlist[Button] | Noner   r   r   r   )ro   
__module____qualname____doc__classmethodr(   r   r   r   r   r   r   r   r   r   r   r5  r4  __classcell__r   s   @r5   r,   r,   )   s   & 3	 4 >BJ- '+6:!#+/01'+"&" EI-59)-GO#7;"'=FPT>B#+!')0/3>D !#!8<%)WJ-J- CJ- D	J-
 ;J- $J- 4J- J- )J- .J- J- %J-  J- J- !J-( C)J-* +J-, 3-J-. '/J-0 1J-2 3J-4 E5J-6 7J-8 59J-: ;J-<  =J-> ;?J-@ NAJ-B &<CJ-D !EJ-F GJ-H 'IJ-J -KJ-L <MJ-N OJ-P QJ-R SJ-T 6UJ-V #WJ-X'E>

>
@6
%6

6
p#G(G5BG	GR

 !.
2C&C  C "	CJ D	r6   r,   c                  :     e Zd ZdZ	 	 	 d	 	 	 	 	 	 	 d fdZ xZS )TabbedInterfacez
    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.

    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)a  
        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.
            analytics_enabled: Whether to allow basic telemetry. If None, will use GRADIO_ANALYTICS_ENABLED environment variable or default to True.
        Returns:
            a Gradio Tabbed Interface for the given interfaces
        rc   tabbed_interfaceT)rF   rM   rd   fill_heightNzTab r   r   Frm   rj   )rk   r   )
r   r   ranger   r   r"   r   r!   rO  rf   )	r   interface_list	tab_namesrF   rM   r   r4   tab_namer   s	           r5   r   zTabbedInterface.__init__  s     	#8/#	 	 	
 -23~3F-GH4sHIH 	+J5'QVW  ++.~yQV+W +'Ix&#,#8#8ad + "((*	+ +++	+ 	+ I+ ++ +	+ 	+sA   B:C0CB?	
C)C?CCC	CC )NNN)rQ  zSequence[Blocks]rR  r>  rF   r@  rM   r<  )ro   rE  rF  rG  r   rI  rJ  s   @r5   rL  rL    sC     '+ )-#+(#+ $#+ 	#+
 '#+ #+r6   rL  c                r    t        j                         D ]   }|j                  s|j                  |        " y r|   )r   get_instances
is_runningclose)verboseinstances     r5   	close_allrZ    s/    ((* $NN7#$r6   )T)rX  r?  r:  rC  );rG  
__future__r   r   r   r   r   collections.abcr   r   typingr   r   r   gradio_client.documentationr	   gradior
   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#   	diffusersr$   transformers.pipelines.baser%   r,   rL  rZ  r.   r6   r5   <module>rk     s    #   	  . . . 0 "  	 	 	 / 0 0 ) C C   < < /+4 
(FO['BR R CRj 
++f ++ ++\$r6   