a
    þd|  ã                
   @  s¬   d Z ddl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 ddlmZ ddlmZmZ dd	lmZmZmZmZ ed
ƒ eƒ G dd„ deeeeeeƒƒZdS )zgr.Model3D() component.é    )Úannotations)ÚPath)ÚAnyÚCallableÚLiteral)Ú
media_data)ÚdocumentÚset_documentation_group)ÚFileSerializable)ÚIOComponentÚ	_Keywords)Ú
ChangeableÚ	ClearableÚEditableÚ
UploadableÚ	componentc                   @  sÂ   e Zd Z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„Zdd„ Zddœdd„Zeej	ddddddfddd
d
ddd
dœdd„ƒZ
dddœdd„Zd dd!œd"d#„Zdd$d%œd&d'„ZdS ))ÚModel3DaV  
    Component allows users to upload or view 3D Model files (.obj, .glb, or .gltf).
    Preprocessing: This component passes the uploaded file as a {str}filepath.
    Postprocessing: expects function to return a {str} or {pathlib.Path} filepath of type (.obj, glb, or .gltf)

    Demos: model3D
    Guides: how-to-use-3D-model-component
    NTé    )
Úclear_colorÚlabelÚeveryÚ
show_labelÚ	containerÚscaleÚ	min_widthÚvisibleÚelem_idÚelem_classeszstr | Callable | Nonezlist[float] | Nonez
str | Nonezfloat | Nonezbool | NoneÚboolz
int | NoneÚintzlist[str] | str | None)Úvaluer   r   r   r   r   r   r   r   r   r   c       
         K  s:   |p
g d¢| _ tj| f|||||||	|
||dœ
|¤Ž dS )a  
        Parameters:
            value: path to (.obj, glb, or .gltf) file to show in model3D viewer. If callable, the function will be called whenever the app loads to set the initial value of the component.
            clear_color: background color of scene
            label: component name in interface.
            every: If `value` is a callable, run the function 'every' number of seconds while the client connection is open. Has no effect otherwise. Queue must be enabled. The event can be accessed (e.g. to cancel it) via this component's .load_event attribute.
            show_label: if True, will display label.
            container: If True, will place the component in a container - providing some extra padding around the border.
            scale: relative width compared to adjacent Components in a Row. For example, if Component A has scale=2, and Component B has scale=1, A will be twice as wide as B. Should be an integer.
            min_width: minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first.
            visible: If False, component will be hidden.
            elem_id: An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.
            elem_classes: An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles.
        )r   r   r   r   )
r   r   r   r   r   r   r   r   r   r    N)r   r   Ú__init__)Úselfr    r   r   r   r   r   r   r   r   r   r   Úkwargs© r$   úb/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/gradio/components/model3d.pyr!   $   s"    ÿõôzModel3D.__init__c                 C  s   | j | jdœt | ¡¥S )N)Z
clearColorr    )r   r    r   Ú
get_config©r"   r$   r$   r%   r&   R   s
    þýzModel3D.get_configzdict[str, Any])Úreturnc                 C  s   dt jdœddœS )NF)Úis_fileÚdatazFhttps://github.com/gradio-app/gradio/raw/main/test/test_files/Box.gltf)ÚrawZ
serialized)r   ZBASE64_MODEL3Dr'   r$   r$   r%   Úexample_inputsY   s    
þzModel3D.example_inputsz(Any | Literal[_Keywords.NO_VALUE] | None)r    r   r   r   r   r   r   c              	   C  s   ||||||| ddœ}|S )NÚupdate)r   r   r   r   r   r   r    Z__type__r$   )r    r   r   r   r   r   r   Zupdated_configr$   r$   r%   r-   _   s    ø
zModel3D.updatezdict[str, str] | None)Úxr(   c                 C  sL   |du r|S |d |d |  dd¡  }}}|r<|  |¡}n|  ||¡}|S )zÔ
        Parameters:
            x: JSON object with filename as 'name' property and base64 data as 'data' property
        Returns:
            string file path to temporary file with the 3D image model
        NÚnamer*   r)   F)ÚgetÚmake_temp_copy_if_neededZbase64_to_temp_file_if_needed)r"   r.   Ú	file_nameZ	file_datar)   Ztemp_file_pathr$   r$   r%   Ú
preprocessu   s    
ý
zModel3D.preprocesszstr | Path | None)Úyr(   c                 C  s"   |du r|S |   |¡dddœ}|S )z
        Parameters:
            y: path to the model
        Returns:
            file name mapped to base64 url data
        NT)r/   r*   r)   )r1   )r"   r4   r*   r$   r$   r%   ÚpostprocessŠ   s    ýzModel3D.postprocessÚstr)Ú
input_datar(   c                 C  s   |rt |ƒjS dS )NÚ )r   r/   )r"   r7   r$   r$   r%   Ú
as_exampleš   s    zModel3D.as_example)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r!   r&   r,   Ústaticmethodr   ZNO_VALUEr-   r3   r5   r9   r$   r$   r$   r%   r      s8    þó&.ùr   N)r=   Ú
__future__r   Úpathlibr   Útypingr   r   r   Zgradio_clientr   Zgradio_client.documentationr   r	   Zgradio_client.serializingr
   Zgradio.components.baser   r   Zgradio.eventsr   r   r   r   r   r$   r$   r$   r%   Ú<module>   s   
ÿ