code: def draw_box(coor, region_mask, region_ph, img, input_mode):
      colors = ["red"]
      draw = ImageDraw.Draw(img)
      font = ImageFont.truetype(
          "./ferret/serve/dejavu/DejaVuSans.ttf", size=18
      )
      if input_mode == "Box":
          draw.rectangle(
              [coor[0], coor[1], coor[2], coor[3]],
              outline=colors[0],
              width=4,
          )
          draw.rectangle(
              [
                  coor[0],
                  coor[3] - int(font.size * 1.2),
                  coor[0]
                  + int((len(region_ph) + 0.8) * font.size * 0.6),
                  coor[3],
              ],
              outline=colors[0],
              fill=colors[0],
              width=4,
          )
          draw.text(
              [
                  coor[0] + int(font.size * 0.2),
                  coor[3] - int(font.size * 1.2),
              ],
              region_ph,
              font=font,
              fill=(255, 255, 255),
          )
      elif input_mode == "Point":
          r = 8
          leftUpPoint = (coor[0] - r, coor[1] - r)
          rightDownPoint = (coor[0] + r, coor[1] + r)
          twoPointList = [leftUpPoint, rightDownPoint]
          draw.ellipse(twoPointList, outline=colors[0], width=4)
          draw.rectangle(
              [
                  coor[0],
                  coor[1],
                  coor[0]
                  + int((len(region_ph) + 0.8) * font.size * 0.6),
                  coor[1] + int(font.size * 1.2),
              ],
              outline=colors[0],
              fill=colors[0],
              width=4,
          )
          draw.text(
              [coor[0] + int(font.size * 0.2), coor[1]],
              region_ph,
              font=font,
              fill=(255, 255, 255),
          )
      elif input_mode == "Sketch":
          draw.rectangle(
              [
                  coor[0],
                  coor[3] - int(font.size * 1.2),
                  coor[0]
                  + int((len(region_ph) + 0.8) * font.size * 0.6),
                  coor[3],
              ],
              outline=colors[0],
              fill=colors[0],
              width=4,
          )
          draw.text(
              [
                  coor[0] + int(font.size * 0.2),
                  coor[3] - int(font.size * 1.2),
              ],
              region_ph,
              font=font,
              fill=(255, 255, 255),
          )
          # Use morphological operations to find the boundary
          mask = np.array(region_mask)
          dilated = binary_dilation(mask, structure=np.ones((3, 3)))
          eroded = binary_erosion(mask, structure=np.ones((3, 3)))
          boundary = (
              dilated ^ eroded
          )  # XOR operation to find the difference between dilated and eroded mask
          # Loop over the boundary and paint the corresponding pixels
          for i in range(boundary.shape[0]):
              for j in range(boundary.shape[1]):
                  if boundary[i, j]:
                      # This is a pixel on the boundary, paint it red
                      draw.point((i, j), fill=colors[0])
      else:
          NotImplementedError(
              f"Input mode of {input_mode} is not Implemented."
          )
      return img
  
imports: import argparse
  import datetime
  import json
  import os
  import time
  import gradio
  import requests
  from ferret.conversation import default_conversation, conv_templates, SeparatorStyle
  from ferret.constants import LOGDIR
  from ferret.utils import build_logger, server_error_msg, violates_moderation, moderation_msg
  import hashlib
  import re
  from copy import deepcopy
  from PIL import ImageDraw, ImageFont
  from gradio import processing_utils
  import numpy
  import torch
  import torch.nn.functional
  from scipy.ndimage import binary_dilation, binary_erosion
  import pdb
  from ferret.serve.gradio_css import code_highlight_css
label_desc: Use image node_id 2 for calling a global function with example usage: draw_box(coor, region_mask, region_ph, img, input_mode) and returns: img