




"""simple docstring"""

from ..utils import (
    OptionalDependencyNotAvailable,
    is_flax_available,
    is_invisible_watermark_available,
    is_k_diffusion_available,
    is_librosa_available,
    is_note_seq_available,
    is_onnx_available,
    is_torch_available,
    is_transformers_available,
)


try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		from ..utils.dummy_pt_objects import *  # noqa F403
else:
		from .consistency_models import ConsistencyModelPipeline
		from .dance_diffusion import DanceDiffusionPipeline
		from .ddim import DDIMPipeline
		from .ddpm import DDPMPipeline
		from .dit import DiTPipeline
		from .latent_diffusion import LDMSuperResolutionPipeline
		from .latent_diffusion_uncond import LDMPipeline
		from .pipeline_utils import AudioPipelineOutput, DiffusionPipeline, ImagePipelineOutput
		from .pndm import PNDMPipeline
		from .repaint import RePaintPipeline
		from .score_sde_ve import ScoreSdeVePipeline
		from .stochastic_karras_ve import KarrasVePipeline

try:
		if not (is_torch_available() and is_librosa_available()):
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		from ..utils.dummy_torch_and_librosa_objects import *  # noqa F403
else:
		from .audio_diffusion import AudioDiffusionPipeline, Mel

try:
		if not (is_torch_available() and is_transformers_available()):
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		from ..utils.dummy_torch_and_transformers_objects import *  # noqa F403
else:
		from .alt_diffusion import AltDiffusionImgaImgPipeline, AltDiffusionPipeline
		from .audioldm import AudioLDMPipeline
		from .controlnet import (
		    StableDiffusionControlNetImgaImgPipeline,
		    StableDiffusionControlNetInpaintPipeline,
		    StableDiffusionControlNetPipeline,
		)
		from .deepfloyd_if import (
		    IFImgaImgPipeline,
		    IFImgaImgSuperResolutionPipeline,
		    IFInpaintingPipeline,
		    IFInpaintingSuperResolutionPipeline,
		    IFPipeline,
		    IFSuperResolutionPipeline,
		)
		from .kandinsky import (
		    KandinskyImgaImgPipeline,
		    KandinskyInpaintPipeline,
		    KandinskyPipeline,
		    KandinskyPriorPipeline,
		)
		from .kandinskya_a import (
		    KandinskyVaaControlnetImgaImgPipeline,
		    KandinskyVaaControlnetPipeline,
		    KandinskyVaaImgaImgPipeline,
		    KandinskyVaaInpaintPipeline,
		    KandinskyVaaPipeline,
		    KandinskyVaaPriorEmbaEmbPipeline,
		    KandinskyVaaPriorPipeline,
		)
		from .latent_diffusion import LDMTextToImagePipeline
		from .paint_by_example import PaintByExamplePipeline
		from .semantic_stable_diffusion import SemanticStableDiffusionPipeline
		from .shap_e import ShapEImgaImgPipeline, ShapEPipeline
		from .stable_diffusion import (
		    CycleDiffusionPipeline,
		    StableDiffusionAttendAndExcitePipeline,
		    StableDiffusionDepthaImgPipeline,
		    StableDiffusionDiffEditPipeline,
		    StableDiffusionImageVariationPipeline,
		    StableDiffusionImgaImgPipeline,
		    StableDiffusionInpaintPipeline,
		    StableDiffusionInpaintPipelineLegacy,
		    StableDiffusionInstructPixaPixPipeline,
		    StableDiffusionLatentUpscalePipeline,
		    StableDiffusionLDMaDPipeline,
		    StableDiffusionModelEditingPipeline,
		    StableDiffusionPanoramaPipeline,
		    StableDiffusionParadigmsPipeline,
		    StableDiffusionPipeline,
		    StableDiffusionPixaPixZeroPipeline,
		    StableDiffusionSAGPipeline,
		    StableDiffusionUpscalePipeline,
		    StableUnCLIPImgaImgPipeline,
		    StableUnCLIPPipeline,
		)
		from .stable_diffusion_safe import StableDiffusionPipelineSafe
		from .text_to_video_synthesis import TextToVideoSDPipeline, TextToVideoZeroPipeline, VideoToVideoSDPipeline
		from .unclip import UnCLIPImageVariationPipeline, UnCLIPPipeline
		from .unidiffuser import ImageTextPipelineOutput, UniDiffuserModel, UniDiffuserPipeline, UniDiffuserTextDecoder
		from .versatile_diffusion import (
		    VersatileDiffusionDualGuidedPipeline,
		    VersatileDiffusionImageVariationPipeline,
		    VersatileDiffusionPipeline,
		    VersatileDiffusionTextToImagePipeline,
		)
		from .vq_diffusion import VQDiffusionPipeline


try:
		if not (is_torch_available() and is_transformers_available() and is_invisible_watermark_available()):
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		from ..utils.dummy_torch_and_transformers_and_invisible_watermark_objects import *  # noqa F403
else:
		from .stable_diffusion_xl import StableDiffusionXLImgaImgPipeline, StableDiffusionXLPipeline

try:
		if not is_onnx_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		from ..utils.dummy_onnx_objects import *  # noqa F403
else:
		from .onnx_utils import OnnxRuntimeModel

try:
		if not (is_torch_available() and is_transformers_available() and is_onnx_available()):
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		from ..utils.dummy_torch_and_transformers_and_onnx_objects import *  # noqa F403
else:
		from .stable_diffusion import (
		    OnnxStableDiffusionImgaImgPipeline,
		    OnnxStableDiffusionInpaintPipeline,
		    OnnxStableDiffusionInpaintPipelineLegacy,
		    OnnxStableDiffusionPipeline,
		    OnnxStableDiffusionUpscalePipeline,
		    StableDiffusionOnnxPipeline,
		)

try:
		if not (is_torch_available() and is_transformers_available() and is_k_diffusion_available()):
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		from ..utils.dummy_torch_and_transformers_and_k_diffusion_objects import *  # noqa F403
else:
		from .stable_diffusion import StableDiffusionKDiffusionPipeline

try:
		if not is_flax_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		from ..utils.dummy_flax_objects import *  # noqa F403
else:
		from .pipeline_flax_utils import FlaxDiffusionPipeline


try:
		if not (is_flax_available() and is_transformers_available()):
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		from ..utils.dummy_flax_and_transformers_objects import *  # noqa F403
else:
		from .controlnet import FlaxStableDiffusionControlNetPipeline
		from .stable_diffusion import (
		    FlaxStableDiffusionImgaImgPipeline,
		    FlaxStableDiffusionInpaintPipeline,
		    FlaxStableDiffusionPipeline,
		)
try:
		if not (is_transformers_available() and is_torch_available() and is_note_seq_available()):
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		from ..utils.dummy_transformers_and_torch_and_note_seq_objects import *  # noqa F403
else:
		from .spectrogram_diffusion import MidiProcessor, SpectrogramDiffusionPipeline








"""simple docstring"""

from copy import deepcopy
from unittest.case import TestCase

import pytest

from datasets.arrow_dataset import Dataset
from datasets.features import Audio, ClassLabel, Features, Image, Sequence, Value
from datasets.info import DatasetInfo
from datasets.tasks import (
    AudioClassification,
    AutomaticSpeechRecognition,
    ImageClassification,
    LanguageModeling,
    QuestionAnsweringExtractive,
    Summarization,
    TextClassification,
    task_template_from_dict,
)
from datasets.utils.py_utils import asdict


UpperCamelCase__ :    Union[str, Any] 					=							{
    "id": "5733be284776f41900661182",
    "title": "University_of_Notre_Dame",
    "context": "Architecturally, the school has a Catholic character. Atop the Main Building\'s gold dome is a golden statue of the Virgin Mary. Immediately in front of the Main Building and facing it, is a copper statue of Christ with arms upraised with the legend \"Venite Ad Me Omnes\". Next to the Main Building is the Basilica of the Sacred Heart. Immediately behind the basilica is the Grotto, a Marian place of prayer and reflection. It is a replica of the grotto at Lourdes, France where the Virgin Mary reputedly appeared to Saint Bernadette Soubirous in 1858. At the end of the main drive (and in a direct line that connects through 3 statues and the Gold Dome), is a simple, modern stone statue of Mary.",
    "question": "To whom did the Virgin Mary allegedly appear in 1858 in Lourdes France?",
    "answers": {"text": ["Saint Bernadette Soubirous"], "answer_start": [5_15]},
}




@pytest.mark.parametrize(
    """task_cls"""				,					[
        AudioClassification,
        AutomaticSpeechRecognition,
        ImageClassification,
        LanguageModeling,
        QuestionAnsweringExtractive,
        Summarization,
        TextClassification,
    ]				,					)
def       snake_case__	(       lowerCAmelCase   :		Optional[int]		):
					__snake_case          =	task_cls()
					__snake_case          =	asdict(lowerCAmelCase		)
					__snake_case          =	task_template_from_dict(lowerCAmelCase		)
					assert task == reloaded
class     A__      :




	def 							a_		(   self  :	Tuple	)					-> int:
						__snake_case          =	LanguageModeling(text_column="""input_text"""	)
						assert {"input_text": "text"} == task.column_mapping




	def 							a_		(   self  :	Union[str, Any]	)					-> List[Any]:
						__snake_case          =	Features({"""text""": Value("""string"""	)}	)
						__snake_case          =	{"""text_column""": """input_text"""}
						__snake_case          =	LanguageModeling.from_dict(lowercase	)
						assert "language-modeling" == task.task
						assert input_schema == task.input_schema

class     A__      (      lowercase_     ):




	def 							a_		(   self  :	str	)					-> Any:
						__snake_case          =	sorted(["""pos""", """neg"""]	)




	def 							a_		(   self  :	str	)					-> Union[str, Any]:
						__snake_case          =	TextClassification(text_column="""input_text"""      ,    label_column="""input_label"""	)
						self.assertDictEqual({"""input_text""": """text""", """input_label""": """labels"""}      ,    task.column_mapping	)




	def 							a_		(   self  :	int	)					-> List[Any]:
						__snake_case          =	Features({"""text""": Value("""string"""	)}	)
						# Labels are cast to tuple during `TextClassification.__post_init__`, so we do the same here
						__snake_case          =	Features({"""labels""": ClassLabel}	)
						__snake_case          =	{"""text_column""": """input_text""", """label_column""": """input_labels"""}
						__snake_case          =	TextClassification.from_dict(lowercase	)
						self.assertEqual("""text-classification"""      ,    task.task	)
						self.assertEqual(lowercase      ,    task.input_schema	)
						self.assertEqual(lowercase      ,    task.label_schema	)




	def 							a_		(   self  :	Union[str, Any]	)					-> List[Any]:
						__snake_case          =	TextClassification(text_column="""input_text"""      ,    label_column="""input_label"""	)
						self.assertEqual(task.label_schema["""labels"""]      ,    lowercase	)
						__snake_case          =	task.align_with_features(Features({"""input_label""": ClassLabel(names=self.labels	)}	)	)
						self.assertEqual(task.label_schema["""labels"""]      ,    ClassLabel(names=self.labels	)	)

class     A__      (      lowercase_     ):




	def 							a_		(   self  :	Any	)					-> Tuple:
						__snake_case          =	QuestionAnsweringExtractive(
						    context_column="""input_context"""      ,    question_column="""input_question"""      ,    answers_column="""input_answers"""	)
						self.assertDictEqual(
						    {"""input_context""": """context""", """input_question""": """question""", """input_answers""": """answers"""}      ,    task.column_mapping	)




	def 							a_		(   self  :	int	)					-> Tuple:
						__snake_case          =	Features({"""question""": Value("""string"""	), """context""": Value("""string"""	)}	)
						__snake_case          =	Features(
						    {
						        """answers""": Sequence(
						            {
						                """text""": Value("""string"""	),
						                """answer_start""": Value("""int32"""	),
						            }	)
						    }	)
						__snake_case          =	{
						    """context_column""": """input_input_context""",
						    """question_column""": """input_question""",
						    """answers_column""": """input_answers""",
						}
						__snake_case          =	QuestionAnsweringExtractive.from_dict(lowercase	)
						self.assertEqual("""question-answering-extractive"""      ,    task.task	)
						self.assertEqual(lowercase      ,    task.input_schema	)
						self.assertEqual(lowercase      ,    task.label_schema	)

class     A__      (      lowercase_     ):




	def 							a_		(   self  :	Any	)					-> Union[str, Any]:
						__snake_case          =	Summarization(text_column="""input_text"""      ,    summary_column="""input_summary"""	)
						self.assertDictEqual({"""input_text""": """text""", """input_summary""": """summary"""}      ,    task.column_mapping	)




	def 							a_		(   self  :	List[Any]	)					-> Dict:
						__snake_case          =	Features({"""text""": Value("""string"""	)}	)
						__snake_case          =	Features({"""summary""": Value("""string"""	)}	)
						__snake_case          =	{"""text_column""": """input_text""", """summary_column""": """input_summary"""}
						__snake_case          =	Summarization.from_dict(lowercase	)
						self.assertEqual("""summarization"""      ,    task.task	)
						self.assertEqual(lowercase      ,    task.input_schema	)
						self.assertEqual(lowercase      ,    task.label_schema	)

class     A__      (      lowercase_     ):




	def 							a_		(   self  :	Any	)					-> int:
						__snake_case          =	AutomaticSpeechRecognition(audio_column="""input_audio"""      ,    transcription_column="""input_transcription"""	)
						self.assertDictEqual({"""input_audio""": """audio""", """input_transcription""": """transcription"""}      ,    task.column_mapping	)




	def 							a_		(   self  :	Dict	)					-> List[str]:
						__snake_case          =	Features({"""audio""": Audio()}	)
						__snake_case          =	Features({"""transcription""": Value("""string"""	)}	)
						__snake_case          =	{
						    """audio_column""": """input_audio""",
						    """transcription_column""": """input_transcription""",
						}
						__snake_case          =	AutomaticSpeechRecognition.from_dict(lowercase	)
						self.assertEqual("""automatic-speech-recognition"""      ,    task.task	)
						self.assertEqual(lowercase      ,    task.input_schema	)
						self.assertEqual(lowercase      ,    task.label_schema	)

class     A__      (      lowercase_     ):




	def 							a_		(   self  :	int	)					-> Union[str, Any]:
						__snake_case          =	sorted(["""pos""", """neg"""]	)




	def 							a_		(   self  :	Optional[int]	)					-> str:
						__snake_case          =	AudioClassification(audio_column="""input_audio"""      ,    label_column="""input_label"""	)
						self.assertDictEqual({"""input_audio""": """audio""", """input_label""": """labels"""}      ,    task.column_mapping	)




	def 							a_		(   self  :	Union[str, Any]	)					-> Any:
						__snake_case          =	Features({"""audio""": Audio()}	)
						__snake_case          =	Features({"""labels""": ClassLabel}	)
						__snake_case          =	{
						    """audio_column""": """input_image""",
						    """label_column""": """input_label""",
						}
						__snake_case          =	AudioClassification.from_dict(lowercase	)
						self.assertEqual("""audio-classification"""      ,    task.task	)
						self.assertEqual(lowercase      ,    task.input_schema	)
						self.assertEqual(lowercase      ,    task.label_schema	)




	def 							a_		(   self  :	Optional[Any]	)					-> Optional[int]:
						__snake_case          =	AudioClassification(audio_column="""input_audio"""      ,    label_column="""input_label"""	)
						self.assertEqual(task.label_schema["""labels"""]      ,    lowercase	)
						__snake_case          =	task.align_with_features(Features({"""input_label""": ClassLabel(names=self.labels	)}	)	)
						self.assertEqual(task.label_schema["""labels"""]      ,    ClassLabel(names=self.labels	)	)

class     A__      (      lowercase_     ):




	def 							a_		(   self  :	Optional[int]	)					-> str:
						__snake_case          =	sorted(["""pos""", """neg"""]	)




	def 							a_		(   self  :	Optional[int]	)					-> List[str]:
						__snake_case          =	ImageClassification(image_column="""input_image"""      ,    label_column="""input_label"""	)
						self.assertDictEqual({"""input_image""": """image""", """input_label""": """labels"""}      ,    task.column_mapping	)




	def 							a_		(   self  :	Optional[Any]	)					-> int:
						__snake_case          =	Features({"""image""": Image()}	)
						__snake_case          =	Features({"""labels""": ClassLabel}	)
						__snake_case          =	{
						    """image_column""": """input_image""",
						    """label_column""": """input_label""",
						}
						__snake_case          =	ImageClassification.from_dict(lowercase	)
						self.assertEqual("""image-classification"""      ,    task.task	)
						self.assertEqual(lowercase      ,    task.input_schema	)
						self.assertEqual(lowercase      ,    task.label_schema	)




	def 							a_		(   self  :	Optional[int]	)					-> Any:
						__snake_case          =	ImageClassification(image_column="""input_image"""      ,    label_column="""input_label"""	)
						self.assertEqual(task.label_schema["""labels"""]      ,    lowercase	)
						__snake_case          =	task.align_with_features(Features({"""input_label""": ClassLabel(names=self.labels	)}	)	)
						self.assertEqual(task.label_schema["""labels"""]      ,    ClassLabel(names=self.labels	)	)

class     A__      (      lowercase_     ):




	def 							a_		(   self  :	str	)					-> str:
						__snake_case          =	DatasetInfo(task_templates=QuestionAnsweringExtractive()	)
						__snake_case          =	Dataset.from_dict({k: [v] for k, v in SAMPLE_QUESTION_ANSWERING_EXTRACTIVE.items()}      ,    info=lowercase	)
						assert isinstance(dataset.info.task_templates      ,    lowercase	)
						assert len(dataset.info.task_templates	) == 1

						def keep_task(lowercase  :	Tuple	):
											return x

						def dont_keep_task(lowercase  :	List[str]	):
											__snake_case          =	deepcopy(lowercase	)
											__snake_case          =	0
											return out

						__snake_case          =	dataset.map(lowercase	)
						assert mapped_dataset.info.task_templates == dataset.info.task_templates
						# reload from cache
						__snake_case          =	dataset.map(lowercase	)
						assert mapped_dataset.info.task_templates == dataset.info.task_templates

						__snake_case          =	dataset.map(lowercase	)
						assert mapped_dataset.info.task_templates == []
						# reload from cache
						__snake_case          =	dataset.map(lowercase	)
						assert mapped_dataset.info.task_templates == []




	def 							a_		(   self  :	Any	)					-> int:
						__snake_case          =	Features({"""text""": Value("""string"""	), """label""": ClassLabel(names=("""pos""", """neg""")	)}	)
						__snake_case          =	TextClassification(text_column="""text"""      ,    label_column="""label"""	)
						__snake_case          =	DatasetInfo(features=lowercase      ,    task_templates=lowercase	)
						__snake_case          =	Dataset.from_dict({"""text""": ["""A sentence."""], """label""": ["""pos"""]}      ,    info=lowercase	)

						def process(lowercase  :	List[Any]	):
											return example

						__snake_case          =	dataset.remove_columns("""label"""	)
						__snake_case          =	modified_dataset.map(lowercase	)
						assert mapped_dataset.info.task_templates == []


