o
    ॵi                     @   s   d dl Z d dlZd dlmZmZmZ d dlZd dlZd dl	Z	d dl
m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 d d	lmZ d d
lmZ e ZejejejdG dd deZdS )    N)AnyDictUnion)	Pipelines)ImageSkyChangePreprocessor)
OutputKeys)InputModelPipeline)	PIPELINES)	LoadImage)Tasks)
get_logger)module_namec                       sj   e Zd ZdZdef fddZdeeef deeef fddZd	eeef deeef fd
dZ	  Z
S )ImageSkychangePipelinea@  
    Image Sky Change Pipeline. Given two images(sky_image and scene_image), pipeline will replace the sky style
    of sky_image with the sky style of scene_image.

    Examples:

    >>> from modelscope.pipelines import pipeline
    >>> detector = pipeline('image-skychange', 'damo/cv_hrnetocr_skychange')
    >>> detector({
            'sky_image': 'sky_image.jpg', # sky_image path (str)
            'scene_image': 'scene_image.jpg', # scene_image path (str)
        })
    >>> {"output_img": [H * W * 3] 0~255, we can use cv2.imwrite to save output_img as an image.}
    modelc                    sT   t  jdd|i| t| jtstd td| jdu r#t	 | _t
d dS )a  
        use `model` to create a image sky change pipeline for image editing
        Args:
            model (`str` or `Model`): model_id on modelscope hub
            preprocessor(`Preprocessor`, *optional*,  defaults to None): `ImageSkyChangePreprocessor`.
        r   z model object is not initialized.Nzload model done )super__init__
isinstancer   r	   loggererror	Exceptionpreprocessorr   info)selfr   kwargs	__class__r   d/home/ubuntu/.local/lib/python3.10/site-packages/modelscope/pipelines/cv/image_skychange_pipeline.pyr   (   s   

zImageSkychangePipeline.__init__inputreturnc                 C   s   | j jdi |}tj|iS )Nr   )r   forwardr   
OUTPUT_IMG)r   r    resr   r   r   r"   7   s   
zImageSkychangePipeline.forwardinputsc                 C   s   |S )Nr   )r   r%   r   r   r   postprocess;   s   z"ImageSkychangePipeline.postprocess)__name__
__module____qualname____doc__strr   r   r   r"   r&   __classcell__r   r   r   r   r      s
    "*r   ) pdbtimetypingr   r   r   cv2numpynpPILmodelscope.metainfor   $modelscope.models.cv.image_skychanger   modelscope.outputsr   modelscope.pipelines.baser   r	   r
   modelscope.pipelines.builderr   modelscope.preprocessorsr   modelscope.utils.constantr   modelscope.utils.loggerr   r   register_moduleimage_skychanger   r   r   r   r   <module>   s&   