



import unittest

from transformers import MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING, is_vision_available
from transformers.pipelines import pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_tf,
    require_torch,
    require_vision,
    slow,
)

from .test_pipelines_common import ANY


if is_vision_available():
						from PIL import Image
else:






						class       SCREAMING_SNAKE_CASE	:





													@staticmethod
													def   UpperCamelCase_    (      *__lowercase						:						Optional[Any]					, **__lowercase						:						int		):

																	'''simple docstring'''
																	pass






@is_pipeline_test
@require_torch
@require_vision
class       SCREAMING_SNAKE_CASE	(							unittest.TestCase    ):
							__lowerCamelCase		:		List[Any]			=MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING





							def   UpperCamelCase_    (      self						:						Optional[Any]					, __lowercase						:						Optional[int]					, __lowercase						:						Any					, __lowercase						:						List[Any]		):

											'''simple docstring'''
											__a        =						pipeline("""visual-question-answering"""					, model="""hf-internal-testing/tiny-vilt-random-vqa"""		)
											__a        =						[
											    {
											        """image""": Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""		),
											        """question""": """How many cats are there?""",
											    },
											    {
											        """image""": """./tests/fixtures/tests_samples/COCO/000000039769.png""",
											        """question""": """How many cats are there?""",
											    },
											]
											return vqa_pipeline, examples





							def   UpperCamelCase_    (      self						:						List[str]					, __lowercase						:						Optional[int]					, __lowercase						:						Dict		):

											'''simple docstring'''
											__a        =						vqa_pipeline(__lowercase					, top_k=1		)
											self.assertEqual(
											    __lowercase					, [
											        [{"""score""": ANY(__lowercase		), """answer""": ANY(__lowercase		)}],
											        [{"""score""": ANY(__lowercase		), """answer""": ANY(__lowercase		)}],
											    ]					, )





							@require_torch
							def   UpperCamelCase_    (      self						:						Optional[int]		):

											'''simple docstring'''
											__a        =						pipeline("""visual-question-answering"""					, model="""hf-internal-testing/tiny-vilt-random-vqa"""		)
											__a        =						"""./tests/fixtures/tests_samples/COCO/000000039769.png"""
											__a        =						"""How many cats are there?"""

											__a        =						vqa_pipeline(image=__lowercase					, question="""How many cats are there?"""					, top_k=2		)
											self.assertEqual(
											    __lowercase					, [{"""score""": ANY(__lowercase		), """answer""": ANY(__lowercase		)}, {"""score""": ANY(__lowercase		), """answer""": ANY(__lowercase		)}]		)

											__a        =						vqa_pipeline({"""image""": image, """question""": question}					, top_k=2		)
											self.assertEqual(
											    __lowercase					, [{"""score""": ANY(__lowercase		), """answer""": ANY(__lowercase		)}, {"""score""": ANY(__lowercase		), """answer""": ANY(__lowercase		)}]		)





							@slow
							@require_torch
							def   UpperCamelCase_    (      self						:						List[str]		):

											'''simple docstring'''
											__a        =						pipeline("""visual-question-answering"""					, model="""dandelin/vilt-b32-finetuned-vqa"""		)
											__a        =						"""./tests/fixtures/tests_samples/COCO/000000039769.png"""
											__a        =						"""How many cats are there?"""

											__a        =						vqa_pipeline(image=__lowercase					, question=__lowercase					, top_k=2		)
											self.assertEqual(
											    nested_simplify(__lowercase					, decimals=4		)					, [{"""score""": 0.8799, """answer""": """2"""}, {"""score""": 0.296, """answer""": """1"""}]		)

											__a        =						vqa_pipeline({"""image""": image, """question""": question}					, top_k=2		)
											self.assertEqual(
											    nested_simplify(__lowercase					, decimals=4		)					, [{"""score""": 0.8799, """answer""": """2"""}, {"""score""": 0.296, """answer""": """1"""}]		)

											__a        =						vqa_pipeline(
											    [{"""image""": image, """question""": question}, {"""image""": image, """question""": question}]					, top_k=2		)
											self.assertEqual(
											    nested_simplify(__lowercase					, decimals=4		)					, [[{"""score""": 0.8799, """answer""": """2"""}, {"""score""": 0.296, """answer""": """1"""}]] * 2					, )







							@require_tf
							@unittest.skip("""Visual question answering not implemented in TF"""		)
							def   UpperCamelCase_    (      self						:						Optional[int]		):

											'''simple docstring'''
											pass





'''simple docstring'''




import torch

from diffusers import StableDiffusionPipeline


lowerCamelCase							:Tuple				    =					'''path-to-your-trained-model'''
lowerCamelCase							:Optional[int]				    =					StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.floataa).to('''cuda''')

lowerCamelCase							:Optional[int]				    =					'''A photo of sks dog in a bucket'''
lowerCamelCase							:List[Any]				    =					pipe(prompt, num_inference_steps=5_0, guidance_scale=7.5).images[0]

image.save('''dog-bucket.png''')