

import functools
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

import huggingface_hub.utils as hf_hub_utils
from tqdm import auto as tqdm_lib


SCREAMING_SNAKE_CASE_        =      threading.Lock()
SCREAMING_SNAKE_CASE_        =      None

SCREAMING_SNAKE_CASE_        =      {
    'debug': logging.DEBUG,
    'info': logging.INFO,
    'warning': logging.WARNING,
    'error': logging.ERROR,
    'critical': logging.CRITICAL,
}

SCREAMING_SNAKE_CASE_        =      logging.WARNING

SCREAMING_SNAKE_CASE_        =      True

def 	__SCREAMING_SNAKE_CASE							(				)   ->       List[Any]:
				_UpperCAmelCase       :		Dict 		=    os.getenv("TRANSFORMERS_VERBOSITY"  ,      _A )
				if env_level_str:
								if env_level_str in log_levels:
												return log_levels[env_level_str]
								else:
												logging.getLogger().warning(
												    F'Unknown option TRANSFORMERS_VERBOSITY={env_level_str}, '
												    F'has to be one of: { ", ".join(log_levels.keys() ) }' )
				return _default_log_level

def 	__SCREAMING_SNAKE_CASE							(				)   ->       str:
				return __name__.split("." )[0]

def 	__SCREAMING_SNAKE_CASE							(				)   ->       logging.Logger:
				return logging.getLogger(_get_library_name() )

def 	__SCREAMING_SNAKE_CASE							(				)   ->       None:
				global _default_handler

				with _lock:
								if _default_handler:
												# This library has already configured the library root logger.
												return
								_UpperCAmelCase       :		Optional[int] 		=    logging.StreamHandler()  # Set sys.stderr as stream.
								_UpperCAmelCase       :		List[str] 		=    sys.stderr.flush

								# Apply our default configuration to the library root logger.
								_UpperCAmelCase       :		Any 		=    _get_library_root_logger()
								library_root_logger.addHandler(_default_handler )
								library_root_logger.setLevel(_get_default_logging_level() )
								_UpperCAmelCase       :		List[Any] 		=    False

def 	__SCREAMING_SNAKE_CASE							(				)   ->       None:
				global _default_handler

				with _lock:
								if not _default_handler:
												return

								_UpperCAmelCase       :		Optional[int] 		=    _get_library_root_logger()
								library_root_logger.removeHandler(_default_handler )
								library_root_logger.setLevel(logging.NOTSET )
								_UpperCAmelCase       :		Optional[int] 		=    None

def 	__SCREAMING_SNAKE_CASE							(				)   ->       Optional[int]:
				return log_levels

def 	__SCREAMING_SNAKE_CASE							(				lowerCAmelCase:  Optional[str] = None )   ->       logging.Logger:

				if name is None:
								_UpperCAmelCase       :		Tuple 		=    _get_library_name()

				_configure_library_root_logger()
				return logging.getLogger(_A )

def 	__SCREAMING_SNAKE_CASE							(				)   ->       int:
				_configure_library_root_logger()
				return _get_library_root_logger().getEffectiveLevel()

def 	__SCREAMING_SNAKE_CASE							(				lowerCAmelCase:  int )   ->       None:
				_configure_library_root_logger()
				_get_library_root_logger().setLevel(_A )

def 	__SCREAMING_SNAKE_CASE							(				)   ->       int:
				return set_verbosity(_A )

def 	__SCREAMING_SNAKE_CASE							(				)   ->       List[Any]:
				return set_verbosity(_A )

def 	__SCREAMING_SNAKE_CASE							(				)   ->       Tuple:
				return set_verbosity(_A )

def 	__SCREAMING_SNAKE_CASE							(				)   ->       List[Any]:
				return set_verbosity(_A )

def 	__SCREAMING_SNAKE_CASE							(				)   ->       None:
				_configure_library_root_logger()

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

def 	__SCREAMING_SNAKE_CASE							(				)   ->       None:
				_configure_library_root_logger()

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

def 	__SCREAMING_SNAKE_CASE							(				lowerCAmelCase:  logging.Handler )   ->       None:
				_configure_library_root_logger()

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

def 	__SCREAMING_SNAKE_CASE							(				lowerCAmelCase:  logging.Handler )   ->       None:
				_configure_library_root_logger()

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

def 	__SCREAMING_SNAKE_CASE							(				)   ->       None:
				_configure_library_root_logger()
				_UpperCAmelCase       :		Dict 		=    False

def 	__SCREAMING_SNAKE_CASE							(				)   ->       None:
				_configure_library_root_logger()
				_UpperCAmelCase       :		Optional[Any] 		=    True

def 	__SCREAMING_SNAKE_CASE							(				)   ->       None:
				_UpperCAmelCase       :		int 		=    _get_library_root_logger().handlers

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

def 	__SCREAMING_SNAKE_CASE							(				)   ->       None:
				_UpperCAmelCase       :		List[str] 		=    _get_library_root_logger().handlers

				for handler in handlers:
								handler.setFormatter(_A )

def 	__SCREAMING_SNAKE_CASE							(				self:  List[str]  ,      *lowerCAmelCase:  str  ,      **lowerCAmelCase:  Any )   ->       Union[str, Any]:
				_UpperCAmelCase       :		Optional[Any] 		=    os.getenv("TRANSFORMERS_NO_ADVISORY_WARNINGS"  ,      _A )
				if no_advisory_warnings:
								return
				self.warning(*_A  ,      **_A )


SCREAMING_SNAKE_CASE_        =      warning_advice

@functools.lru_cache(_A )
def 	__SCREAMING_SNAKE_CASE							(				self:  List[Any]  ,      *lowerCAmelCase:  int  ,      **lowerCAmelCase:  Tuple )   ->       str:
				self.warning(*_A  ,      **_A )


SCREAMING_SNAKE_CASE_        =      warning_once

class 				a  :


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







										'''simple docstring'''


										_UpperCAmelCase       :		str 		=    args[0] if args else None


						def __iter__(       self	):







										'''simple docstring'''


										return iter(self._iterator	)


						def __getattr__(       self						,					A_	):







										'''simple docstring'''


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

										return empty_fn


						def __enter__(       self	):







										'''simple docstring'''


										return self





						def __exit__(       self						,					A_						,					A_						,					A_	):







										'''simple docstring'''


										return







class 				a  :


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







										'''simple docstring'''


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


						def        _UpperCAmelCase				(       self						,					*A_						,					**A_	):







										'''simple docstring'''


										_UpperCAmelCase       :		Optional[int] 		=    None
										if _tqdm_active:
														return tqdm_lib.tqdm.set_lock(*_SCREAMING_SNAKE_CASE						,					**_SCREAMING_SNAKE_CASE	)





						def        _UpperCAmelCase				(       self	):







										'''simple docstring'''


										if _tqdm_active:
														return tqdm_lib.tqdm.get_lock()







SCREAMING_SNAKE_CASE_        =      _tqdm_cls()

def 	__SCREAMING_SNAKE_CASE							(				)   ->       bool:
				global _tqdm_active
				return bool(_tqdm_active )

def 	__SCREAMING_SNAKE_CASE							(				)   ->       Any:
				global _tqdm_active
				_UpperCAmelCase       :		Any 		=    True
				hf_hub_utils.enable_progress_bars()





def 	__SCREAMING_SNAKE_CASE							(				)   ->       Tuple:
				global _tqdm_active
				_UpperCAmelCase       :		int 		=    False
				hf_hub_utils.disable_progress_bars()





import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin


SCREAMING_SNAKE_CASE_        =      '\nHugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf originally as a company that developed a chatbot app targeted at teenagers.[2] After open-sourcing the model behind the chatbot, the company pivoted to focus on being a platform for machine learning.\n\nIn March 2021, Hugging Face raised $40 million in a Series B funding round.[3]\n\nOn April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model.[4] In 2022, the workshop concluded with the announcement of BLOOM, a multilingual large language model with 176 billion parameters.[5]\n'

class 				a  (	unittest.TestCase							, UpperCAmelCase				):


						def        _UpperCAmelCase				(       self	):







										'''simple docstring'''


										_UpperCAmelCase       :		Tuple 		=    load_tool("text-question-answering"	)
										self.tool.setup()
										_UpperCAmelCase       :		str 		=    load_tool("text-question-answering"						,					remote=A_	)


						def        _UpperCAmelCase				(       self	):







										'''simple docstring'''


										_UpperCAmelCase       :		List[str] 		=    self.tool(A_						,					"What did Hugging Face do in April 2021?"	)
										self.assertEqual(A_						,					"launched the BigScience Research Workshop"	)


						def        _UpperCAmelCase				(       self	):







										'''simple docstring'''


										_UpperCAmelCase       :		Optional[Any] 		=    self.remote_tool(A_						,					"What did Hugging Face do in April 2021?"	)
										self.assertEqual(A_						,					"launched the BigScience Research Workshop"	)


						def        _UpperCAmelCase				(       self	):







										'''simple docstring'''


										_UpperCAmelCase       :		int 		=    self.tool(text=A_						,					question="What did Hugging Face do in April 2021?"	)
										self.assertEqual(A_						,					"launched the BigScience Research Workshop"	)





						def        _UpperCAmelCase				(       self	):







										'''simple docstring'''


										_UpperCAmelCase       :		List[Any] 		=    self.remote_tool(text=A_						,					question="What did Hugging Face do in April 2021?"	)
										self.assertEqual(A_						,					"launched the BigScience Research Workshop"	)


