o
    ۷i                     @   s   d Z ddlZddlmZ ddlmZ eejd Zdde	dee	 de	fd	d
Z
ddee	 de	fddZddee	 de	fddZddee	 de	fddZddee	 de	fddZddee	 de	fddZdS )a2  
Media Registry for Gradio Demos

This module provides a centralized way to access media files.

Usage:
    from gradio.media import get_image, get_video, get_audio, get_model3d, get_file

    # Get specific media files
    cheetah_img = get_image("cheetah1.jpg")
    world_video = get_video("world.mp4")
    cantina_audio = get_audio("cantina.wav")
    bunny_model = get_model3d("Bunny.obj")
    titanic_data = get_file("titanic.csv")

    # Get random media of a type
    random_img = get_image()
    random_video = get_video()
    random_audio = get_audio()

    N)Path)Optionalmedia_assets
media_typefilenamereturnc                 C   s   t |  }| std| |du r)t|d}|s#td| t|}n|dr0|S || }| s?td| t	|
 S )a  
    Internal function to get the path to a media file.

    Args:
        media_type: Type of media (images, videos, audio, models3d, data)
        filename: Optional filename of the media file. If None, returns a random file.

    Returns:
        Absolute path to the media file

    Raises:
        ValueError: If media_type is invalid
        FileNotFoundError: If the media file doesn't exist
    zMedia directory not found: N*zNo media files found in )zhttp://zhttps://zMedia file not found: )
MEDIA_ROOTexists
ValueErrorlistglobrandomchoice
startswithFileNotFoundErrorstrabsolute)r   r   	media_dirmedia_files	file_path r   B/home/ubuntu/vllm_env/lib/python3.10/site-packages/gradio/media.py_get_media_path   s   
r   c                 C   
   t d| S )a7  
    Get path to an image file.

    Args:
        filename: Filename of the image (e.g., "tower.jpg"). If None, returns a random image.

    Returns:
        Absolute path to the image file

    Examples:
        >>> get_image("tower.jpg")  # Get specific image
        >>> get_image()  # Get random image
    imagesr   r   r   r   r   	get_imageD      
r   c                 C   r   )a6  
    Get path to a video file.

    Args:
        filename: Filename of the video (e.g., "world.mp4"). If None, returns a random video.

    Returns:
        Absolute path to the video file

    Examples:
        >>> get_video("world.mp4")  # Get specific video
        >>> get_video()  # Get random video
    videosr   r   r   r   r   	get_videoU   r   r!   c                 C   r   )a@  
    Get path to an audio file.

    Args:
        filename: Filename of the audio (e.g., "cantina.wav"). If None, returns a random audio file.

    Returns:
        Absolute path to the audio file

    Examples:
        >>> get_audio("cantina.wav")  # Get specific audio
        >>> get_audio()  # Get random audio
    audior   r   r   r   r   	get_audiof   r   r#   c                 C   r   )aD  
    Get path to a 3D model file.

    Args:
        filename: Filename of the 3D model (e.g., "Duck.glb"). If None, returns a random model.

    Returns:
        Absolute path to the 3D model file

    Examples:
        >>> get_model3d("Duck.glb")  # Get specific model
        >>> get_model3d()  # Get random 3D model
    models3dr   r   r   r   r   get_model3dw   r   r%   c                 C   r   )aT  
    Get path to a data file (CSV, JSON, text, etc.).

    Args:
        filename: Filename of the data file (e.g., "titanic.csv"). If None, returns a random file.

    Returns:
        Absolute path to the data file

    Examples:
        >>> get_file("titanic.csv")  # Get specific file
        >>> get_file()  # Get random data file
    datar   r   r   r   r   get_file   r   r'   )N)__doc__r   pathlibr   typingr   __file__parentr	   r   r   r   r!   r#   r%   r'   r   r   r   r   <module>   s    &