



'''simple docstring'''




import unittest

from transformers import MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING, AutoTokenizer, is_vision_available
from transformers.pipelines import pipeline
from transformers.pipelines.document_question_answering import apply_tesseract
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_detectrona,
    require_pytesseract,
    require_tf,
    require_torch,
    require_vision,
    slow,
)

from .test_pipelines_common import ANY


if is_vision_available():
							from PIL import Image

							from transformers.image_utils import load_image
else:

							class 			UpperCamelCase_ :





								@staticmethod
								def  _lowercase(  *A		,		**A    )			->			int:
															pass




							def       __lowerCamelCase  (					_lowercase		)      ->			Any:
														return None


# This is a pinned image from a specific revision of a document question answering space, hosted by HuggingFace,
# so we can expect it to be available.
a   :			Dict					  =    (
    """https://huggingface.co/spaces/impira/docquery/resolve/2f6c96314dc84dfda62d40de9da55f2f5165d403/invoice.png"""
)

@is_pipeline_test
@require_torch
@require_vision
class 			UpperCamelCase_ (							unittest.TestCase			):
	lowercase          = MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING





	@require_pytesseract
	@require_vision
	def  _lowercase(  self		,		A		,		A		,		A    )			->			Optional[int]:
								UpperCAmelCase     :		int							     =		pipeline(
								    """document-question-answering"""		,		model=UpperCAmelCase__		,		tokenizer=UpperCAmelCase__		,		image_processor=UpperCAmelCase__    )

								UpperCAmelCase     :		Optional[int]							     =		INVOICE_URL
								UpperCAmelCase     :		Dict							     =		list(zip(*apply_tesseract(load_image(UpperCAmelCase__    )		,		UpperCAmelCase__		,		""""""    )    )    )
								UpperCAmelCase     :		Optional[Any]							     =		"""What is the placebo?"""
								UpperCAmelCase     :		Dict							     =		[
								    {
								        """image""": load_image(UpperCAmelCase__    ),
								        """question""": question,
								    },
								    {
								        """image""": image,
								        """question""": question,
								    },
								    {
								        """image""": image,
								        """question""": question,
								        """word_boxes""": word_boxes,
								    },
								]
								return dqa_pipeline, examples





	def  _lowercase(  self		,		A		,		A    )			->			Union[str, Any]:
								UpperCAmelCase     :		int							     =		dqa_pipeline(UpperCAmelCase__		,		top_k=2    )
								self.assertEqual(
								    UpperCAmelCase__		,		[
								        [
								            {"""score""": ANY(UpperCAmelCase__    ), """answer""": ANY(UpperCAmelCase__    ), """start""": ANY(UpperCAmelCase__    ), """end""": ANY(UpperCAmelCase__    )},
								            {"""score""": ANY(UpperCAmelCase__    ), """answer""": ANY(UpperCAmelCase__    ), """start""": ANY(UpperCAmelCase__    ), """end""": ANY(UpperCAmelCase__    )},
								        ]
								    ]
								    * 3		,		)





	@require_torch
	@require_detectrona
	@require_pytesseract
	def  _lowercase(  self    )			->			str:
								UpperCAmelCase     :		int							     =		pipeline("""document-question-answering"""		,		model="""hf-internal-testing/tiny-random-layoutlmv2"""    )
								UpperCAmelCase     :		Any							     =		INVOICE_URL
								UpperCAmelCase     :		List[Any]							     =		"""How many cats are there?"""

								UpperCAmelCase     :		int							     =		[
								    {"""score""": 0.0_0_0_1, """answer""": """oy 2312/2019""", """start""": 38, """end""": 39},
								    {"""score""": 0.0_0_0_1, """answer""": """oy 2312/2019 DUE""", """start""": 38, """end""": 40},
								]
								UpperCAmelCase     :		List[str]							     =		dqa_pipeline(image=UpperCAmelCase__		,		question=UpperCAmelCase__		,		top_k=2    )
								self.assertEqual(nested_simplify(UpperCAmelCase__		,		decimals=4    )		,		UpperCAmelCase__    )

								UpperCAmelCase     :		int							     =		dqa_pipeline({"""image""": image, """question""": question}		,		top_k=2    )
								self.assertEqual(nested_simplify(UpperCAmelCase__		,		decimals=4    )		,		UpperCAmelCase__    )

								# This image does not detect ANY text in it, meaning layoutlmv2 should fail.
								# Empty answer probably
								UpperCAmelCase     :		List[Any]							     =		"""./tests/fixtures/tests_samples/COCO/000000039769.png"""
								UpperCAmelCase     :		int							     =		dqa_pipeline(image=UpperCAmelCase__		,		question=UpperCAmelCase__		,		top_k=2    )
								self.assertEqual(UpperCAmelCase__		,		[]    )

								# We can optionnally pass directly the words and bounding boxes
								UpperCAmelCase     :		Any							     =		"""./tests/fixtures/tests_samples/COCO/000000039769.png"""
								UpperCAmelCase     :		List[str]							     =		[]
								UpperCAmelCase     :		Tuple							     =		[]
								UpperCAmelCase     :		Dict							     =		dqa_pipeline(image=UpperCAmelCase__		,		question=UpperCAmelCase__		,		words=UpperCAmelCase__		,		boxes=UpperCAmelCase__		,		top_k=2    )
								self.assertEqual(UpperCAmelCase__		,		[]    )





	@slow
	@require_torch
	@require_detectrona
	@require_pytesseract
	def  _lowercase(  self    )			->			List[Any]:
								UpperCAmelCase     :		Tuple							     =		pipeline(
								    """document-question-answering"""		,		model="""tiennvcs/layoutlmv2-base-uncased-finetuned-docvqa"""		,		revision="""9977165"""		,		)
								UpperCAmelCase     :		Optional[Any]							     =		INVOICE_URL
								UpperCAmelCase     :		Optional[Any]							     =		"""What is the invoice number?"""

								UpperCAmelCase     :		Tuple							     =		dqa_pipeline(image=UpperCAmelCase__		,		question=UpperCAmelCase__		,		top_k=2    )
								self.assertEqual(
								    nested_simplify(UpperCAmelCase__		,		decimals=4    )		,		[
								        {"""score""": 0.9_9_4_4, """answer""": """us-001""", """start""": 16, """end""": 16},
								        {"""score""": 0.0_0_0_9, """answer""": """us-001""", """start""": 16, """end""": 16},
								    ]		,		)

								UpperCAmelCase     :		Any							     =		dqa_pipeline({"""image""": image, """question""": question}		,		top_k=2    )
								self.assertEqual(
								    nested_simplify(UpperCAmelCase__		,		decimals=4    )		,		[
								        {"""score""": 0.9_9_4_4, """answer""": """us-001""", """start""": 16, """end""": 16},
								        {"""score""": 0.0_0_0_9, """answer""": """us-001""", """start""": 16, """end""": 16},
								    ]		,		)

								UpperCAmelCase     :		Any							     =		dqa_pipeline(
								    [{"""image""": image, """question""": question}, {"""image""": image, """question""": question}]		,		top_k=2    )
								self.assertEqual(
								    nested_simplify(UpperCAmelCase__		,		decimals=4    )		,		[
								        [
								            {"""score""": 0.9_9_4_4, """answer""": """us-001""", """start""": 16, """end""": 16},
								            {"""score""": 0.0_0_0_9, """answer""": """us-001""", """start""": 16, """end""": 16},
								        ],
								    ]
								    * 2		,		)





	@slow
	@require_torch
	@require_detectrona
	@require_pytesseract
	def  _lowercase(  self    )			->			Optional[int]:
								UpperCAmelCase     :		Any							     =		pipeline(
								    """document-question-answering"""		,		model="""tiennvcs/layoutlmv2-base-uncased-finetuned-docvqa"""		,		revision="""9977165"""		,		max_seq_len=50		,		)
								UpperCAmelCase     :		Dict							     =		INVOICE_URL
								UpperCAmelCase     :		Optional[Any]							     =		"""What is the invoice number?"""

								UpperCAmelCase     :		Tuple							     =		dqa_pipeline(image=UpperCAmelCase__		,		question=UpperCAmelCase__		,		top_k=2    )
								self.assertEqual(
								    nested_simplify(UpperCAmelCase__		,		decimals=4    )		,		[
								        {"""score""": 0.9_9_7_4, """answer""": """1110212019""", """start""": 23, """end""": 23},
								        {"""score""": 0.9_9_4_8, """answer""": """us-001""", """start""": 16, """end""": 16},
								    ]		,		)

								UpperCAmelCase     :		Dict							     =		dqa_pipeline({"""image""": image, """question""": question}		,		top_k=2    )
								self.assertEqual(
								    nested_simplify(UpperCAmelCase__		,		decimals=4    )		,		[
								        {"""score""": 0.9_9_7_4, """answer""": """1110212019""", """start""": 23, """end""": 23},
								        {"""score""": 0.9_9_4_8, """answer""": """us-001""", """start""": 16, """end""": 16},
								    ]		,		)

								UpperCAmelCase     :		int							     =		dqa_pipeline(
								    [{"""image""": image, """question""": question}, {"""image""": image, """question""": question}]		,		top_k=2    )
								self.assertEqual(
								    nested_simplify(UpperCAmelCase__		,		decimals=4    )		,		[
								        [
								            {"""score""": 0.9_9_7_4, """answer""": """1110212019""", """start""": 23, """end""": 23},
								            {"""score""": 0.9_9_4_8, """answer""": """us-001""", """start""": 16, """end""": 16},
								        ]
								    ]
								    * 2		,		)





	@slow
	@require_torch
	@require_pytesseract
	@require_vision
	def  _lowercase(  self    )			->			str:
								UpperCAmelCase     :		str							     =		AutoTokenizer.from_pretrained(
								    """impira/layoutlm-document-qa"""		,		revision="""3dc6de3"""		,		add_prefix_space=UpperCAmelCase__    )
								UpperCAmelCase     :		Union[str, Any]							     =		pipeline(
								    """document-question-answering"""		,		model="""impira/layoutlm-document-qa"""		,		tokenizer=UpperCAmelCase__		,		revision="""3dc6de3"""		,		)
								UpperCAmelCase     :		int							     =		INVOICE_URL
								UpperCAmelCase     :		Dict							     =		"""What is the invoice number?"""

								UpperCAmelCase     :		List[str]							     =		dqa_pipeline(image=UpperCAmelCase__		,		question=UpperCAmelCase__		,		top_k=2    )
								self.assertEqual(
								    nested_simplify(UpperCAmelCase__		,		decimals=4    )		,		[
								        {"""score""": 0.4_2_5_1, """answer""": """us-001""", """start""": 16, """end""": 16},
								        {"""score""": 0.0_8_1_9, """answer""": """1110212019""", """start""": 23, """end""": 23},
								    ]		,		)

								UpperCAmelCase     :		Union[str, Any]							     =		dqa_pipeline({"""image""": image, """question""": question}		,		top_k=2    )
								self.assertEqual(
								    nested_simplify(UpperCAmelCase__		,		decimals=4    )		,		[
								        {"""score""": 0.4_2_5_1, """answer""": """us-001""", """start""": 16, """end""": 16},
								        {"""score""": 0.0_8_1_9, """answer""": """1110212019""", """start""": 23, """end""": 23},
								    ]		,		)

								UpperCAmelCase     :		Optional[int]							     =		dqa_pipeline(
								    [{"""image""": image, """question""": question}, {"""image""": image, """question""": question}]		,		top_k=2    )
								self.assertEqual(
								    nested_simplify(UpperCAmelCase__		,		decimals=4    )		,		[
								        [
								            {"""score""": 0.4_2_5_1, """answer""": """us-001""", """start""": 16, """end""": 16},
								            {"""score""": 0.0_8_1_9, """answer""": """1110212019""", """start""": 23, """end""": 23},
								        ]
								    ]
								    * 2		,		)

								UpperCAmelCase     :		Optional[int]							     =		list(zip(*apply_tesseract(load_image(UpperCAmelCase__    )		,		UpperCAmelCase__		,		""""""    )    )    )

								# This model should also work if `image` is set to None
								UpperCAmelCase     :		int							     =		dqa_pipeline({"""image""": None, """word_boxes""": word_boxes, """question""": question}		,		top_k=2    )
								self.assertEqual(
								    nested_simplify(UpperCAmelCase__		,		decimals=4    )		,		[
								        {"""score""": 0.4_2_5_1, """answer""": """us-001""", """start""": 16, """end""": 16},
								        {"""score""": 0.0_8_1_9, """answer""": """1110212019""", """start""": 23, """end""": 23},
								    ]		,		)





	@slow
	@require_torch
	@require_pytesseract
	@require_vision
	def  _lowercase(  self    )			->			int:
								UpperCAmelCase     :		str							     =		AutoTokenizer.from_pretrained(
								    """impira/layoutlm-document-qa"""		,		revision="""3dc6de3"""		,		add_prefix_space=UpperCAmelCase__    )
								UpperCAmelCase     :		List[Any]							     =		pipeline(
								    """document-question-answering"""		,		model="""impira/layoutlm-document-qa"""		,		tokenizer=UpperCAmelCase__		,		revision="""3dc6de3"""		,		max_seq_len=50		,		)
								UpperCAmelCase     :		List[str]							     =		INVOICE_URL
								UpperCAmelCase     :		List[str]							     =		"""What is the invoice number?"""

								UpperCAmelCase     :		List[Any]							     =		dqa_pipeline(image=UpperCAmelCase__		,		question=UpperCAmelCase__		,		top_k=2    )
								self.assertEqual(
								    nested_simplify(UpperCAmelCase__		,		decimals=4    )		,		[
								        {"""score""": 0.9_9_9_9, """answer""": """us-001""", """start""": 16, """end""": 16},
								        {"""score""": 0.9_9_9_8, """answer""": """us-001""", """start""": 16, """end""": 16},
								    ]		,		)

								UpperCAmelCase     :		List[str]							     =		dqa_pipeline(
								    [{"""image""": image, """question""": question}, {"""image""": image, """question""": question}]		,		top_k=2    )
								self.assertEqual(
								    nested_simplify(UpperCAmelCase__		,		decimals=4    )		,		[
								        [
								            {"""score""": 0.9_9_9_9, """answer""": """us-001""", """start""": 16, """end""": 16},
								            {"""score""": 0.9_9_9_8, """answer""": """us-001""", """start""": 16, """end""": 16},
								        ]
								    ]
								    * 2		,		)

								UpperCAmelCase     :		Any							     =		list(zip(*apply_tesseract(load_image(UpperCAmelCase__    )		,		UpperCAmelCase__		,		""""""    )    )    )

								# This model should also work if `image` is set to None
								UpperCAmelCase     :		Tuple							     =		dqa_pipeline({"""image""": None, """word_boxes""": word_boxes, """question""": question}		,		top_k=2    )
								self.assertEqual(
								    nested_simplify(UpperCAmelCase__		,		decimals=4    )		,		[
								        {"""score""": 0.9_9_9_9, """answer""": """us-001""", """start""": 16, """end""": 16},
								        {"""score""": 0.9_9_9_8, """answer""": """us-001""", """start""": 16, """end""": 16},
								    ]		,		)





	@slow
	@require_torch
	def  _lowercase(  self    )			->			Optional[Any]:
								UpperCAmelCase     :		Optional[int]							     =		pipeline(
								    """document-question-answering"""		,		model="""naver-clova-ix/donut-base-finetuned-docvqa"""		,		tokenizer=AutoTokenizer.from_pretrained("""naver-clova-ix/donut-base-finetuned-docvqa"""    )		,		feature_extractor="""naver-clova-ix/donut-base-finetuned-docvqa"""		,		)

								UpperCAmelCase     :		Optional[Any]							     =		INVOICE_URL
								UpperCAmelCase     :		Union[str, Any]							     =		"""What is the invoice number?"""
								UpperCAmelCase     :		str							     =		dqa_pipeline(image=UpperCAmelCase__		,		question=UpperCAmelCase__		,		top_k=2    )
								self.assertEqual(nested_simplify(UpperCAmelCase__		,		decimals=4    )		,		[{"""answer""": """us-001"""}]    )






	@require_tf
	@unittest.skip("""Document question answering not implemented in TF"""    )
	def  _lowercase(  self    )			->			int:
								pass




"""simple docstring"""





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

import torch
from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    DiffusionPipeline,
    LMSDiscreteScheduler,
    PNDMScheduler,
    StableDiffusionPipeline,
    UNetaDConditionModel,
)
from diffusers.pipelines.stable_diffusion import StableDiffusionPipelineOutput
from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker


_a       =							'CompVis/stable-diffusion-v1-1'
_a       =							'CompVis/stable-diffusion-v1-2'
_a       =							'CompVis/stable-diffusion-v1-3'
_a       =							'CompVis/stable-diffusion-v1-4'




class 					_lowerCAmelCase  (	lowercase   ):







 """simple docstring"""







 def __init__(			self							:			Dict,					UpperCAmelCase__							:			AutoencoderKL,					UpperCAmelCase__							:			CLIPTextModel,					UpperCAmelCase__							:			CLIPTokenizer,					UpperCAmelCase__							:			UNetaDConditionModel,					UpperCAmelCase__							:			Union[DDIMScheduler, PNDMScheduler, LMSDiscreteScheduler],					UpperCAmelCase__							:			StableDiffusionSafetyChecker,					UpperCAmelCase__							:			CLIPImageProcessor,					UpperCAmelCase__							:			bool = True,					):
    super()._init_()

    __lowercase								=						StableDiffusionPipeline.from_pretrained(UpperCAmelCase__	)
    __lowercase								=						StableDiffusionPipeline.from_pretrained(UpperCAmelCase__	)
    __lowercase								=						StableDiffusionPipeline.from_pretrained(UpperCAmelCase__	)
    __lowercase								=						StableDiffusionPipeline(
        vae=UpperCAmelCase__,					text_encoder=UpperCAmelCase__,					tokenizer=UpperCAmelCase__,					unet=UpperCAmelCase__,					scheduler=UpperCAmelCase__,					safety_checker=UpperCAmelCase__,					feature_extractor=UpperCAmelCase__,					requires_safety_checker=UpperCAmelCase__,					)

    self.register_modules(pipelinea=self.pipea,					pipelinea=self.pipea,					pipelinea=self.pipea,					pipelinea=self.pipea	)


 @property
 def 					_lowercase (			self							:			List[str]	):
    return {k: getattr(self,					UpperCAmelCase__	) for k in self.config.keys() if not k.startswith("_"	)}


 def 					_lowercase (			self							:			Union[str, Any],					UpperCAmelCase__							:			Optional[Union[str, int]] = "auto"	):
    if slice_size == "auto":
       # half the attention head size is usually a good trade-off between
       # speed and memory
       __lowercase								=						self.unet.config.attention_head_dim // 2
    self.unet.set_attention_slice(UpperCAmelCase__	)


 def 					_lowercase (			self							:			List[str]	):
    self.enable_attention_slicing(UpperCAmelCase__	)


 @torch.no_grad()
 def 					_lowercase (			self							:			Optional[Any],					UpperCAmelCase__							:			Union[str, List[str]],					UpperCAmelCase__							:			int = 5_1_2,					UpperCAmelCase__							:			int = 5_1_2,					UpperCAmelCase__							:			int = 5_0,					UpperCAmelCase__							:			float = 7.5,					UpperCAmelCase__							:			Optional[Union[str, List[str]]] = None,					UpperCAmelCase__							:			Optional[int] = 1,					UpperCAmelCase__							:			float = 0.0,					UpperCAmelCase__							:			Optional[torch.Generator] = None,					UpperCAmelCase__							:			Optional[torch.FloatTensor] = None,					UpperCAmelCase__							:			Optional[str] = "pil",					UpperCAmelCase__							:			bool = True,					UpperCAmelCase__							:			Optional[Callable[[int, int, torch.FloatTensor], None]] = None,					UpperCAmelCase__							:			int = 1,					**UpperCAmelCase__							:			Tuple,					):
    return self.pipea(
        prompt=UpperCAmelCase__,					height=UpperCAmelCase__,					width=UpperCAmelCase__,					num_inference_steps=UpperCAmelCase__,					guidance_scale=UpperCAmelCase__,					negative_prompt=UpperCAmelCase__,					num_images_per_prompt=UpperCAmelCase__,					eta=UpperCAmelCase__,					generator=UpperCAmelCase__,					latents=UpperCAmelCase__,					output_type=UpperCAmelCase__,					return_dict=UpperCAmelCase__,					callback=UpperCAmelCase__,					callback_steps=UpperCAmelCase__,					**UpperCAmelCase__,					)


 @torch.no_grad()
 def 					_lowercase (			self							:			Tuple,					UpperCAmelCase__							:			Union[str, List[str]],					UpperCAmelCase__							:			int = 5_1_2,					UpperCAmelCase__							:			int = 5_1_2,					UpperCAmelCase__							:			int = 5_0,					UpperCAmelCase__							:			float = 7.5,					UpperCAmelCase__							:			Optional[Union[str, List[str]]] = None,					UpperCAmelCase__							:			Optional[int] = 1,					UpperCAmelCase__							:			float = 0.0,					UpperCAmelCase__							:			Optional[torch.Generator] = None,					UpperCAmelCase__							:			Optional[torch.FloatTensor] = None,					UpperCAmelCase__							:			Optional[str] = "pil",					UpperCAmelCase__							:			bool = True,					UpperCAmelCase__							:			Optional[Callable[[int, int, torch.FloatTensor], None]] = None,					UpperCAmelCase__							:			int = 1,					**UpperCAmelCase__							:			str,					):
    return self.pipea(
        prompt=UpperCAmelCase__,					height=UpperCAmelCase__,					width=UpperCAmelCase__,					num_inference_steps=UpperCAmelCase__,					guidance_scale=UpperCAmelCase__,					negative_prompt=UpperCAmelCase__,					num_images_per_prompt=UpperCAmelCase__,					eta=UpperCAmelCase__,					generator=UpperCAmelCase__,					latents=UpperCAmelCase__,					output_type=UpperCAmelCase__,					return_dict=UpperCAmelCase__,					callback=UpperCAmelCase__,					callback_steps=UpperCAmelCase__,					**UpperCAmelCase__,					)


 @torch.no_grad()
 def 					_lowercase (			self							:			str,					UpperCAmelCase__							:			Union[str, List[str]],					UpperCAmelCase__							:			int = 5_1_2,					UpperCAmelCase__							:			int = 5_1_2,					UpperCAmelCase__							:			int = 5_0,					UpperCAmelCase__							:			float = 7.5,					UpperCAmelCase__							:			Optional[Union[str, List[str]]] = None,					UpperCAmelCase__							:			Optional[int] = 1,					UpperCAmelCase__							:			float = 0.0,					UpperCAmelCase__							:			Optional[torch.Generator] = None,					UpperCAmelCase__							:			Optional[torch.FloatTensor] = None,					UpperCAmelCase__							:			Optional[str] = "pil",					UpperCAmelCase__							:			bool = True,					UpperCAmelCase__							:			Optional[Callable[[int, int, torch.FloatTensor], None]] = None,					UpperCAmelCase__							:			int = 1,					**UpperCAmelCase__							:			Any,					):
    return self.pipea(
        prompt=UpperCAmelCase__,					height=UpperCAmelCase__,					width=UpperCAmelCase__,					num_inference_steps=UpperCAmelCase__,					guidance_scale=UpperCAmelCase__,					negative_prompt=UpperCAmelCase__,					num_images_per_prompt=UpperCAmelCase__,					eta=UpperCAmelCase__,					generator=UpperCAmelCase__,					latents=UpperCAmelCase__,					output_type=UpperCAmelCase__,					return_dict=UpperCAmelCase__,					callback=UpperCAmelCase__,					callback_steps=UpperCAmelCase__,					**UpperCAmelCase__,					)


 @torch.no_grad()
 def 					_lowercase (			self							:			Union[str, Any],					UpperCAmelCase__							:			Union[str, List[str]],					UpperCAmelCase__							:			int = 5_1_2,					UpperCAmelCase__							:			int = 5_1_2,					UpperCAmelCase__							:			int = 5_0,					UpperCAmelCase__							:			float = 7.5,					UpperCAmelCase__							:			Optional[Union[str, List[str]]] = None,					UpperCAmelCase__							:			Optional[int] = 1,					UpperCAmelCase__							:			float = 0.0,					UpperCAmelCase__							:			Optional[torch.Generator] = None,					UpperCAmelCase__							:			Optional[torch.FloatTensor] = None,					UpperCAmelCase__							:			Optional[str] = "pil",					UpperCAmelCase__							:			bool = True,					UpperCAmelCase__							:			Optional[Callable[[int, int, torch.FloatTensor], None]] = None,					UpperCAmelCase__							:			int = 1,					**UpperCAmelCase__							:			Optional[int],					):
    return self.pipea(
        prompt=UpperCAmelCase__,					height=UpperCAmelCase__,					width=UpperCAmelCase__,					num_inference_steps=UpperCAmelCase__,					guidance_scale=UpperCAmelCase__,					negative_prompt=UpperCAmelCase__,					num_images_per_prompt=UpperCAmelCase__,					eta=UpperCAmelCase__,					generator=UpperCAmelCase__,					latents=UpperCAmelCase__,					output_type=UpperCAmelCase__,					return_dict=UpperCAmelCase__,					callback=UpperCAmelCase__,					callback_steps=UpperCAmelCase__,					**UpperCAmelCase__,					)



 @torch.no_grad()
 def 					_lowercase (			self							:			Optional[Any],					UpperCAmelCase__							:			Union[str, List[str]],					UpperCAmelCase__							:			int = 5_1_2,					UpperCAmelCase__							:			int = 5_1_2,					UpperCAmelCase__							:			int = 5_0,					UpperCAmelCase__							:			float = 7.5,					UpperCAmelCase__							:			Optional[Union[str, List[str]]] = None,					UpperCAmelCase__							:			Optional[int] = 1,					UpperCAmelCase__							:			float = 0.0,					UpperCAmelCase__							:			Optional[torch.Generator] = None,					UpperCAmelCase__							:			Optional[torch.FloatTensor] = None,					UpperCAmelCase__							:			Optional[str] = "pil",					UpperCAmelCase__							:			bool = True,					UpperCAmelCase__							:			Optional[Callable[[int, int, torch.FloatTensor], None]] = None,					UpperCAmelCase__							:			int = 1,					**UpperCAmelCase__							:			str,					):
    __lowercase								=						"cuda" if torch.cuda.is_available() else "cpu"
    self.to(UpperCAmelCase__	)

    # Checks if the height and width are divisible by 8 or not
    if height % 8 != 0 or width % 8 != 0:
       raise ValueError(F"""`height` and `width` must be divisible by 8 but are {height} and {width}."""	)

    # Get first result from Stable Diffusion Checkpoint v1.1
    __lowercase								=						self.textaimg_sda_a(
        prompt=UpperCAmelCase__,					height=UpperCAmelCase__,					width=UpperCAmelCase__,					num_inference_steps=UpperCAmelCase__,					guidance_scale=UpperCAmelCase__,					negative_prompt=UpperCAmelCase__,					num_images_per_prompt=UpperCAmelCase__,					eta=UpperCAmelCase__,					generator=UpperCAmelCase__,					latents=UpperCAmelCase__,					output_type=UpperCAmelCase__,					return_dict=UpperCAmelCase__,					callback=UpperCAmelCase__,					callback_steps=UpperCAmelCase__,					**UpperCAmelCase__,					)

    # Get first result from Stable Diffusion Checkpoint v1.2
    __lowercase								=						self.textaimg_sda_a(
        prompt=UpperCAmelCase__,					height=UpperCAmelCase__,					width=UpperCAmelCase__,					num_inference_steps=UpperCAmelCase__,					guidance_scale=UpperCAmelCase__,					negative_prompt=UpperCAmelCase__,					num_images_per_prompt=UpperCAmelCase__,					eta=UpperCAmelCase__,					generator=UpperCAmelCase__,					latents=UpperCAmelCase__,					output_type=UpperCAmelCase__,					return_dict=UpperCAmelCase__,					callback=UpperCAmelCase__,					callback_steps=UpperCAmelCase__,					**UpperCAmelCase__,					)

    # Get first result from Stable Diffusion Checkpoint v1.3
    __lowercase								=						self.textaimg_sda_a(
        prompt=UpperCAmelCase__,					height=UpperCAmelCase__,					width=UpperCAmelCase__,					num_inference_steps=UpperCAmelCase__,					guidance_scale=UpperCAmelCase__,					negative_prompt=UpperCAmelCase__,					num_images_per_prompt=UpperCAmelCase__,					eta=UpperCAmelCase__,					generator=UpperCAmelCase__,					latents=UpperCAmelCase__,					output_type=UpperCAmelCase__,					return_dict=UpperCAmelCase__,					callback=UpperCAmelCase__,					callback_steps=UpperCAmelCase__,					**UpperCAmelCase__,					)

    # Get first result from Stable Diffusion Checkpoint v1.4
    __lowercase								=						self.textaimg_sda_a(
        prompt=UpperCAmelCase__,					height=UpperCAmelCase__,					width=UpperCAmelCase__,					num_inference_steps=UpperCAmelCase__,					guidance_scale=UpperCAmelCase__,					negative_prompt=UpperCAmelCase__,					num_images_per_prompt=UpperCAmelCase__,					eta=UpperCAmelCase__,					generator=UpperCAmelCase__,					latents=UpperCAmelCase__,					output_type=UpperCAmelCase__,					return_dict=UpperCAmelCase__,					callback=UpperCAmelCase__,					callback_steps=UpperCAmelCase__,					**UpperCAmelCase__,					)

    # Get all result images into a single list and pass it via StableDiffusionPipelineOutput for final result
    return StableDiffusionPipelineOutput([resa[0], resa[0], resa[0], resa[0]]	)




