'''simple docstring'''




from __future__ import annotations

import os
import tempfile
import unittest

import numpy as np
from huggingface_hub import hf_hub_download

from transformers import is_tensorflow_text_available, is_tf_available
from transformers.testing_utils import require_tensorflow_text, require_tf, slow

from ..test_modeling_tf_common import floats_tensor
from .test_framework_agnostic import GenerationIntegrationTestsMixin


if is_tf_available():
  import tensorflow as tf

  from transformers import (
      AutoTokenizer,
      TFAutoModelForCausalLM,
      TFAutoModelForSeqaSeqLM,
      TFAutoModelForSpeechSeqaSeq,
      TFAutoModelForVisionaSeq,
      TFBartForConditionalGeneration,
      TFLogitsProcessorList,
      TFMinLengthLogitsProcessor,
      tf_top_k_top_p_filtering,
  )

if is_tensorflow_text_available():
  import tensorflow_text as text




@require_tf
class    a__				(       unittest.TestCase			):






     def        SCREAMING_SNAKE_CASE__       (			self		:		int   ):





         """simple docstring"""



         __lowerCamelCase          =  tf.convert_to_tensor(
             [
                 [
                     8.2_22_09_91,  # 3rd highest value; idx. 0
                     -0.5_62_00_44,
                     5.23_22_97_52,
                     4.0_38_63_93,
                     -6.8_79_83_78,
                     -0.54_78_58_02,
                     -3.2_01_21_53,
                     2.92_77_71_76,
                     1.88_17_19_53,
                     7.35_34_12_76,  # 5th highest value; idx. 9
                     8.43_20_78_33,  # 2nd highest value; idx. 10
                     -9.85_71_18_36,
                     -5.96_20_92_36,
                     -1.13_03_91_61,
                     -7.1_11_52_94,
                     -0.8_36_96_33,
                     -5.3_18_64_08,
                     7.06_42_74_07,
                     0.81_36_93_44,
                     -0.82_02_38_17,
                     -5.9_17_97_96,
                     0.58_81_34_43,
                     -6.99_77_84_38,
                     4.71_55_11_89,
                     -0.18_77_16_37,
                     7.44_02_07_59,  # 4th highest value; idx. 25
                     9.38_45_09_87,  # 1st highest value; idx. 26
                     2.12_66_29_41,
                     -9.32_56_20_38,
                     2.35_65_25_22,
                 ],  # cummulative prob of 5 highest values <= 0.6
                 [
                     0.58_42_55_18,
                     4.53_13_92_38,
                     -5.57_51_04_64,
                     -6.28_03_06_99,
                     -7.19_52_95_03,
                     -4.02_12_25_51,
                     1.39_33_70_37,
                     -6.06_70_70_57,
                     1.59_48_05_17,
                     -9.64_31_19,
                     0.03_90_77_99,
                     0.67_23_17_62,
                     -8.88_20_67_26,
                     6.27_11_59_22,  # 4th highest value; idx. 13
                     2.28_52_07_23,
                     4.82_76_75_06,
                     4.30_42_13_68,
                     8.8_27_53_13,  # 2nd highest value; idx. 17
                     5.44_02_99_58,  # 5th highest value; idx. 18
                     -4.4_73_57_94,
                     7.38_57_95_36,  # 3rd highest value; idx. 20
                     -2.91_05_16_63,
                     2.61_94_60_77,
                     -2.5_67_47_62,
                     -9.48_95_93_02,
                     -4.02_92_26_45,
                     -1.35_41_69_18,
                     9.67_70_23_23,  # 1st highest value; idx. 27
                     -5.89_47_85_53,
                     1.85_37_04_67,
                 ],  # cummulative prob of 5 highest values <= 0.6
             ]  ,    dtype=tf.floataa  ,    )

         __lowerCamelCase          =  tf.convert_to_tensor(
             [[0, 0], [0, 9], [0, 10], [0, 25], [0, 26], [1, 13], [1, 17], [1, 18], [1, 20], [1, 27]]  ,    dtype=tf.intaa  ,    )  # expected non filtered idx as noted above

         __lowerCamelCase          =  tf.convert_to_tensor(
             [8.22_20_99, 7.3_53_41_26, 8.43_20_78, 7.4_40_20_75, 9.3_84_51, 6.27_11_59, 8.82_75_31, 5.4_40_29_95, 7.3_85_79_56, 9.67_70_23]  ,    dtype=tf.floataa  ,    )  # expected non filtered values as noted above

         __lowerCamelCase          =  tf_top_k_top_p_filtering(snake_case__  ,    top_k=10  ,    top_p=0.6  ,    min_tokens_to_keep=4   )

         __lowerCamelCase          =  output[output != -float('''inf'''   )]
         __lowerCamelCase          =  tf.cast(
             tf.where(tf.not_equal(snake_case__  ,    tf.constant(-float('''inf'''   )  ,    dtype=tf.floataa   )   )   )  ,    dtype=tf.intaa  ,    )

         tf.debugging.assert_near(snake_case__  ,    snake_case__  ,    rtol=1e-1_2   )
         tf.debugging.assert_equal(snake_case__  ,    snake_case__   )




@require_tf
class    a__				(       unittest.TestCase							,       A_			):
     # setting framework_dependent_parameters needs to be gated, just like its contents' imports
     if is_tf_available():
          lowerCamelCase  :					str							={
              "AutoModelForCausalLM": TFAutoModelForCausalLM,
              "AutoModelForSpeechSeq2Seq": TFAutoModelForSpeechSeqaSeq,
              "AutoModelForSeq2SeqLM": TFAutoModelForSeqaSeqLM,
              "AutoModelForVision2Seq": TFAutoModelForVisionaSeq,
              "LogitsProcessorList": TFLogitsProcessorList,
              "MinLengthLogitsProcessor": TFMinLengthLogitsProcessor,
              "create_tensor_fn": tf.convert_to_tensor,
              "floats_tensor": floats_tensor,
              "return_tensors": "tf",
          }






     @slow
     def        SCREAMING_SNAKE_CASE__       (			self		:		Optional[Any]   ):





         """simple docstring"""



         __lowerCamelCase          =  TFAutoModelForCausalLM.from_pretrained('''hf-internal-testing/tiny-random-gpt2'''   )
         __lowerCamelCase          =  2
         __lowerCamelCase          =  2




         class    a__				(       tf.Module			):






              def __init__(			self		:		Optional[Any]  ,    a		:		Tuple   ):





                  """simple docstring"""



                  super(snake_case__  ,    self   ).__init__()
                  __lowerCamelCase          =  model






              @tf.function(
                  input_signature=(
                      tf.TensorSpec((None, input_length)  ,    tf.intaa  ,    name='''input_ids'''   ),
                      tf.TensorSpec((None, input_length)  ,    tf.intaa  ,    name='''attention_mask'''   ),
                  )  ,    jit_compile=snake_case__  ,    )
              def        SCREAMING_SNAKE_CASE__       (			self		:		Union[str, Any]  ,    a		:		Tuple  ,    a		:		Dict   ):





                  """simple docstring"""



                  __lowerCamelCase          =  self.model.generate(
                      input_ids=snake_case__  ,    attention_mask=snake_case__  ,    max_new_tokens=snake_case__  ,    return_dict_in_generate=snake_case__  ,    )
                  return {"sequences": outputs["sequences"]}
         __lowerCamelCase          =  [[2, 0], [1_02, 1_03]]
         __lowerCamelCase          =  [[1, 0], [1, 1]]
         __lowerCamelCase          =  DummyModel(model=snake_case__   )
         with tempfile.TemporaryDirectory() as tmp_dir:
             tf.saved_model.save(snake_case__  ,    snake_case__  ,    signatures={'''serving_default''': dummy_model.serving}   )
             __lowerCamelCase          =  tf.saved_model.load(snake_case__   ).signatures["serving_default"]
             for batch_size in range(1  ,    len(snake_case__   ) + 1   ):
                 __lowerCamelCase          =  {
                     "input_ids": tf.constant(dummy_input_ids[:batch_size]   ),
                     "attention_mask": tf.constant(dummy_attention_masks[:batch_size]   ),
                 }
                 __lowerCamelCase          =  serving_func(**snake_case__   )["sequences"]
                 __lowerCamelCase          =  test_model.generate(**snake_case__  ,    max_new_tokens=snake_case__   )
                 tf.debugging.assert_equal(snake_case__  ,    snake_case__   )






     @slow
     def        SCREAMING_SNAKE_CASE__       (			self		:		Dict   ):





         """simple docstring"""



         __lowerCamelCase          =  TFAutoModelForCausalLM.from_pretrained('''hf-internal-testing/tiny-random-gpt2'''   )
         __lowerCamelCase          =  1
         __lowerCamelCase          =  2




         class    a__				(       tf.Module			):






              def __init__(			self		:		List[Any]  ,    a		:		Optional[int]   ):





                  """simple docstring"""



                  super(snake_case__  ,    self   ).__init__()
                  __lowerCamelCase          =  model






              @tf.function(
                  input_signature=(
                      tf.TensorSpec((batch_size, None)  ,    tf.intaa  ,    name='''input_ids'''   ),
                      tf.TensorSpec((batch_size, None)  ,    tf.intaa  ,    name='''attention_mask'''   ),
                  )  ,    jit_compile=snake_case__  ,    )
              def        SCREAMING_SNAKE_CASE__       (			self		:		Any  ,    a		:		int  ,    a		:		List[str]   ):





                  """simple docstring"""



                  __lowerCamelCase          =  self.model.generate(
                      input_ids=snake_case__  ,    attention_mask=snake_case__  ,    max_new_tokens=snake_case__  ,    return_dict_in_generate=snake_case__  ,    )
                  return {"sequences": outputs["sequences"]}
         __lowerCamelCase          =  [[2], [1_02, 1_03]]
         __lowerCamelCase          =  [[1], [1, 1]]
         __lowerCamelCase          =  DummyModel(model=snake_case__   )
         with tempfile.TemporaryDirectory() as tmp_dir:
             tf.saved_model.save(snake_case__  ,    snake_case__  ,    signatures={'''serving_default''': dummy_model.serving}   )
             __lowerCamelCase          =  tf.saved_model.load(snake_case__   ).signatures["serving_default"]
             for input_row in range(len(snake_case__   )   ):
                 __lowerCamelCase          =  {
                     "input_ids": tf.constant([dummy_input_ids[input_row]]   ),
                     "attention_mask": tf.constant([dummy_attention_masks[input_row]]   ),
                 }
                 __lowerCamelCase          =  serving_func(**snake_case__   )["sequences"]
                 __lowerCamelCase          =  test_model.generate(**snake_case__  ,    max_new_tokens=snake_case__   )
                 tf.debugging.assert_equal(snake_case__  ,    snake_case__   )






     @slow
     @require_tensorflow_text
     def        SCREAMING_SNAKE_CASE__       (			self		:		List[Any]   ):





         """simple docstring"""



         with tempfile.TemporaryDirectory() as tmp_dir:
             # file needed to load the TF tokenizer
             hf_hub_download(repo_id='''google/flan-t5-small'''  ,    filename='''spiece.model'''  ,    local_dir=snake_case__   )




             class    a__				(       tf.keras.layers.Layer			):






                  def __init__(			self		:		str   ):





                      """simple docstring"""



                      super().__init__()
                      __lowerCamelCase          =  text.SentencepieceTokenizer(
                          model=tf.io.gfile.GFile(os.path.join(snake_case__  ,    '''spiece.model'''   )  ,    '''rb'''   ).read()   )
                      __lowerCamelCase          =  TFAutoModelForSeqaSeqLM.from_pretrained('''hf-internal-testing/tiny-random-t5'''   )






                  def        SCREAMING_SNAKE_CASE__       (			self		:		List[str]  ,    a		:		str  ,    *a		:		Any  ,    **a		:		List[str]   ):





                      """simple docstring"""



                      __lowerCamelCase          =  self.tokenizer.tokenize(snake_case__   )
                      __lowerCamelCase          =  text.pad_model_inputs(
                          snake_case__  ,    max_seq_length=64  ,    pad_value=self.model.config.pad_token_id   )
                      __lowerCamelCase          =  self.model.generate(input_ids=snake_case__  ,    attention_mask=snake_case__   )
                      return self.tokenizer.detokenize(snake_case__   )
             __lowerCamelCase          =  CompleteSentenceTransformer()
             __lowerCamelCase          =  tf.keras.layers.Input(shape=(1,)  ,    dtype=tf.string  ,    name='''inputs'''   )
             __lowerCamelCase          =  complete_model(snake_case__   )
             __lowerCamelCase          =  tf.keras.Model(snake_case__  ,    snake_case__   )
             keras_model.save(snake_case__   )






     def        SCREAMING_SNAKE_CASE__       (			self		:		List[Any]   ):





         """simple docstring"""



         __lowerCamelCase          =  {
             "do_sample": True,
             "num_beams": 1,
             "top_p": 0.7,
             "top_k": 10,
             "temperature": 0.7,
         }
         __lowerCamelCase          =  14

         __lowerCamelCase          =  AutoTokenizer.from_pretrained('''hf-internal-testing/tiny-random-gpt2'''   )
         __lowerCamelCase          =  "Hello, my dog is cute and"
         __lowerCamelCase          =  tokenizer(snake_case__  ,    return_tensors='''tf'''   )
         __lowerCamelCase          =  TFAutoModelForCausalLM.from_pretrained('''hf-internal-testing/tiny-random-gpt2'''   )

         __lowerCamelCase          =  6_38
         # forces the generation to happen on CPU, to avoid GPU-related quirks
         with tf.device(''':/CPU:0'''   ):
             tf.random.set_seed(0   )
             __lowerCamelCase          =  model.generate(**snake_case__  ,    eos_token_id=snake_case__  ,    **snake_case__   )
         self.assertTrue(expectation == len(generated_tokens[0]   )   )

         __lowerCamelCase          =  [6_38, 1_98]
         with tf.device(''':/CPU:0'''   ):
             tf.random.set_seed(0   )
             __lowerCamelCase          =  model.generate(**snake_case__  ,    eos_token_id=snake_case__  ,    **snake_case__   )
         self.assertTrue(expectation == len(generated_tokens[0]   )   )






     def        SCREAMING_SNAKE_CASE__       (			self		:		List[str]   ):





         """simple docstring"""



         __lowerCamelCase          =  AutoTokenizer.from_pretrained('''hf-internal-testing/tiny-random-bart'''   )
         __lowerCamelCase          =  "Hugging Face is a technology company based in New York and Paris."
         __lowerCamelCase          =  bart_tokenizer(snake_case__  ,    return_tensors='''tf'''   ).input_ids
         __lowerCamelCase          =  TFBartForConditionalGeneration.from_pretrained('''hf-internal-testing/tiny-random-bart'''   )
         __lowerCamelCase          =  bart_model.generate(snake_case__   ).numpy()




         class    a__				(       A_			):






              def        SCREAMING_SNAKE_CASE__       (			self		:		Dict  ,    a		:		Optional[Any]  ,    a		:		int=None  ,    **a		:		int   ):





                  """simple docstring"""



                  return super().call(snake_case__  ,    **snake_case__   )
         __lowerCamelCase          =  FakeBart.from_pretrained('''hf-internal-testing/tiny-random-bart'''   )
         __lowerCamelCase          =  bart_model.generate(snake_case__  ,    foo='''bar'''   ).numpy()
         self.assertTrue(np.array_equal(snake_case__  ,    snake_case__   )   )




         class    a__				(       bart_model.model.encoder.__class__			):






              def        SCREAMING_SNAKE_CASE__       (			self		:		Optional[int]  ,    a		:		Tuple  ,    **a		:		Optional[Any]   ):





                  """simple docstring"""



                  return super().call(snake_case__  ,    **snake_case__   )
         __lowerCamelCase          =  FakeEncoder(bart_model.config  ,    bart_model.model.shared   )
         __lowerCamelCase          =  fake_encoder

         # Normal generation still works (the output will be different because the encoder weights are different)
         __lowerCamelCase          =  bart_model.generate(snake_case__   ).numpy()
         with self.assertRaises(snake_case__   ):
             # FakeEncoder.call() accepts **kwargs -> no filtering -> value error due to unexpected input "foo"
             bart_model.generate(snake_case__  ,    foo='''bar'''   )



'''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.auto import AutoModelForSeqaSeqLM, AutoTokenizer
from .base import PipelineTool


__UpperCAmelCase												={
    "Acehnese Arabic": "ace_Arab",
    "Acehnese Latin": "ace_Latn",
    "Mesopotamian Arabic": "acm_Arab",
    "Ta'izzi-Adeni Arabic": "acq_Arab",
    "Tunisian Arabic": "aeb_Arab",
    "Afrikaans": "afr_Latn",
    "South Levantine Arabic": "ajp_Arab",
    "Akan": "aka_Latn",
    "Amharic": "amh_Ethi",
    "North Levantine Arabic": "apc_Arab",
    "Modern Standard Arabic": "arb_Arab",
    "Modern Standard Arabic Romanized": "arb_Latn",
    "Najdi Arabic": "ars_Arab",
    "Moroccan Arabic": "ary_Arab",
    "Egyptian Arabic": "arz_Arab",
    "Assamese": "asm_Beng",
    "Asturian": "ast_Latn",
    "Awadhi": "awa_Deva",
    "Central Aymara": "ayr_Latn",
    "South Azerbaijani": "azb_Arab",
    "North Azerbaijani": "azj_Latn",
    "Bashkir": "bak_Cyrl",
    "Bambara": "bam_Latn",
    "Balinese": "ban_Latn",
    "Belarusian": "bel_Cyrl",
    "Bemba": "bem_Latn",
    "Bengali": "ben_Beng",
    "Bhojpuri": "bho_Deva",
    "Banjar Arabic": "bjn_Arab",
    "Banjar Latin": "bjn_Latn",
    "Standard Tibetan": "bod_Tibt",
    "Bosnian": "bos_Latn",
    "Buginese": "bug_Latn",
    "Bulgarian": "bul_Cyrl",
    "Catalan": "cat_Latn",
    "Cebuano": "ceb_Latn",
    "Czech": "ces_Latn",
    "Chokwe": "cjk_Latn",
    "Central Kurdish": "ckb_Arab",
    "Crimean Tatar": "crh_Latn",
    "Welsh": "cym_Latn",
    "Danish": "dan_Latn",
    "German": "deu_Latn",
    "Southwestern Dinka": "dik_Latn",
    "Dyula": "dyu_Latn",
    "Dzongkha": "dzo_Tibt",
    "Greek": "ell_Grek",
    "English": "eng_Latn",
    "Esperanto": "epo_Latn",
    "Estonian": "est_Latn",
    "Basque": "eus_Latn",
    "Ewe": "ewe_Latn",
    "Faroese": "fao_Latn",
    "Fijian": "fij_Latn",
    "Finnish": "fin_Latn",
    "Fon": "fon_Latn",
    "French": "fra_Latn",
    "Friulian": "fur_Latn",
    "Nigerian Fulfulde": "fuv_Latn",
    "Scottish Gaelic": "gla_Latn",
    "Irish": "gle_Latn",
    "Galician": "glg_Latn",
    "Guarani": "grn_Latn",
    "Gujarati": "guj_Gujr",
    "Haitian Creole": "hat_Latn",
    "Hausa": "hau_Latn",
    "Hebrew": "heb_Hebr",
    "Hindi": "hin_Deva",
    "Chhattisgarhi": "hne_Deva",
    "Croatian": "hrv_Latn",
    "Hungarian": "hun_Latn",
    "Armenian": "hye_Armn",
    "Igbo": "ibo_Latn",
    "Ilocano": "ilo_Latn",
    "Indonesian": "ind_Latn",
    "Icelandic": "isl_Latn",
    "Italian": "ita_Latn",
    "Javanese": "jav_Latn",
    "Japanese": "jpn_Jpan",
    "Kabyle": "kab_Latn",
    "Jingpho": "kac_Latn",
    "Kamba": "kam_Latn",
    "Kannada": "kan_Knda",
    "Kashmiri Arabic": "kas_Arab",
    "Kashmiri Devanagari": "kas_Deva",
    "Georgian": "kat_Geor",
    "Central Kanuri Arabic": "knc_Arab",
    "Central Kanuri Latin": "knc_Latn",
    "Kazakh": "kaz_Cyrl",
    "Kabiyè": "kbp_Latn",
    "Kabuverdianu": "kea_Latn",
    "Khmer": "khm_Khmr",
    "Kikuyu": "kik_Latn",
    "Kinyarwanda": "kin_Latn",
    "Kyrgyz": "kir_Cyrl",
    "Kimbundu": "kmb_Latn",
    "Northern Kurdish": "kmr_Latn",
    "Kikongo": "kon_Latn",
    "Korean": "kor_Hang",
    "Lao": "lao_Laoo",
    "Ligurian": "lij_Latn",
    "Limburgish": "lim_Latn",
    "Lingala": "lin_Latn",
    "Lithuanian": "lit_Latn",
    "Lombard": "lmo_Latn",
    "Latgalian": "ltg_Latn",
    "Luxembourgish": "ltz_Latn",
    "Luba-Kasai": "lua_Latn",
    "Ganda": "lug_Latn",
    "Luo": "luo_Latn",
    "Mizo": "lus_Latn",
    "Standard Latvian": "lvs_Latn",
    "Magahi": "mag_Deva",
    "Maithili": "mai_Deva",
    "Malayalam": "mal_Mlym",
    "Marathi": "mar_Deva",
    "Minangkabau Arabic ": "min_Arab",
    "Minangkabau Latin": "min_Latn",
    "Macedonian": "mkd_Cyrl",
    "Plateau Malagasy": "plt_Latn",
    "Maltese": "mlt_Latn",
    "Meitei Bengali": "mni_Beng",
    "Halh Mongolian": "khk_Cyrl",
    "Mossi": "mos_Latn",
    "Maori": "mri_Latn",
    "Burmese": "mya_Mymr",
    "Dutch": "nld_Latn",
    "Norwegian Nynorsk": "nno_Latn",
    "Norwegian Bokmål": "nob_Latn",
    "Nepali": "npi_Deva",
    "Northern Sotho": "nso_Latn",
    "Nuer": "nus_Latn",
    "Nyanja": "nya_Latn",
    "Occitan": "oci_Latn",
    "West Central Oromo": "gaz_Latn",
    "Odia": "ory_Orya",
    "Pangasinan": "pag_Latn",
    "Eastern Panjabi": "pan_Guru",
    "Papiamento": "pap_Latn",
    "Western Persian": "pes_Arab",
    "Polish": "pol_Latn",
    "Portuguese": "por_Latn",
    "Dari": "prs_Arab",
    "Southern Pashto": "pbt_Arab",
    "Ayacucho Quechua": "quy_Latn",
    "Romanian": "ron_Latn",
    "Rundi": "run_Latn",
    "Russian": "rus_Cyrl",
    "Sango": "sag_Latn",
    "Sanskrit": "san_Deva",
    "Santali": "sat_Olck",
    "Sicilian": "scn_Latn",
    "Shan": "shn_Mymr",
    "Sinhala": "sin_Sinh",
    "Slovak": "slk_Latn",
    "Slovenian": "slv_Latn",
    "Samoan": "smo_Latn",
    "Shona": "sna_Latn",
    "Sindhi": "snd_Arab",
    "Somali": "som_Latn",
    "Southern Sotho": "sot_Latn",
    "Spanish": "spa_Latn",
    "Tosk Albanian": "als_Latn",
    "Sardinian": "srd_Latn",
    "Serbian": "srp_Cyrl",
    "Swati": "ssw_Latn",
    "Sundanese": "sun_Latn",
    "Swedish": "swe_Latn",
    "Swahili": "swh_Latn",
    "Silesian": "szl_Latn",
    "Tamil": "tam_Taml",
    "Tatar": "tat_Cyrl",
    "Telugu": "tel_Telu",
    "Tajik": "tgk_Cyrl",
    "Tagalog": "tgl_Latn",
    "Thai": "tha_Thai",
    "Tigrinya": "tir_Ethi",
    "Tamasheq Latin": "taq_Latn",
    "Tamasheq Tifinagh": "taq_Tfng",
    "Tok Pisin": "tpi_Latn",
    "Tswana": "tsn_Latn",
    "Tsonga": "tso_Latn",
    "Turkmen": "tuk_Latn",
    "Tumbuka": "tum_Latn",
    "Turkish": "tur_Latn",
    "Twi": "twi_Latn",
    "Central Atlas Tamazight": "tzm_Tfng",
    "Uyghur": "uig_Arab",
    "Ukrainian": "ukr_Cyrl",
    "Umbundu": "umb_Latn",
    "Urdu": "urd_Arab",
    "Northern Uzbek": "uzn_Latn",
    "Venetian": "vec_Latn",
    "Vietnamese": "vie_Latn",
    "Waray": "war_Latn",
    "Wolof": "wol_Latn",
    "Xhosa": "xho_Latn",
    "Eastern Yiddish": "ydd_Hebr",
    "Yoruba": "yor_Latn",
    "Yue Chinese": "yue_Hant",
    "Chinese Simplified": "zho_Hans",
    "Chinese Traditional": "zho_Hant",
    "Standard Malay": "zsm_Latn",
    "Zulu": "zul_Latn",
}




class    a__				(       UpperCAmelCase__			):
     lowerCamelCase  :					Any							="facebook/nllb-200-distilled-600M"
     lowerCamelCase  :					Optional[Any]							=(
         "This is a tool that translates text from a language to another. It takes three inputs: `text`, which should "
         "be the text to translate, `src_lang`, which should be the language of the text to translate and `tgt_lang`, "
         "which should be the language for the desired ouput language. Both `src_lang` and `tgt_lang` are written in "
         "plain English, such as 'Romanian', or 'Albanian'. It returns the text translated in `tgt_lang`."
     )
     lowerCamelCase  :					Tuple							="translator"
     lowerCamelCase  :					Any							=AutoTokenizer
     lowerCamelCase  :					Dict							=AutoModelForSeqaSeqLM
     lowerCamelCase  :					Union[str, Any]							=LANGUAGE_CODES

     lowerCamelCase  :					Any							=["text", "text", "text"]
     lowerCamelCase  :					Union[str, Any]							=["text"]






     def        SCREAMING_SNAKE_CASE__       (			self		:		Optional[int]  ,    a		:		Any  ,    a		:		List[str]  ,    a		:		Any   ):





         """simple docstring"""



         if src_lang not in self.lang_to_code:
             raise ValueError(f"""{src_lang} is not a supported language."""   )
         if tgt_lang not in self.lang_to_code:
             raise ValueError(f"""{tgt_lang} is not a supported language."""   )
         __lowerCamelCase          =  self.lang_to_code[src_lang]
         __lowerCamelCase          =  self.lang_to_code[tgt_lang]
         return self.pre_processor._build_translation_inputs(
             a  ,    return_tensors='''pt'''  ,    src_lang=a  ,    tgt_lang=a   )






     def        SCREAMING_SNAKE_CASE__       (			self		:		str  ,    a		:		Optional[Any]   ):





         """simple docstring"""



         return self.model.generate(**a   )






     def        SCREAMING_SNAKE_CASE__       (			self		:		Optional[int]  ,    a		:		str   ):





         """simple docstring"""



         return self.post_processor.decode(outputs[0].tolist()  ,    skip_special_tokens=a   )
