
    fTh                         S SK JrJr  S SKrSSKJrJrJrJ	r	J
r
  SSKJrJr  \" 5       (       a  S SKJr  SSKJr  \" 5       (       a  SS	KJr  \	R(                  " \5      r\" \" S
S95       " S S\5      5       rg)    )ListUnionN   )add_end_docstringsis_torch_availableis_vision_availableloggingrequires_backends   )Pipelinebuild_pipeline_init_args)Image)
load_image)&MODEL_FOR_IMAGE_TO_IMAGE_MAPPING_NAMEST)has_image_processorc                      ^  \ rS rSrSrU 4S jrS rS\\\	\   S\	S   4   S\S\	S   4   4U 4S jjr
S	 rSS
 jrS rSrU =r$ )ImageToImagePipeline'   a  
Image to Image pipeline using any `AutoModelForImageToImage`. This pipeline generates an image based on a previous
image input.

Example:

```python
>>> from PIL import Image
>>> import requests

>>> from transformers import pipeline

>>> upscaler = pipeline("image-to-image", model="caidas/swin2SR-classical-sr-x2-64")
>>> img = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw)
>>> img = img.resize((64, 64))
>>> upscaled_img = upscaler(img)
>>> img.size
(64, 64)

>>> upscaled_img.size
(144, 144)
```

This image to image pipeline can currently be loaded from [`pipeline`] using the following task identifier:
`"image-to-image"`.

See the list of available models on [huggingface.co/models](https://huggingface.co/models?filter=image-to-image).
c                 h   > [         TU ]  " U0 UD6  [        U S5        U R                  [        5        g )Nvision)super__init__r
   check_model_typer   )selfargskwargs	__class__s      ]/var/www/auris/envauris/lib/python3.13/site-packages/transformers/pipelines/image_to_image.pyr   ImageToImagePipeline.__init__F   s.    $)&)$)DE    c                 N    0 n0 n0 nSU;   a  US   US'   SU;   a  US   US'   X$U4$ )Ntimeout	head_mask )r   r   preprocess_paramspostprocess_paramsforward_paramss        r   _sanitize_parameters)ImageToImagePipeline._sanitize_parametersK   sN    +1)+<i(& *0*=N;' 2DDDr    imageszImage.Imagereturnc                 &   > [         TU ]  " U40 UD6$ )a  
Transform the image(s) passed as inputs.

Args:
    images (`str`, `List[str]`, `PIL.Image` or `List[PIL.Image]`):
        The pipeline handles three types of images:

        - A string containing a http link pointing to an image
        - A string containing a local path to an image
        - An image loaded in PIL directly

        The pipeline accepts either a single image or a batch of images, which must then be passed as a string.
        Images in a batch must all be in the same format: all as http links, all as local paths, or all as PIL
        images.
    timeout (`float`, *optional*, defaults to None):
        The maximum time in seconds to wait for fetching images from the web. If None, no timeout is used and
        the call may block forever.

Return:
    An image (Image.Image) or a list of images (List["Image.Image"]) containing result(s). If the input is a
    single image, the return will be also a single image, if the input is a list of several images, it will
    return a list of transformed images.
)r   __call__)r   r*   r   r   s      r   r-   ImageToImagePipeline.__call__W   s    4 w1&11r    c                 *    U R                   " S0 UD6nU$ )Nr$   )model)r   model_inputsmodel_outputss      r   _forwardImageToImagePipeline._forwards   s    

2\2r    c                     [        XS9nU R                  U/SS9nU R                  S:X  a  UR                  U R                  5      nU$ )N)r"   pt)r*   return_tensors)r   image_processor	frameworktotorch_dtype)r   imager"   inputss       r   
preprocessImageToImagePipeline.preprocessw   sH    52%%eWT%J>>T!YYt//0Fr    c                    / nSUR                  5       ;   a  UR                  nW H  nUR                  R                  5       R	                  5       R                  5       R                  SS5      R                  5       n[        R                  " USSS9nUS-  R                  5       R                  [        R                  5      nUR                  [        R                  " U5      5        M     [!        U5      S:  a  U$ US   $ )Nreconstructionr   r   )sourcedestinationg     o@)keysrA   datasqueezefloatcpuclamp_numpynpmoveaxisroundastypeuint8appendr   	fromarraylen)r   r2   r*   outputsoutputs        r   postprocess ImageToImagePipeline.postprocess~   s    }1133#22GF[[((*002668??1EKKMF[[rBFun++-44RXX>FMM%//&12	  Vqv7fQi7r    r$   )N)__name__
__module____qualname____firstlineno____doc__r   r(   r   strr   r-   r3   r>   rV   __static_attributes____classcell__)r   s   @r   r   r   '   sc    :F

E2CcM4;NNO2	}d=11	228
8 
8r    r   )typingr   r   rK   rL   utilsr   r   r   r	   r
   baser   r   PILr   image_utilsr   models.auto.modeling_autor   
get_loggerrX   loggerr   r$   r    r   <module>rh      ss       5 (R			H	% ,FG`88 `8 H`8r    