class_docstr: Streamer that stores print-ready text in a queue, to be used by a downstream application as an iterator. This is
  useful for applications that benefit from acessing the generated text in a non-blocking way (e.g. in an interactive
  Gradio demo).
  
  <Tip warning={true}>
  
  The API for the streamer classes is still under development and may change in the future.
  
  </Tip>
  
  Parameters:
      tokenizer (`AutoTokenizer`):
          The tokenized used to decode the tokens.
      skip_prompt (`bool`, *optional*, defaults to `False`):
          Whether to skip the prompt to `.generate()` or not. Useful e.g. for chatbots.
      timeout (`float`, *optional*):
          The timeout for the text queue. If `None`, the queue will block indefinitely. Useful to handle exceptions
          in `.generate()`, when it is called in a separate thread.
      decode_kwargs (`dict`, *optional*):
          Additional keyword arguments to pass to the tokenizer's `decode` method.
  
  Examples:
  
      ```python
      >>> from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
      >>> from threading import Thread
  
      >>> tok = AutoTokenizer.from_pretrained("gpt2")
      >>> model = AutoModelForCausalLM.from_pretrained("gpt2")
      >>> inputs = tok(["An increasing sequence: one,"], return_tensors="pt")
      >>> streamer = TextIteratorStreamer(tok)
  
      >>> # Run the generation in a separate thread, so that we can fetch the generated text in a non-blocking way.
      >>> generation_kwargs = dict(inputs, streamer=streamer, max_new_tokens=20)
      >>> thread = Thread(target=model.generate, kwargs=generation_kwargs)
      >>> thread.start()
      >>> generated_text = ""
      >>> for new_text in streamer:
      ...     generated_text += new_text
      >>> generated_text
      'An increasing sequence: one, two, three, four, five, six, seven, eight, nine, ten, eleven,'
      ```
class_docstr_tok: ["Streamer","that","stores","print-ready","text","in","a","queue",",","to","be","used","by","a","downstream","application","as","an","iterator",".","This","is","useful","for","applications","that","benefit","from","acessing","the","generated","text","in","a","non-blocking","way","(","e.g",".","in","an","interactive","Gradio","demo",")",".","<","Tip","warning=","{","true","}",">","The","API","for","the","streamer","classes","is","still","under","development","and","may","change","in","the","future",".","<","\/Tip",">","Parameters",":","tokenizer","(","`","AutoTokenizer","`",")",":","The","tokenized","used","to","decode","the","tokens",".","skip_prompt","(","`","bool","`",",","*","optional","*",",","defaults","to","`","False","`",")",":","Whether","to","skip","the","prompt","to","`",".generate","(",")","`","or","not",".","Useful","e.g",".","for","chatbots",".","timeout","(","`","float","`",",","*","optional","*",")",":","The","timeout","for","the","text","queue",".","If","`","None","`",",","the","queue","will","block","indefinitely",".","Useful","to","handle","exceptions","in","`",".generate","(",")","`",",","when","it","is","called","in","a","separate","thread",".","decode_kwargs","(","`","dict","`",",","*","optional","*",")",":","Additional","keyword","arguments","to","pass","to","the","tokenizer","'s","`","decode","`","method",".","Examples",":","``","`","python",">",">",">","from","transformers","import","AutoModelForCausalLM",",","AutoTokenizer",",","TextIteratorStreamer",">",">",">","from","threading","import","Thread",">",">",">","tok","=","AutoTokenizer.from_pretrained","(","``","gpt2","''",")",">",">",">","model","=","AutoModelForCausalLM.from_pretrained","(","``","gpt2","''",")",">",">",">","inputs","=","tok","(","[","``","An","increasing","sequence",":","one",",","''","]",",","return_tensors=","''","pt","''",")",">",">",">","streamer","=","TextIteratorStreamer","(","tok",")",">",">",">","#","Run","the","generation","in","a","separate","thread",",","so","that","we","can","fetch","the","generated","text","in","a","non-blocking","way",".",">",">",">","generation_kwargs","=","dict","(","inputs",",","streamer=streamer",",","max_new_tokens=20",")",">",">",">","thread","=","Thread","(","target=model.generate",",","kwargs=generation_kwargs",")",">",">",">","thread.start","(",")",">",">",">","generated_text","=","``","''",">",">",">","for","new_text","in","streamer",":","...","generated_text","+=","new_text",">",">",">","generated_text","'An","increasing","sequence",":","one",",","two",",","three",",","four",",","five",",","six",",","seven",",","eight",",","nine",",","ten",",","eleven",",","'","``","`"]
docstr: Put the new text in the queue. If the stream is ending, also put a stop signal in the queue.
docstr_tok: ["Put","the","new","text","in","the","queue",".","If","the","stream","is","ending",",","also","put","a","stop","signal","in","the","queue","."]
code: def on_finalized_text(self, text: str, stream_end: bool = False):
      """Put the new text in the queue. If the stream is ending, also put a stop signal in the queue."""
      self.text_queue.put(text, timeout=self.timeout)
      if stream_end:
          self.text_queue.put(self.stop_signal, timeout=self.timeout)
  
file_path: transformers/src/transformers/generation/streamers.py
imports: from queue import Queue
  from typing import TYPE_CHECKING, Optional
label_desc: Use image node_id 2 for calling the TextIteratorStreamer obj's underlying member method code with example usage: obj.on_finalized_text(text, stream_end) without return types