






from collections import UserDict
from typing import Union

import numpy as np
import requests

from ..utils import (
    add_end_docstrings,
    logging,
)
from .audio_classification import ffmpeg_read
from .base import PIPELINE_INIT_ARGS, Pipeline


lowercase  :							List[str]			  =    logging.get_logger(__name__)




@add_end_docstrings(lowercase_					)
class 		UpperCAmelCase_						(	lowercase_					):


				'''simple docstring'''




				def __init__(	self		,				**_SCREAMING_SNAKE_CASE				) ->				List[Any]:
						super().__init__(**UpperCamelCase__				)

						if self.framework != "pt":
								raise ValueError(f'''The {self.__class__} is only available in PyTorch.'''				)
						# No specific FOR_XXX available yet






				def __call__(	self		,				_SCREAMING_SNAKE_CASE		,				**_SCREAMING_SNAKE_CASE				) ->				Dict:
						return super().__call__(UpperCamelCase__		,				**UpperCamelCase__				)






				def       _lowerCAmelCase       (	self		,				**_SCREAMING_SNAKE_CASE				) ->				Optional[Any]:
						snake_case_				:							Tuple						 =       {}
						if "candidate_labels" in kwargs:
								snake_case_				:							str						 =       kwargs["candidate_labels"]
						if "hypothesis_template" in kwargs:
								snake_case_				:							Tuple						 =       kwargs["hypothesis_template"]

						return preprocess_params, {}, {}






				def       _lowerCAmelCase       (	self		,				_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE=None		,				_SCREAMING_SNAKE_CASE="This is a sound of {}."				) ->				Union[str, Any]:







						if isinstance(UpperCamelCase__		,				UpperCamelCase__				):
								if audio.startswith("http://"				) or audio.startswith("https://"				):
										# We need to actually check for a real protocol, otherwise it's impossible to use a local file
										# like http_huggingface_co.png
										snake_case_				:							Optional[int]						 =       requests.get(UpperCamelCase__				).content
								else:
										with open(UpperCamelCase__		,				"rb"				) as f:
												snake_case_				:							str						 =       f.read()

						if isinstance(UpperCamelCase__		,				UpperCamelCase__				):
								snake_case_				:							Tuple						 =       ffmpeg_read(UpperCamelCase__		,				self.feature_extractor.sampling_rate				)

						if not isinstance(UpperCamelCase__		,				np.ndarray				):
								raise ValueError("We expect a numpy ndarray as input"				)
						if len(audio.shape				) != 1:
								raise ValueError("We expect a single channel audio input for ZeroShotAudioClassificationPipeline"				)

						snake_case_				:							List[Any]						 =       self.feature_extractor(
						    [audio]		,				sampling_rate=self.feature_extractor.sampling_rate		,				return_tensors="pt"				)
						snake_case_				:							Optional[Any]						 =       candidate_labels
						snake_case_				:							List[str]						 =       [hypothesis_template.format(UpperCamelCase__				) for x in candidate_labels]
						snake_case_				:							List[str]						 =       self.tokenizer(UpperCamelCase__		,				return_tensors=self.framework		,				padding=UpperCamelCase__				)
						snake_case_				:							Dict						 =       [text_inputs]
						return inputs






				def       _lowerCAmelCase       (	self		,				_SCREAMING_SNAKE_CASE				) ->				Union[str, Any]:
						snake_case_				:							List[str]						 =       model_inputs.pop("candidate_labels"				)
						snake_case_				:							Union[str, Any]						 =       model_inputs.pop("text_inputs"				)
						if isinstance(text_inputs[0]		,				UpperCamelCase__				):
								snake_case_				:							Tuple						 =       text_inputs[0]
						else:
								# Batching case.
								snake_case_				:							Any						 =       text_inputs[0][0]

						snake_case_				:							Optional[Any]						 =       self.model(**UpperCamelCase__		,				**UpperCamelCase__				)

						snake_case_				:							Tuple						 =       {
						    "candidate_labels": candidate_labels,
						    "logits": outputs.logits_per_audio,
						}
						return model_outputs






				def       _lowerCAmelCase       (	self		,				_SCREAMING_SNAKE_CASE				) ->				Optional[Any]:
						snake_case_				:							int						 =       model_outputs.pop("candidate_labels"				)
						snake_case_				:							str						 =       model_outputs["logits"][0]

						if self.framework == "pt":
								snake_case_				:							List[Any]						 =       logits.softmax(dim=0				)
								snake_case_				:							List[Any]						 =       probs.tolist()
						else:
								raise ValueError("`tf` framework not supported."				)

						snake_case_				:							Dict						 =       [
						    {"score": score, "label": candidate_label}
						    for score, candidate_label in sorted(zip(UpperCamelCase__		,				UpperCamelCase__				)		,				key=lambda _SCREAMING_SNAKE_CASE				: -x[0]				)
						]
						return result








import qiskit

def      lowerCAmelCase__	(    _a       :			int  ,      _a       :			int    ):
		snake_case_				:							Tuple						 =       qiskit.Aer.get_backend("aer_simulator"    )

		# Create a Quantum Circuit acting on the q register
		snake_case_				:							Any						 =       qiskit.QuantumCircuit(_a  ,      _a    )

		# Apply X (NOT) Gate to Qubits 0 & 1
		circuit.x(0    )
		circuit.x(1    )

		# Map the quantum measurement to the classical bits
		circuit.measure([0, 1]  ,      [0, 1]    )

		# Execute the circuit on the qasm simulator
		snake_case_				:							Any						 =       qiskit.execute(_a  ,      _a  ,      shots=10_00    )

		# Return the histogram data of the results of the experiment.
		return job.result().get_counts(_a    )


if __name__ == "__main__":
							lowercase  :							List[Any]			  =    single_qubit_measure(2, 2)
							print(F"""Total count for various states are: {counts}""")
