class_docstr: :obj:`Text` defines API specification for the inputs/outputs of a Service. :obj:`Text`
  represents strings for all incoming requests/outcoming responses as specified in
  your API function signature.
  
  A sample GPT2 service implementation:
  
  .. code-block:: python
     :caption: `service.py`
  
     from __future__ import annotations
  
     import bentoml
     from bentoml.io import Text
  
     runner = bentoml.tensorflow.get('gpt2:latest').to_runner()
  
     svc = bentoml.Service("gpt2-generation", runners=[runner])
  
     @svc.api(input=Text(), output=Text())
     def predict(text: str) -> str:
         res = runner.run(text)
         return res['generated_text']
  
  Users then can then serve this service with :code:`bentoml serve`:
  
  .. code-block:: bash
  
     % bentoml serve ./service.py:svc --reload
  
  Users can then send requests to the newly started services with any client:
  
  .. tab-set::
  
      .. tab-item:: Bash
  
         .. code-block:: bash
  
            % curl -X POST -H "Content-Type: text/plain" \
                    --data 'Not for nothing did Orin say that people outdoors.' \
                    http://0.0.0.0:3000/predict
  
      .. tab-item:: Python
  
         .. code-block:: python
            :caption: `request.py`
  
            import requests
            requests.post(
                "http://0.0.0.0:3000/predict",
                headers = {"content-type":"text/plain"},
                data = 'Not for nothing did Orin say that people outdoors.'
            ).text
  
  .. note::
  
      :obj:`Text` is not designed to take any ``args`` or ``kwargs`` during initialization.
  
  Returns:
      :obj:`Text`: IO Descriptor that represents strings type.
class_docstr_tok: [":","obj",":","`","Text","`","defines","API","specification","for","the","inputs\/outputs","of","a","Service",".",":","obj",":","`","Text","`","represents","strings","for","all","incoming","requests\/outcoming","responses","as","specified","in","your","API","function","signature",".","A","sample","GPT2","service","implementation",":","..","code-block",":",":","python",":","caption",":","`","service.py","`","from","__future__","import","annotations","import","bentoml","from","bentoml.io","import","Text","runner","=","bentoml.tensorflow.get","(","'gpt2",":","latest","'",")",".to_runner","(",")","svc","=","bentoml.Service","(","``","gpt2-generation","''",",","runners=","[","runner","]",")","@","svc.api","(","input=Text","(",")",",","output=Text","(",")",")","def","predict","(","text",":","str",")","-",">","str",":","res","=","runner.run","(","text",")","return","res","[","'generated_text","'","]","Users","then","can","then","serve","this","service","with",":","code",":","`","bentoml","serve","`",":","..","code-block",":",":","bash","%","bentoml","serve",".\/service.py",":","svc","--","reload","Users","can","then","send","requests","to","the","newly","started","services","with","any","client",":","..","tab-set",":",":","..","tab-item",":",":","Bash","..","code-block",":",":","bash","%","curl","-X","POST","-H","``","Content-Type",":","text\/plain","''","\\","--","data","'Not","for","nothing","did","Orin","say","that","people","outdoors",".","'","\\","http",":","\/\/0.0.0.0:3000\/predict","..","tab-item",":",":","Python","..","code-block",":",":","python",":","caption",":","`","request.py","`","import","requests","requests.post","(","``","http",":","\/\/0.0.0.0:3000\/predict","''",",","headers","=","{","``","content-type","''",":","''","text\/plain","''","}",",","data","=","'Not","for","nothing","did","Orin","say","that","people","outdoors",".","'",")",".text","..","note",":",":",":","obj",":","`","Text","`","is","not","designed","to","take","any","``","args","``","or","``","kwargs","``","during","initialization",".","Returns",":",":","obj",":","`","Text","`",":","IO","Descriptor","that","represents","strings","type","."]
docstr: Create a :class:`~bentoml._internal.io_descriptors.text.Text` IO Descriptor from given inputs.
  
  Args:
      sample: Given sample text.
  
  Returns:
      :class:`Text`: IODescriptor from given users inputs.
  
  Example:
  
  .. code-block:: python
     :caption: `service.py`
  
     @svc.api(input=bentoml.io.Text.from_sample('Bento box is'), output=bentoml.io.Text())
     def predict(inputs: str) -> str: ...
docstr_tok: ["Create","a",":","class",":","`","~bentoml._internal.io_descriptors.text.Text","`","IO","Descriptor","from","given","inputs",".","Args",":","sample",":","Given","sample","text",".","Returns",":",":","class",":","`","Text","`",":","IODescriptor","from","given","users","inputs",".","Example",":","..","code-block",":",":","python",":","caption",":","`","service.py","`","@","svc.api","(","input=bentoml.io.Text.from_sample","(","'Bento","box","is","'",")",",","output=bentoml.io.Text","(",")",")","def","predict","(","inputs",":","str",")","-",">","str",":","..."]
code: def _from_sample(self, sample: str | bytes) -> str:
      """
      Create a :class:`~bentoml._internal.io_descriptors.text.Text` IO Descriptor from given inputs.
  
      Args:
          sample: Given sample text.
  
      Returns:
          :class:`Text`: IODescriptor from given users inputs.
  
      Example:
  
      .. code-block:: python
         :caption: `service.py`
  
         @svc.api(input=bentoml.io.Text.from_sample('Bento box is'), output=bentoml.io.Text())
         def predict(inputs: str) -> str: ...
      """
      if isinstance(sample, bytes):
          sample = sample.decode("utf-8")
      return sample
  
imports: from __future__ import annotations
  import typing
  from starlette.requests import Request
  from starlette.responses import StreamingResponse
  from ..service.openapi import SUCCESS_DESCRIPTION
  from ..service.openapi.specification import MediaType
  from ..service.openapi.specification import Schema
  from ..utils.http import set_cookies
  from ..utils.lazy_loader import LazyLoader
  from .base import IODescriptor
label_desc: Use image node_id 2 for calling the Text obj's underlying member method code with example usage: obj._from_sample(sample) and returns: sample