





"""simple docstring"""
import logging
import os
import sys
import threading
from logging import (
    CRITICAL,  # NOQA
    DEBUG,  # NOQA
    ERROR,  # NOQA
    FATAL,  # NOQA
    INFO,  # NOQA
    NOTSET,  # NOQA
    WARN,  # NOQA
    WARNING,  # NOQA
)
from typing import Optional

from tqdm import auto as tqdm_lib


__UpperCamelCase    :	List[str]						=     threading.Lock()
__UpperCamelCase    :	Optional[logging.Handler]						=     None

__UpperCamelCase    :	Optional[Any]						=     {
    '''debug''': logging.DEBUG,
    '''info''': logging.INFO,
    '''warning''': logging.WARNING,
    '''error''': logging.ERROR,
    '''critical''': logging.CRITICAL,
}

__UpperCamelCase    :	Union[str, Any]						=     logging.WARNING

__UpperCamelCase    :	int						=     True

def 		_SCREAMING_SNAKE_CASE ():
 lowerCAmelCase													=   os.getenv('DIFFUSERS_VERBOSITY'     ,    _UpperCAmelCase )
 if env_level_str:
  if env_level_str in log_levels:
   return log_levels[env_level_str]
  else:
   logging.getLogger().warning(
       F'Unknown option DIFFUSERS_VERBOSITY={env_level_str}, '
       F'has to be one of: { ", ".join(log_levels.keys() ) }' )
 return _default_log_level

def 		_SCREAMING_SNAKE_CASE ():
 return __name__.split('.' )[0]

def 		_SCREAMING_SNAKE_CASE ():
 return logging.getLogger(_get_library_name() )

def 		_SCREAMING_SNAKE_CASE ():
 global _default_handler

 with _lock:
  if _default_handler:
   # This library has already configured the library root logger.
   return
  lowerCAmelCase													=   logging.StreamHandler()  # Set sys.stderr as stream.
  lowerCAmelCase													=   sys.stderr.flush

  # Apply our default configuration to the library root logger.
  lowerCAmelCase													=   _get_library_root_logger()
  library_root_logger.addHandler(_default_handler )
  library_root_logger.setLevel(_get_default_logging_level() )
  lowerCAmelCase													=   False

def 		_SCREAMING_SNAKE_CASE ():
 global _default_handler

 with _lock:
  if not _default_handler:
   return

  lowerCAmelCase													=   _get_library_root_logger()
  library_root_logger.removeHandler(_default_handler )
  library_root_logger.setLevel(logging.NOTSET )
  lowerCAmelCase													=   None

def 		_SCREAMING_SNAKE_CASE ():
 return log_levels

def 		_SCREAMING_SNAKE_CASE (_UpperCAmelCase				:						Optional[str] = None ):

 if name is None:
  lowerCAmelCase													=   _get_library_name()

 _configure_library_root_logger()
 return logging.getLogger(_UpperCAmelCase )

def 		_SCREAMING_SNAKE_CASE ():
 _configure_library_root_logger()
 return _get_library_root_logger().getEffectiveLevel()

def 		_SCREAMING_SNAKE_CASE (_UpperCAmelCase				:						int ):
 _configure_library_root_logger()
 _get_library_root_logger().setLevel(_UpperCAmelCase )

def 		_SCREAMING_SNAKE_CASE ():
 return set_verbosity(_UpperCAmelCase )

def 		_SCREAMING_SNAKE_CASE ():
 return set_verbosity(_UpperCAmelCase )

def 		_SCREAMING_SNAKE_CASE ():
 return set_verbosity(_UpperCAmelCase )

def 		_SCREAMING_SNAKE_CASE ():
 return set_verbosity(_UpperCAmelCase )

def 		_SCREAMING_SNAKE_CASE ():
 _configure_library_root_logger()

 assert _default_handler is not None
 _get_library_root_logger().removeHandler(_default_handler )

def 		_SCREAMING_SNAKE_CASE ():
 _configure_library_root_logger()

 assert _default_handler is not None
 _get_library_root_logger().addHandler(_default_handler )

def 		_SCREAMING_SNAKE_CASE (_UpperCAmelCase				:						logging.Handler ):
 _configure_library_root_logger()

 assert handler is not None
 _get_library_root_logger().addHandler(_UpperCAmelCase )

def 		_SCREAMING_SNAKE_CASE (_UpperCAmelCase				:						logging.Handler ):
 _configure_library_root_logger()

 assert handler is not None and handler not in _get_library_root_logger().handlers
 _get_library_root_logger().removeHandler(_UpperCAmelCase )

def 		_SCREAMING_SNAKE_CASE ():
 _configure_library_root_logger()
 lowerCAmelCase													=   False

def 		_SCREAMING_SNAKE_CASE ():
 _configure_library_root_logger()
 lowerCAmelCase													=   True

def 		_SCREAMING_SNAKE_CASE ():
 lowerCAmelCase													=   _get_library_root_logger().handlers

 for handler in handlers:
  lowerCAmelCase													=   logging.Formatter('[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s >> %(message)s' )
  handler.setFormatter(_UpperCAmelCase )

def 		_SCREAMING_SNAKE_CASE ():
 lowerCAmelCase													=   _get_library_root_logger().handlers

 for handler in handlers:
  handler.setFormatter(_UpperCAmelCase )

def 		_SCREAMING_SNAKE_CASE (self				:						Optional[Any]     ,    *_UpperCAmelCase				:						Optional[int]     ,    **_UpperCAmelCase				:						Dict ):
 lowerCAmelCase													=   os.getenv('DIFFUSERS_NO_ADVISORY_WARNINGS'     ,    _UpperCAmelCase )
 if no_advisory_warnings:
  return
 self.warning(*_UpperCAmelCase     ,    **_UpperCAmelCase )


__UpperCamelCase    :	Dict						=     warning_advice







class 			a       :



 def __init__(    self							,					*_snake_case							,					**_snake_case    ):  # pylint: disable=unused-argument







  """simple docstring"""






  lowerCAmelCase													=   args[0] if args else None



 def __iter__(    self    ):







  """simple docstring"""






  return iter(self._iterator    )



 def __getattr__(    self							,					_snake_case    ):







  """simple docstring"""






  def empty_fn(*_snake_case							,					**_snake_case    ):  # pylint: disable=unused-argument
   return

  return empty_fn



 def __enter__(    self    ):







  """simple docstring"""






  return self



 def __exit__(    self							,					_snake_case							,					_snake_case							,					_snake_case    ):







  """simple docstring"""






  return







class 			a       :



 def __call__(    self							,					*_snake_case							,					**_snake_case    ):







  """simple docstring"""






  if _tqdm_active:
   return tqdm_lib.tqdm(*_snake_case							,					**_snake_case    )
  else:
   return EmptyTqdm(*_snake_case							,					**_snake_case    )



 def       UpperCamelCase__     (    self							,					*_snake_case							,					**_snake_case    ):







  """simple docstring"""






  lowerCAmelCase													=   None
  if _tqdm_active:
   return tqdm_lib.tqdm.set_lock(*_snake_case							,					**_snake_case    )



 def       UpperCamelCase__     (    self    ):







  """simple docstring"""






  if _tqdm_active:
   return tqdm_lib.tqdm.get_lock()


__UpperCamelCase    :	Optional[Any]						=     _tqdm_cls()

def 		_SCREAMING_SNAKE_CASE ():
 global _tqdm_active
 return bool(_tqdm_active )

def 		_SCREAMING_SNAKE_CASE ():
 global _tqdm_active
 lowerCAmelCase													=   True




def 		_SCREAMING_SNAKE_CASE ():
 global _tqdm_active
 lowerCAmelCase													=   False












"""simple docstring"""
import unittest
from pathlib import Path

from transformers import is_vision_available, load_tool
from transformers.testing_utils import get_tests_dir

from .test_tools_common import ToolTesterMixin


if is_vision_available():
       from PIL import Image







class 			a       (      unittest.TestCase      ,   a__     ):



 def       UpperCamelCase__     (    self    ):







  """simple docstring"""






  lowerCAmelCase													=   load_tool('image-question-answering'    )
  self.tool.setup()
  lowerCAmelCase													=   load_tool('image-question-answering'							,					remote=_snake_case    )



 def       UpperCamelCase__     (    self    ):







  """simple docstring"""






  lowerCAmelCase													=   Image.open(Path(get_tests_dir('fixtures/tests_samples/COCO'    )    ) / '000000039769.png'    )
  lowerCAmelCase													=   self.tool(_snake_case							,					'How many cats are sleeping on the couch?'    )
  self.assertEqual(_snake_case							,					'2'    )



 def       UpperCamelCase__     (    self    ):







  """simple docstring"""






  lowerCAmelCase													=   Image.open(Path(get_tests_dir('fixtures/tests_samples/COCO'    )    ) / '000000039769.png'    )
  lowerCAmelCase													=   self.remote_tool(_snake_case							,					'How many cats are sleeping on the couch?'    )
  self.assertEqual(_snake_case							,					'2'    )



 def       UpperCamelCase__     (    self    ):







  """simple docstring"""






  lowerCAmelCase													=   Image.open(Path(get_tests_dir('fixtures/tests_samples/COCO'    )    ) / '000000039769.png'    )
  lowerCAmelCase													=   self.tool(image=_snake_case							,					question='How many cats are sleeping on the couch?'    )
  self.assertEqual(_snake_case							,					'2'    )



 def       UpperCamelCase__     (    self    ):







  """simple docstring"""






  lowerCAmelCase													=   Image.open(Path(get_tests_dir('fixtures/tests_samples/COCO'    )    ) / '000000039769.png'    )
  lowerCAmelCase													=   self.remote_tool(image=_snake_case							,					question='How many cats are sleeping on the couch?'    )
  self.assertEqual(_snake_case							,					'2'    )





