class_docstr: Initialize a new Inference Client.
  
  [`InferenceClient`] aims to provide a unified experience to perform inference. The client can be used
  seamlessly with either the (free) Inference API or self-hosted Inference Endpoints.
  
  Args:
      model (`str`, `optional`):
          The model to run inference with. Can be a model id hosted on the Hugging Face Hub, e.g. `bigcode/starcoder`
          or a URL to a deployed Inference Endpoint. Defaults to None, in which case a recommended model is
          automatically selected for the task.
      token (`str`, *optional*):
          Hugging Face token. Will default to the locally saved token. Pass `token=False` if you don't want to send
          your token to the server.
      timeout (`float`, `optional`):
          The maximum number of seconds to wait for a response from the server. Loading a new model in Inference
          API can take up to several minutes. Defaults to None, meaning it will loop until the server is available.
      headers (`Dict[str, str]`, `optional`):
          Additional headers to send to the server. By default only the authorization and user-agent headers are sent.
          Values in this dictionary will override the default values.
      cookies (`Dict[str, str]`, `optional`):
          Additional cookies to send to the server.
docstr: Convert text from one language to another.
  
  Check out https://huggingface.co/tasks/translation for more information on how to choose the best model for
  your specific use case. Source and target languages usually depend on the model.
  However, it is possible to specify source and target languages for certain models. If you are working with one of these models,
  you can use `src_lang` and `tgt_lang` arguments to pass the relevant information.
  You can find this information in the model card.
  
  Args:
      text (`str`):
          A string to be translated.
      model (`str`, *optional*):
          The model to use for the translation task. Can be a model ID hosted on the Hugging Face Hub or a URL to
          a deployed Inference Endpoint. If not provided, the default recommended translation model will be used.
          Defaults to None.
      src_lang (`str`, *optional*):
          Source language of the translation task, i.e. input language. Cannot be passed without `tgt_lang`.
      tgt_lang (`str`, *optional*):
          Target language of the translation task, i.e. output language. Cannot be passed without `src_lang`.
  
  Returns:
      `str`: The generated translated text.
  
  Raises:
      [`InferenceTimeoutError`]:
          If the model is unavailable or the request times out.
      `HTTPError`:
          If the request fails with an HTTP error status code other than HTTP 503.
      `ValueError`:
          If only one of the `src_lang` and `tgt_lang` arguments are provided.
  
  Example:
  ```py
  >>> from huggingface_hub import InferenceClient
  >>> client = InferenceClient()
  >>> client.translation("My name is Wolfgang and I live in Berlin")
  'Mein Name ist Wolfgang und ich lebe in Berlin.'
  >>> client.translation("My name is Wolfgang and I live in Berlin", model="Helsinki-NLP/opus-mt-en-fr")
  "Je m'appelle Wolfgang et je vis à Berlin."
  ```
  
  Specifying languages:
  ```py
  >>> client.translation("My name is Sarah Jessica Parker but you can call me Jessica", model="facebook/mbart-large-50-many-to-many-mmt", src_lang="en_XX", tgt_lang="fr_XX")
  "Mon nom est Sarah Jessica Parker mais vous pouvez m'appeler Jessica"
  ```
docstr_tok: ["Convert","text","from","one","language","to","another",".","Check","out","https",":","\/\/huggingface.co\/tasks\/translation","for","more","information","on","how","to","choose","the","best","model","for","your","specific","use","case",".","Source","and","target","languages","usually","depend","on","the","model",".","However",",","it","is","possible","to","specify","source","and","target","languages","for","certain","models",".","If","you","are","working","with","one","of","these","models",",","you","can","use","`","src_lang","`","and","`","tgt_lang","`","arguments","to","pass","the","relevant","information",".","You","can","find","this","information","in","the","model","card",".","Args",":","text","(","`","str","`",")",":","A","string","to","be","translated",".","model","(","`","str","`",",","*","optional","*",")",":","The","model","to","use","for","the","translation","task",".","Can","be","a","model","ID","hosted","on","the","Hugging","Face","Hub","or","a","URL","to","a","deployed","Inference","Endpoint",".","If","not","provided",",","the","default","recommended","translation","model","will","be","used",".","Defaults","to","None",".","src_lang","(","`","str","`",",","*","optional","*",")",":","Source","language","of","the","translation","task",",","i.e",".","input","language",".","Can","not","be","passed","without","`","tgt_lang","`",".","tgt_lang","(","`","str","`",",","*","optional","*",")",":","Target","language","of","the","translation","task",",","i.e",".","output","language",".","Can","not","be","passed","without","`","src_lang","`",".","Returns",":","`","str","`",":","The","generated","translated","text",".","Raises",":","[","`","InferenceTimeoutError","`","]",":","If","the","model","is","unavailable","or","the","request","times","out",".","`","HTTPError","`",":","If","the","request","fails","with","an","HTTP","error","status","code","other","than","HTTP","503",".","`","ValueError","`",":","If","only","one","of","the","`","src_lang","`","and","`","tgt_lang","`","arguments","are","provided",".","Example",":","``","`","py",">",">",">","from","huggingface_hub","import","InferenceClient",">",">",">","client","=","InferenceClient","(",")",">",">",">","client.translation","(","``","My","name","is","Wolfgang","and","I","live","in","Berlin","''",")","'Mein","Name","ist","Wolfgang","und","ich","lebe","in","Berlin",".","'",">",">",">","client.translation","(","``","My","name","is","Wolfgang","and","I","live","in","Berlin","''",",","model=","''","Helsinki-NLP\/opus-mt-en-fr","''",")","''","Je","m'appelle","Wolfgang","et","je","vis","\u00e0","Berlin",".","''","``","`","Specifying","languages",":","``","`","py",">",">",">","client.translation","(","``","My","name","is","Sarah","Jessica","Parker","but","you","can","call","me","Jessica","''",",","model=","''","facebook\/mbart-large-50-many-to-many-mmt","''",",","src_lang=","''","en_XX","''",",","tgt_lang=","''","fr_XX","''",")","''","Mon","nom","est","Sarah","Jessica","Parker","mais","vous","pouvez","m'appeler","Jessica","''","``","`"]
code: def translation(
      self,
      text: str,
      *,
      model: Optional[str] = None,
      src_lang: Optional[str] = None,
      tgt_lang: Optional[str] = None,
  ) -> str:
      """
      Convert text from one language to another.
  
      Check out https://huggingface.co/tasks/translation for more information on how to choose the best model for
      your specific use case. Source and target languages usually depend on the model.
      However, it is possible to specify source and target languages for certain models. If you are working with one of these models,
      you can use `src_lang` and `tgt_lang` arguments to pass the relevant information.
      You can find this information in the model card.
  
      Args:
          text (`str`):
              A string to be translated.
          model (`str`, *optional*):
              The model to use for the translation task. Can be a model ID hosted on the Hugging Face Hub or a URL to
              a deployed Inference Endpoint. If not provided, the default recommended translation model will be used.
              Defaults to None.
          src_lang (`str`, *optional*):
              Source language of the translation task, i.e. input language. Cannot be passed without `tgt_lang`.
          tgt_lang (`str`, *optional*):
              Target language of the translation task, i.e. output language. Cannot be passed without `src_lang`.
  
      Returns:
          `str`: The generated translated text.
  
      Raises:
          [`InferenceTimeoutError`]:
              If the model is unavailable or the request times out.
          `HTTPError`:
              If the request fails with an HTTP error status code other than HTTP 503.
          `ValueError`:
              If only one of the `src_lang` and `tgt_lang` arguments are provided.
  
      Example:
      ```py
      >>> from huggingface_hub import InferenceClient
      >>> client = InferenceClient()
      >>> client.translation("My name is Wolfgang and I live in Berlin")
      'Mein Name ist Wolfgang und ich lebe in Berlin.'
      >>> client.translation("My name is Wolfgang and I live in Berlin", model="Helsinki-NLP/opus-mt-en-fr")
      "Je m'appelle Wolfgang et je vis à Berlin."
      ```
  
      Specifying languages:
      ```py
      >>> client.translation("My name is Sarah Jessica Parker but you can call me Jessica", model="facebook/mbart-large-50-many-to-many-mmt", src_lang="en_XX", tgt_lang="fr_XX")
      "Mon nom est Sarah Jessica Parker mais vous pouvez m\'appeler Jessica"
      ```
      """
      # Throw error if only one of `src_lang` and `tgt_lang` was given
      if src_lang is not None and tgt_lang is None:
          raise ValueError(
              "You cannot specify `src_lang` without specifying `tgt_lang`."
          )
  
      if src_lang is None and tgt_lang is not None:
          raise ValueError(
              "You cannot specify `tgt_lang` without specifying `src_lang`."
          )
  
      # If both `src_lang` and `tgt_lang` are given, pass them to the request body
      payload: Dict = {"inputs": text}
      if src_lang and tgt_lang:
          payload["parameters"] = {
              "src_lang": src_lang,
              "tgt_lang": tgt_lang,
          }
      response = self.post(
          json=payload, model=model, task="translation"
      )
      return _bytes_to_dict(response)[0]["translation_text"]
  
imports: import logging
  import time
  import warnings
  from dataclasses import asdict
  from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Literal, Optional, Union, overload
  from requests import HTTPError
  from requests.structures import CaseInsensitiveDict
  from huggingface_hub.constants import ALL_INFERENCE_API_FRAMEWORKS, INFERENCE_ENDPOINT, MAIN_INFERENCE_API_FRAMEWORKS
  from huggingface_hub.inference._common import TASKS_EXPECTING_IMAGES, ContentT, InferenceTimeoutError, ModelStatus, _b64_encode, _b64_to_image, _bytes_to_dict, _bytes_to_image, _bytes_to_list, _fetch_recommended_models, _import_numpy, _is_tgi_server, _open_as_binary, _set_as_non_tgi, _stream_text_generation_response
  from huggingface_hub.inference._text_generation import TextGenerationParameters, TextGenerationRequest, TextGenerationResponse, TextGenerationStreamResponse, raise_text_generation_error
  from huggingface_hub.inference._types import ClassificationOutput, ConversationalOutput, FillMaskOutput, ImageSegmentationOutput, ObjectDetectionOutput, QuestionAnsweringOutput, TableQuestionAnsweringOutput, TokenClassificationOutput
  from huggingface_hub.utils import BadRequestError, build_hf_headers, get_session, hf_raise_for_status
label_desc: Use image node_id 34 for calling the InferenceClient obj's underlying member method code with example usage: obj.translation(text) and returns: _bytes_to_dict