




import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin


UpperCamelCase__            =     """
Hugging 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.

In March 2021, Hugging Face raised $40 million in a Series B funding round.[3]

On 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]
"""
class      a__       (   unittest.TestCase					,							snake_case__ ):






						def 							__SCREAMING_SNAKE_CASE(  self     ):




											"""simple docstring"""



											__lowerCAmelCase							  =			load_tool("summarization"     )
											self.tool.setup()
											__lowerCAmelCase							  =			load_tool("summarization"						,     remote=_A     )






						def 							__SCREAMING_SNAKE_CASE(  self     ):




											"""simple docstring"""



											__lowerCAmelCase							  =			self.tool(_A     )
											self.assertEqual(
											    _A						,     "Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM."						,     )






						def 							__SCREAMING_SNAKE_CASE(  self     ):




											"""simple docstring"""



											__lowerCAmelCase							  =			self.remote_tool(_A     )
											self.assertEqual(
											    _A						,     "Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM."						,     )






						def 							__SCREAMING_SNAKE_CASE(  self     ):




											"""simple docstring"""



											__lowerCAmelCase							  =			self.tool(text=_A     )
											self.assertEqual(
											    _A						,     "Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM."						,     )






						def 							__SCREAMING_SNAKE_CASE(  self     ):




											"""simple docstring"""



											__lowerCAmelCase							  =			self.remote_tool(text=_A     )
											self.assertEqual(
											    _A						,     "Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM."						,     )










from typing import Any, Callable, Dict, List, Optional, Union

import PIL.Image
import torch
from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    DiffusionPipeline,
    LMSDiscreteScheduler,
    PNDMScheduler,
    StableDiffusionImgaImgPipeline,
    StableDiffusionInpaintPipelineLegacy,
    StableDiffusionPipeline,
    UNetaDConditionModel,
)
from diffusers.configuration_utils import FrozenDict
from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker
from diffusers.utils import deprecate, logging


UpperCamelCase__            =     logging.get_logger(__name__)  # pylint: disable=invalid-name
class      a__       (   snake_case__ ):
						_a				:       Tuple   =       ["""safety_checker""", """feature_extractor"""]






						def __init__(  self						,     _A						,     _A						,     _A						,     _A						,     _A						,     _A						,     _A						,     _A = True						,     ):




											"""simple docstring"""



											super().__init__()
											if hasattr(scheduler.config						,     "steps_offset"     ) and scheduler.config.steps_offset != 1:
																__lowerCAmelCase							  =			(
																    f"""The configuration file of this scheduler: {scheduler} is outdated. `steps_offset`"""
																    f""" should be set to 1 instead of {scheduler.config.steps_offset}. Please make sure """
																    "to update the config accordingly as leaving `steps_offset` might led to incorrect results"
																    " in future versions. If you have downloaded this checkpoint from the Hugging Face Hub,"
																    " it would be very nice if you could open a Pull request for the `scheduler/scheduler_config.json`"
																    " file"
																)
																deprecate("steps_offset!=1"						,     "1.0.0"						,     _A						,     standard_warn=_A     )
																__lowerCAmelCase							  =			dict(scheduler.config     )
																__lowerCAmelCase							  =			1
																__lowerCAmelCase							  =			FrozenDict(_A     )

											self.register_modules(
											    vae=_A						,     text_encoder=_A						,     tokenizer=_A						,     unet=_A						,     scheduler=_A						,     safety_checker=_A						,     feature_extractor=_A						,     )
											self.register_to_config(requires_safety_checker=_A     )






						@property
						def 							__SCREAMING_SNAKE_CASE(  self     ):




											"""simple docstring"""



											return {k: getattr(self						,     _A     ) for k in self.config.keys() if not k.startswith("_"     )}






						def 							__SCREAMING_SNAKE_CASE(  self						,     _A = "auto"     ):




											"""simple docstring"""



											if slice_size == "auto":
																# half the attention head size is usually a good trade-off between
																# speed and memory
																__lowerCAmelCase							  =			self.unet.config.attention_head_dim // 2
											self.unet.set_attention_slice(_A     )






						def 							__SCREAMING_SNAKE_CASE(  self     ):




											"""simple docstring"""



											self.enable_attention_slicing(_A     )






						@torch.no_grad()
						def 							__SCREAMING_SNAKE_CASE(  self						,     _A						,     _A						,     _A						,     _A = 0.8						,     _A = 5_0						,     _A = 7.5						,     _A = None						,     _A = 1						,     _A = 0.0						,     _A = None						,     _A = "pil"						,     _A = True						,     _A = None						,     _A = 1						,     ):




											"""simple docstring"""



											return StableDiffusionInpaintPipelineLegacy(**self.components     )(
											    prompt=_A						,     image=_A						,     mask_image=_A						,     strength=_A						,     num_inference_steps=_A						,     guidance_scale=_A						,     negative_prompt=_A						,     num_images_per_prompt=_A						,     eta=_A						,     generator=_A						,     output_type=_A						,     return_dict=_A						,     callback=_A						,     )






						@torch.no_grad()
						def 							__SCREAMING_SNAKE_CASE(  self						,     _A						,     _A						,     _A = 0.8						,     _A = 5_0						,     _A = 7.5						,     _A = None						,     _A = 1						,     _A = 0.0						,     _A = None						,     _A = "pil"						,     _A = True						,     _A = None						,     _A = 1						,     **_A						,     ):




											"""simple docstring"""



											return StableDiffusionImgaImgPipeline(**self.components     )(
											    prompt=_A						,     image=_A						,     strength=_A						,     num_inference_steps=_A						,     guidance_scale=_A						,     negative_prompt=_A						,     num_images_per_prompt=_A						,     eta=_A						,     generator=_A						,     output_type=_A						,     return_dict=_A						,     callback=_A						,     callback_steps=_A						,     )






						@torch.no_grad()
						def 							__SCREAMING_SNAKE_CASE(  self						,     _A						,     _A = 5_1_2						,     _A = 5_1_2						,     _A = 5_0						,     _A = 7.5						,     _A = None						,     _A = 1						,     _A = 0.0						,     _A = None						,     _A = None						,     _A = "pil"						,     _A = True						,     _A = None						,     _A = 1						,     ):




											"""simple docstring"""



											return StableDiffusionPipeline(**self.components     )(
											    prompt=_A						,     height=_A						,     width=_A						,     num_inference_steps=_A						,     guidance_scale=_A						,     negative_prompt=_A						,     num_images_per_prompt=_A						,     eta=_A						,     generator=_A						,     latents=_A						,     output_type=_A						,     return_dict=_A						,     callback=_A						,     callback_steps=_A						,     )




