




'''simple docstring'''




import unittest
from dataclasses import dataclass
from typing import List, Union

import numpy as np
import PIL.Image

from diffusers.utils.outputs import BaseOutput

@dataclass
class 						lowerCAmelCase_   ( lowerCamelCase_   ):







  '''simple docstring'''







  lowerCAmelCase_				:					Union[List[PIL.Image.Image], np.ndarray]

class 						lowerCAmelCase_   ( unittest.TestCase   ):







  '''simple docstring'''







  def 							SCREAMING_SNAKE_CASE__			(						self    :	Optional[Any] ):






   """simple docstring"""






   UpperCAmelCase__										=    CustomOutput(images=np.random.rand(1						,		3						,		4						,		4 ) )

   # check every way of getting the attribute
   assert isinstance(outputs.images						,		np.ndarray )
   assert outputs.images.shape == (1, 3, 4, 4)
   assert isinstance(outputs["""images"""]						,		np.ndarray )
   assert outputs["images"].shape == (1, 3, 4, 4)
   assert isinstance(outputs[0]						,		np.ndarray )
   assert outputs[0].shape == (1, 3, 4, 4)

   # test with a non-tensor attribute
   UpperCAmelCase__										=    CustomOutput(images=[PIL.Image.new("""RGB"""						,		(4, 4) )] )

   # check every way of getting the attribute
   assert isinstance(outputs.images						,		_UpperCAmelCase )
   assert isinstance(outputs.images[0]						,		PIL.Image.Image )
   assert isinstance(outputs["""images"""]						,		_UpperCAmelCase )
   assert isinstance(outputs["""images"""][0]						,		PIL.Image.Image )
   assert isinstance(outputs[0]						,		_UpperCAmelCase )
   assert isinstance(outputs[0][0]						,		PIL.Image.Image )



  def 							SCREAMING_SNAKE_CASE__			(						self    :	int ):






   """simple docstring"""






   UpperCAmelCase__										=    CustomOutput({"""images""": np.random.rand(1						,		3						,		4						,		4 )} )

   # check every way of getting the attribute
   assert isinstance(outputs.images						,		np.ndarray )
   assert outputs.images.shape == (1, 3, 4, 4)
   assert isinstance(outputs["""images"""]						,		np.ndarray )
   assert outputs["images"].shape == (1, 3, 4, 4)
   assert isinstance(outputs[0]						,		np.ndarray )
   assert outputs[0].shape == (1, 3, 4, 4)

   # test with a non-tensor attribute
   UpperCAmelCase__										=    CustomOutput({"""images""": [PIL.Image.new("""RGB"""						,		(4, 4) )]} )

   # check every way of getting the attribute
   assert isinstance(outputs.images						,		_UpperCAmelCase )
   assert isinstance(outputs.images[0]						,		PIL.Image.Image )
   assert isinstance(outputs["""images"""]						,		_UpperCAmelCase )
   assert isinstance(outputs["""images"""][0]						,		PIL.Image.Image )
   assert isinstance(outputs[0]						,		_UpperCAmelCase )
   assert isinstance(outputs[0][0]						,		PIL.Image.Image )






'''simple docstring'''




import os

from apache_beam.io.filesystems import FileSystems
from apache_beam.pipeline import Pipeline

from .logging import get_logger


UpperCAmelCase_       				=      2 << 2_0  # 2mb
UpperCAmelCase_       				=      get_logger(__name__)

class 						lowerCAmelCase_   ( lowerCamelCase_   ):







  '''simple docstring'''







  def 							SCREAMING_SNAKE_CASE__			(						self    :	Any ):






   """simple docstring"""






   UpperCAmelCase__										=    self._options.get_all_options().get("""runner""" )
   return runner in [None, "DirectRunner", "PortableRunner"]

def    _UpperCamelCase      (				SCREAMING_SNAKE_CASE__			:      Any       ,						SCREAMING_SNAKE_CASE__			:      List[Any]       ,						SCREAMING_SNAKE_CASE__			:      Any=False       ):
 '''simple docstring'''





 UpperCAmelCase__										=    FileSystems
 if fs.exists(SCREAMING_SNAKE_CASE__       ):
  if force_upload:
   logger.info(F'''Remote path already exist: {remote_file_path}. Overwriting it as force_upload=True.'''       )
  else:
   logger.info(F'''Remote path already exist: {remote_file_path}. Skipping it as force_upload=False.'''       )
   return
 with fs.create(SCREAMING_SNAKE_CASE__       ) as remote_file:
  with open(SCREAMING_SNAKE_CASE__       ,						"""rb"""       ) as local_file:
   UpperCAmelCase__										=    local_file.read(SCREAMING_SNAKE_CASE__       )
   while chunk:
    remote_file.write(SCREAMING_SNAKE_CASE__       )
    UpperCAmelCase__										=    local_file.read(SCREAMING_SNAKE_CASE__       )







def    _UpperCamelCase      (				SCREAMING_SNAKE_CASE__			:      Dict       ,						SCREAMING_SNAKE_CASE__			:      Any       ,						SCREAMING_SNAKE_CASE__			:      Dict=False       ):
 '''simple docstring'''





 UpperCAmelCase__										=    FileSystems
 if os.path.exists(SCREAMING_SNAKE_CASE__       ):
  if force_download:
   logger.info(F'''Local path already exist: {remote_file_path}. Overwriting it as force_upload=True.'''       )
  else:
   logger.info(F'''Local path already exist: {remote_file_path}. Skipping it as force_upload=False.'''       )
   return
 with fs.open(SCREAMING_SNAKE_CASE__       ) as remote_file:
  with open(SCREAMING_SNAKE_CASE__       ,						"""wb"""       ) as local_file:
   UpperCAmelCase__										=    remote_file.read(SCREAMING_SNAKE_CASE__       )
   while chunk:
    local_file.write(SCREAMING_SNAKE_CASE__       )
    UpperCAmelCase__										=    remote_file.read(SCREAMING_SNAKE_CASE__       )
