class_docstr: Transcribe and parse audio files with OpenAI Whisper model.
  
  Audio transcription with OpenAI Whisper model locally from transformers.
  
  Parameters:
  device - device to use
      NOTE: By default uses the gpu if available,
      if you want to use cpu, please set device = "cpu"
  lang_model - whisper model to use, for example "openai/whisper-medium"
  forced_decoder_ids - id states for decoder in multilanguage model,
      usage example:
      from transformers import WhisperProcessor
      processor = WhisperProcessor.from_pretrained("openai/whisper-medium")
      forced_decoder_ids = WhisperProcessor.get_decoder_prompt_ids(language="french",
        task="transcribe")
      forced_decoder_ids = WhisperProcessor.get_decoder_prompt_ids(language="french",
      task="translate")
docstr: Initialize the parser.
  
  Args:
      device: device to use.
      lang_model: whisper model to use, for example "openai/whisper-medium".
        Defaults to None.
      forced_decoder_ids: id states for decoder in a multilanguage model.
        Defaults to None.
code: def __init__(
      self,
      device: str = "gpu",
      device_id: int = 0,
      lang_model: Optional[str] = None,
      forced_decoder_ids: Optional[Tuple[Dict]] = None,
      use_better=True,
      use_faster=False,
  ):
      """Initialize the parser.
  
      Args:
          device: device to use.
          lang_model: whisper model to use, for example "openai/whisper-medium".
            Defaults to None.
          forced_decoder_ids: id states for decoder in a multilanguage model.
            Defaults to None.
      """
      try:
          from transformers import pipeline
      except ImportError:
          raise ImportError(
              "transformers package not found, please install it with "
              "`pip install transformers`"
          )
      try:
          import torch
      except ImportError:
          raise ImportError(
              "torch package not found, please install it with "
              "`pip install torch`"
          )
  
      # set device, cpu by default check if there is a GPU available
      if device == "cpu":
          self.device = "cpu"
          if lang_model is not None:
              self.lang_model = lang_model
              print(
                  "WARNING! Model override. Using model: ",
                  self.lang_model,
              )
          else:
              # unless overridden, use the small base model on cpu
              self.lang_model = "openai/whisper-base"
      else:
          if torch.cuda.is_available():
              self.device = "cuda"
              # check GPU memory and select automatically the model
              mem = torch.cuda.get_device_properties(
                  self.device
              ).total_memory / (1024**2)
              if mem < 5000:
                  rec_model = "openai/whisper-base"
              elif mem < 7000:
                  rec_model = "openai/whisper-small"
              elif mem < 12000:
                  rec_model = "openai/whisper-medium"
              else:
                  rec_model = "openai/whisper-large-v3"
  
              # check if model is overridden
              if lang_model is not None:
                  self.lang_model = lang_model
                  print(
                      "WARNING! Model override. Might not fit in your GPU"
                  )
              else:
                  self.lang_model = rec_model
          else:
              "cpu"
  
      print("Using the following model: ", self.lang_model)
  
      # load model for inference
      if self.device == "cpu":
          device_map = {"", "cpu"}
      else:
          device_map = (
              {"": "cuda:%d" % device_id}
              if device_id >= 0
              else {"": "cuda"}
          )
  
      # https://huggingface.co/blog/asr-chunking
      self.pipe = pipeline(
          "automatic-speech-recognition",
          model=self.lang_model,
          chunk_length_s=30,
          stride_length_s=5,
          batch_size=8,
          device_map=device_map,
      )
      if use_better:
          # even faster if not doing real time ASR
          # stride_length_s=5,  batch_size=8
          try:
              from optimum.bettertransformer import BetterTransformer
  
              self.pipe.model = BetterTransformer.transform(
                  self.pipe.model, use_flash_attention_2=True
              )
          except Exception as e:
              print(
                  "No optimum, not using BetterTransformer: %s"
                  % str(e),
                  flush=True,
              )
  
      if (
          use_faster
          and have_use_faster
          and self.lang_model
          in ["openai/whisper-large-v2", "openai/whisper-large-v3"]
      ):
          self.pipe.model.to("cpu")
          del self.pipe.model
          clear_torch_cache()
          print("Using faster_whisper", flush=True)
          # has to come here, no framework and no config for model
          # pip install git+https://github.com/SYSTRAN/faster-whisper.git
          from faster_whisper import WhisperModel
  
          model_size = (
              "large-v3"
              if self.lang_model == "openai/whisper-large-v3"
              else "large-v2"
          )
          # Run on GPU with FP16
          model = WhisperModel(
              model_size, device=self.device, compute_type="float16"
          )
          # or run on GPU with INT8
          # model = WhisperModel(model_size, device="cuda", compute_type="int8_float16")
          # or run on CPU with INT8
          # model = WhisperModel(model_size, device="cpu", compute_type="int8")
          self.pipe.model = model
  
      if forced_decoder_ids is not None:
          try:
              self.pipe.model.config.forced_decoder_ids = (
                  forced_decoder_ids
              )
          except Exception as exception_text:
              logger.info(
                  "Unable to set forced_decoder_ids parameter for whisper model"
                  f"Text of exception: {exception_text}"
                  "Therefore whisper model will use default mode for decoder"
              )
  
imports: import logging
  import os
  import tempfile
  import time
  from typing import Dict, Iterator, Optional, Tuple
  from langchain.document_loaders.base import BaseBlobParser
  from langchain.document_loaders.blob_loaders import Blob
  from langchain.document_loaders.generic import GenericLoader
  from langchain.schema import Document
  from typing import List, Union, Any, Tuple
  import requests
  from langchain.docstore.document import Document
  from langchain.document_loaders import ImageCaptionLoader
  from utils import get_device, NullContext, clear_torch_cache, have_use_faster, makedirs
  from importlib.metadata import distribution, PackageNotFoundError
  from typing import Iterable, List
  from langchain.document_loaders.blob_loaders import FileSystemBlobLoader
  from langchain.document_loaders.blob_loaders.schema import Blob, BlobLoader
label_desc: Use image node_id 1 to create a new OpenAIWhisperParserLocal object from inherited base classes: BaseBlobParser with example: obj = OpenAIWhisperParserLocal(device, device_id, lang_model, forced_decoder_ids, use_better, use_faster)