code: def get_chatbot_demo(
      share,
      username,
      password,
      server_port=5555,
      web_port=9889,
      loop=None,
      value=False,
      defaults=None,
      attributes=None,
  ):
      check_gradio_import()
      from nemo.collections.nlp.modules.common.chatbot_component import (
          Chatbot,
      )
  
      asyncio.set_event_loop(loop)
      with gr.Blocks(css=CSS) as demo:
          with gr.Row():
              with gr.Column(scale=2, width=200):
                  # store the mutliple turn conversation
                  session_state = gr.State(value=[])
                  token_to_gen = gr.Number(
                      label="Number of Tokens to generate",
                      value=300,
                      type=int,
                  )
                  seed = gr.Number(
                      label="Random seed", value=0, type=int
                  )
                  prompt_presets = gr.Dropdown(
                      list(PROMPT_PRESETS.keys()),
                      label="Template Presets",
                      default="DIALOGUE2",
                      value="DIALOGUE2",
                  )
                  sampling_method = gr.Dropdown(
                      list(PRESETS.keys()),
                      label="Sampling Presets",
                      default="K50",
                      value="K50",
                  )
                  with gr.Accordion("Sampling Parameters", open=False):
                      temperature = gr.Slider(
                          minimum=0.0,
                          maximum=5.0,
                          value=0.75,
                          label="Temperature",
                          step=0.1,
                          interactive=False,
                      )
                      top_p = gr.Slider(
                          minimum=0.0,
                          maximum=1.0,
                          step=0.02,
                          value=0.95,
                          label="Top P",
                          interactive=False,
                      )
                      top_k = gr.Slider(
                          minimum=0,
                          maximum=1024,
                          step=2,
                          value=50,
                          label="Top K",
                          interactive=False,
                      )
                      repetition_penality = gr.Slider(
                          minimum=1.0,
                          maximum=5.0,
                          step=0.02,
                          value=1.0,
                          label="Repetition penalty",
                          interactive=False,
                      )
  
                  with gr.Accordion(
                      "Value Parameters", open=True, visible=value
                  ):
                      keys = [k.key for k in attributes]
                      # keys = ['quality', 'toxicity', 'humor', 'creativity', 'violence', 'helpfulness', 'not_appropriate']
                      widgets = []
                      for item in attributes:
                          if item.type == "int":
                              slider = gr.Slider(
                                  minimum=item.min,
                                  maximum=item.max,
                                  step=1,
                                  value=item.default,
                                  label=item.name,
                              )
                              widgets.append(slider)
                          elif item.type == "list":
                              dropdown = gr.Dropdown(
                                  item.choices,
                                  label=item.name,
                                  default=item.default,
                                  value=item.default,
                              )
                              widgets.append(dropdown)
                      used_value = gr.CheckboxGroup(keys, value=keys)
  
                      def change_visibility(x):
                          values = []
                          for key in keys:
                              if key in x:
                                  values.append(gr.update(visible=True))
                              else:
                                  values.append(
                                      gr.update(visible=False)
                                  )
                          return values
  
                      used_value.change(
                          change_visibility,
                          inputs=[used_value],
                          outputs=widgets,
                      )
  
                  def set_sampling(x):
                      if x == "Custom":
                          values = [
                              gr.update(value=v, interactive=True)
                              for v in PRESETS[x].values()
                          ]
                          return values
                      else:
                          values = [
                              gr.update(value=v, interactive=False)
                              for v in PRESETS[x].values()
                          ]
                          return values
  
                  sampling_method.change(
                      set_sampling,
                      inputs=[sampling_method],
                      outputs=[
                          temperature,
                          top_p,
                          top_k,
                          repetition_penality,
                      ],
                  )
  
                  gr.HTML("<hr>")
                  human_name = gr.Textbox(
                      label="Human Name",
                      value=defaults["user"],
                      line=1,
                  )
                  assistant_name = gr.Textbox(
                      label="Assistant Name",
                      value=defaults["assistant"],
                      line=1,
                  )
                  preamble = gr.Textbox(
                      label="System",
                      value=defaults["system"],
                      lines=2,
                  )
  
                  def set_prompt(x):
                      if x == "DIALOGUE":
                          return "", ""
                      return defaults["user"], defaults["assistant"]
  
                  prompt_presets.change(
                      set_prompt,
                      inputs=[prompt_presets],
                      outputs=[human_name, assistant_name],
                  )
  
              with gr.Column(scale=1, min_width=900):
                  chatbot = Chatbot(elem_id="chatbot").style(height=800)
                  msg = gr.Textbox(
                      label="User",
                      value="",
                      lines=1,
                  )
                  clear = gr.Button("Clear")
  
                  def user(user_message, history, session_state):
                      session_state.append(user_message)
                      user_message = user_message.replace("\n", "<br>")
                      return "", history + [[user_message, None]]
  
                  def get_value_str(values_array, used_value):
                      if len(used_value) == 0:
                          return ""
                      assert len(values_array) == len(keys)
                      value_str = "<extra_id_2>"
                      elements = []
                      for i, key in enumerate(keys):
                          if key in used_value:
                              elements.append(
                                  f"{key}:{values_array[i]}"
                              )
                      value_str += ",".join(elements) + "\n"
                      return value_str
  
                  def bot(
                      history,
                      preamble,
                      token_to_gen,
                      temperature,
                      top_p,
                      top_k,
                      repetition_penality,
                      seed,
                      human_name,
                      assistant_name,
                      session_state,
                      prompts_presets,
                      used_value,
                      *values,
                  ):
                      values_array = values
                      if value:
                          value_str = get_value_str(
                              values_array, used_value
                          )
                      else:
                          value_str = ""
  
                      prompt_preset = PROMPT_PRESETS[prompts_presets]
                      prompt_text = ""
                      names = [human_name, assistant_name]
                      turn_tokens = [
                          prompt_preset["USER_TURN_TOKEN"],
                          prompt_preset["BOT_TURN_TOKEN"],
                      ]
                      for i, meg in enumerate(session_state):
                          name = names[i % 2]
                          turn = turn_tokens[i % 2]
                          prompt_text += (
                              turn
                              + name
                              + prompt_preset["END_OF_NAME"]
                              + meg
                              + prompt_preset["END_OF_TURN"]
                          )
                      prompt_text += (
                          prompt_preset["BOT_TURN_TOKEN"]
                          + assistant_name
                          + prompt_preset["END_OF_NAME"]
                          + value_str
                      )
                      prompt_text = (
                          prompt_preset["SYSTEM_TURN_TOKEN"]
                          + preamble
                          + prompt_text
                      )
                      bot_message = create_gen_function(server_port)(
                          prompt_text,
                          False,
                          False,
                          token_to_gen,
                          1,
                          temperature,
                          top_p,
                          top_k,
                          repetition_penality,
                          "<extra_id_1>",
                      )
                      if bot_message.endswith(TURN_TOKEN):
                          bot_message = bot_message[: -len(TURN_TOKEN)]
                      history[-1][1] = bot_message
                      print(prompt_text)
                      print(bot_message)
                      print("-------------------")
                      session_state.append(
                          value_str + bot_message.strip()
                      )
                      return history
  
                  msg.submit(
                      user,
                      [msg, chatbot, session_state],
                      [msg, chatbot],
                      queue=False,
                  ).then(
                      bot,
                      [
                          chatbot,
                          preamble,
                          token_to_gen,
                          temperature,
                          top_p,
                          top_k,
                          repetition_penality,
                          seed,
                          human_name,
                          assistant_name,
                          session_state,
                          prompt_presets,
                          used_value,
                          *widgets,
                      ],
                      [chatbot],
                  )
  
                  def clear_fun(session_state):
                      session_state.clear()
                      return None
  
                  clear.click(
                      clear_fun, [session_state], chatbot, queue=False
                  )
          demo.launch(
              share=share,
              server_port=web_port,
              server_name="0.0.0.0",
              auth=(username, password),
          )
  
file_path: NeMo/nemo/collections/nlp/modules/common/megatron_web_server.py
imports: import asyncio
  from nemo.collections.nlp.modules.common.chat_css import CSS
  from nemo.collections.nlp.modules.common.megatron.retrieval_services.util import convert_retrieved_to_md, request_data, text_generation
label_desc: Use image node_id 4 for calling a global function with example usage: get_chatbot_demo(share, username, password, server_port, web_port, loop, value, defaults, attributes) and returns: defaults,  defaults, str,  unknown, value_str, history, None, values, values, values, str,  str, str