



import numpy as np
import qiskit




def       __UpperCamelCase      (    _lowerCAmelCase = 8 ,	_lowerCAmelCase = None						)			->    str:



    """simple docstring"""






    A					:			List[Any]		=  np.random.default_rng(seed=__UpperCAmelCase						)

    # Roughly 25% of the qubits will contribute to the key.
    # So we take more than we need.
    A					:			Optional[Any]		=  6 * key_len
    # Measurement basis for Alice's qubits.
    A					:			List[Any]		=  rng.integers(2 ,	size=__UpperCAmelCase						)
    # The set of states Alice will prepare.
    A					:			str		=  rng.integers(2 ,	size=__UpperCAmelCase						)
    # Measurement basis for Bob's qubits.
    A					:			int		=  rng.integers(2 ,	size=__UpperCAmelCase						)

    # Quantum Circuit to simulate BB84
    A					:			str		=  qiskit.QuantumCircuit(__UpperCAmelCase ,	name="""BB84"""						)

    # Alice prepares her qubits according to rules above.
    for index, _ in enumerate(__UpperCAmelCase						):
        if alice_state[index] == 1:
            bbaa_circ.x(__UpperCAmelCase						)
        if alice_basis[index] == 1:
            bbaa_circ.h(__UpperCAmelCase						)
    bbaa_circ.barrier()

    # Bob measures the received qubits according to rules above.
    for index, _ in enumerate(__UpperCAmelCase						):
        if bob_basis[index] == 1:
            bbaa_circ.h(__UpperCAmelCase						)

    bbaa_circ.barrier()
    bbaa_circ.measure_all()

    # Simulate the quantum circuit.
    A					:			int		=  qiskit.Aer.get_backend("""aer_simulator"""						)
    # We only need to run one shot because the key is unique.
    # Multiple shots will produce the same key.
    A					:			Optional[int]		=  qiskit.execute(__UpperCAmelCase ,	__UpperCAmelCase ,	shots=1 ,	seed_simulator=__UpperCAmelCase						)
    # Returns the result of measurement.
    A					:			Optional[Any]		=  job.result().get_counts(__UpperCAmelCase						).most_frequent()

    # Extracting the generated key from the simulation results.
    # Only keep measurement results where Alice and Bob chose the same basis.
    A					:			Union[str, Any]		=  """""".join(
        [
            result_bit
            for alice_basis_bit, bob_basis_bit, result_bit in zip(
                __UpperCAmelCase ,	__UpperCAmelCase ,	__UpperCAmelCase						)
            if alice_basis_bit == bob_basis_bit
        ]						)

    # Get final key. Pad with 0 if too short, otherwise truncate.
    A					:			Optional[Any]		=  gen_key[:key_len] if len(__UpperCAmelCase						) >= key_len else gen_key.ljust(__UpperCAmelCase ,	"""0"""						)
    return key


if __name__ == "__main__":
     print(F"""The generated key is : {bbaa(8, seed=0)}""")
     from doctest import testmod

     testmod()










"""simple docstring"""





# Copyright 2023 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from ..models.whisper import WhisperForConditionalGeneration, WhisperProcessor
from .base import PipelineTool



class       __A		(   SCREAMING_SNAKE_CASE_			):
					UpperCAmelCase__								=				"openai/whisper-base"
					UpperCAmelCase__								=				(
					    "This is a tool that transcribes an audio into text. It takes an input named `audio` and returns the "
					    "transcribed text."
					)
					UpperCAmelCase__								=				"transcriber"
					UpperCAmelCase__								=				WhisperProcessor
					UpperCAmelCase__								=				WhisperForConditionalGeneration

					UpperCAmelCase__								=				["audio"]
					UpperCAmelCase__								=				["text"]

					def   lowerCamelCase__   (			self  :      Dict     ,		__snake_case  :      List[str]					)			->							Dict:
											return self.pre_processor(__snake_case     ,		return_tensors="""pt"""					).input_features

					def   lowerCamelCase__   (			self  :      int     ,		__snake_case  :      Union[str, Any]					)			->							List[str]:
											return self.model.generate(inputs=__snake_case					)






					def   lowerCamelCase__   (			self  :      Union[str, Any]     ,		__snake_case  :      List[Any]					)			->							Any:
											return self.pre_processor.batch_decode(__snake_case     ,		skip_special_tokens=__snake_case					)[0]



