code: def build_demo(embed_mode):
      textbox = gr.Textbox(
          show_label=False,
          placeholder="Enter text and press ENTER",
          container=False,
      )
      with gr.Blocks(
          title="LLaMA-VID", theme=gr.themes.Default(), css=block_css
      ) as demo:
          state = gr.State()
  
          if not embed_mode:
              gr.Markdown(title_markdown)
  
          with gr.Row():
              with gr.Column(scale=3):
                  with gr.Row(elem_id="model_selector_row"):
                      model_selector = gr.Dropdown(
                          choices=models,
                          value=models[0] if len(models) > 0 else "",
                          interactive=True,
                          show_label=False,
                          container=False,
                      )
  
                  imagebox = gr.Image(
                      label="Movie Poster",
                      type="pil",
                      interactive=False,
                  )
                  image_process_mode = gr.Radio(
                      ["Crop", "Resize", "Pad", "Default"],
                      value="Default",
                      label="Preprocess for non-square image",
                      visible=False,
                  )
  
                  with gr.Accordion(
                      "Movie Part", open=True
                  ) as parameter_row:
                      movie_part = gr.Radio(
                          choices=[0, 1, 2, 3, 4, 5],
                          value=0,
                          interactive=True,
                          label="Part selection (plot introduced below)",
                      )
  
                  videobox = gr.Video(label="Input Video")
  
                  with gr.Accordion(
                      "Parameters", open=False
                  ) as parameter_row:
                      # movie_part = gr.Slider(minimum=0, maximum=5, value=1, step=1, interactive=True, label="Movie Part",)
                      temperature = gr.Slider(
                          minimum=0.0,
                          maximum=1.0,
                          value=0.5,
                          step=0.1,
                          interactive=True,
                          label="Temperature",
                      )
                      top_p = gr.Slider(
                          minimum=0.0,
                          maximum=1.0,
                          value=0.7,
                          step=0.1,
                          interactive=True,
                          label="Top P",
                      )
                      max_output_tokens = gr.Slider(
                          minimum=0,
                          maximum=1024,
                          value=512,
                          step=64,
                          interactive=True,
                          label="Max output tokens",
                      )
  
              with gr.Column(scale=6):
                  chatbot = gr.Chatbot(
                      elem_id="chatbot",
                      label="LLaMA-VID Chatbot",
                      height=650,
                  )
                  with gr.Row():
                      with gr.Column(scale=6):
                          textbox.render()
                      with gr.Column(scale=1, min_width=50):
                          submit_btn = gr.Button(
                              value="Send", variant="primary"
                          )
                  with gr.Row(elem_id="buttons") as button_row:
                      upvote_btn = gr.Button(
                          value="👍  Upvote", interactive=False
                      )
                      downvote_btn = gr.Button(
                          value="👎  Downvote", interactive=False
                      )
                      flag_btn = gr.Button(
                          value="⚠️  Flag", interactive=False
                      )
                      # stop_btn = gr.Button(value="⏹️  Stop Generation", interactive=False)
                      regenerate_btn = gr.Button(
                          value="🔄  Regenerate", interactive=False
                      )
                      clear_btn = gr.Button(
                          value="🗑️  Clear", interactive=False
                      )
  
          description_titanic = (
              "Titanic (Choose Part 0-5 in the above movie part)"
          )
          description_avatar = (
              "Avatar (Choose Part 0-5 in the above movie part)"
          )
          description_avengers = (
              "The Avengers (Choose Part 0-4 in the above movie part)"
          )
          description_intersteller = (
              "Intersteller (Choose Part 0-5 in the above movie part)"
          )
          description_gump = (
              "Forrest Gump (Choose Part 0-4 in the above movie part)"
          )
  
          if not embed_mode:
              gr.Markdown(introduce_markdown)
  
          cur_dir = os.path.dirname(os.path.abspath(__file__))
          gr.Examples(
              examples=[
                  [
                      f"{cur_dir}/examples/Titanic.jpg",
                      description_titanic,
                      "Write a brief summary of this movie part.",
                  ],
                  [
                      f"{cur_dir}/examples/Avatar.png",
                      description_avatar,
                      "How does human work on Pandora?",
                  ],
                  [
                      f"{cur_dir}/examples/Avengers.jpg",
                      description_avengers,
                      "Who is the main antagonist in this movie, and what is his goal?",
                  ],
                  [
                      f"{cur_dir}/examples/Interstellar.jpg",
                      description_intersteller,
                      "What happens in this video?",
                  ],
                  [
                      f"{cur_dir}/examples/Forrest_Gump.jpg",
                      description_gump,
                      "What did Forrest Gump do in this movie part?",
                  ],
              ],
              inputs=[imagebox, textbox, textbox],
          )
  
          if not embed_mode:
              gr.Markdown(plot_markdown)
              gr.Markdown(tos_markdown)
              gr.Markdown(learn_more_markdown)
          url_params = gr.JSON(visible=False)
  
          # Register listeners
          btn_list = [
              upvote_btn,
              downvote_btn,
              flag_btn,
              regenerate_btn,
              clear_btn,
          ]
          upvote_btn.click(
              upvote_last_response,
              [state, model_selector],
              [textbox, upvote_btn, downvote_btn, flag_btn],
          )
          downvote_btn.click(
              downvote_last_response,
              [state, model_selector],
              [textbox, upvote_btn, downvote_btn, flag_btn],
          )
          flag_btn.click(
              flag_last_response,
              [state, model_selector],
              [textbox, upvote_btn, downvote_btn, flag_btn],
          )
          regenerate_btn.click(
              regenerate,
              [state, image_process_mode],
              [state, chatbot, textbox, imagebox, videobox] + btn_list,
          ).then(
              http_bot,
              [
                  state,
                  model_selector,
                  movie_part,
                  temperature,
                  top_p,
                  max_output_tokens,
              ],
              [state, chatbot] + btn_list,
          )
          clear_btn.click(
              clear_history,
              None,
              [state, chatbot, textbox, imagebox, videobox] + btn_list,
          )
  
          textbox.submit(
              add_text,
              [state, textbox, imagebox, videobox, image_process_mode],
              [state, chatbot, textbox, imagebox, videobox] + btn_list,
          ).then(
              http_bot,
              [
                  state,
                  model_selector,
                  movie_part,
                  temperature,
                  top_p,
                  max_output_tokens,
              ],
              [state, chatbot] + btn_list,
          )
          submit_btn.click(
              add_text,
              [state, textbox, imagebox, videobox, image_process_mode],
              [state, chatbot, textbox, imagebox, videobox] + btn_list,
          ).then(
              http_bot,
              [
                  state,
                  model_selector,
                  movie_part,
                  temperature,
                  top_p,
                  max_output_tokens,
              ],
              [state, chatbot] + btn_list,
          )
  
          if args.model_list_mode == "once":
              demo.load(
                  load_demo,
                  [url_params],
                  [state, model_selector],
                  _js=get_window_url_params,
              )
          elif args.model_list_mode == "reload":
              demo.load(
                  load_demo_refresh_model_list,
                  None,
                  [state, model_selector],
              )
          else:
              raise ValueError(
                  f"Unknown model list mode: {args.model_list_mode}"
              )
  
      return demo
  
imports: import argparse
  import datetime
  import json
  import os
  import time
  import gradio
  import requests
  import tempfile
  import shutil
  from llamavid.conversation import default_conversation, conv_templates, SeparatorStyle
  from llamavid.constants import LOGDIR
  from llava.utils import build_logger, server_error_msg, violates_moderation, moderation_msg
  import hashlib
label_desc: Use image node_id 13 for calling a global function with example usage: build_demo(embed_mode) and returns: demo