code: def run_inference(
      background_tasks: BackgroundTasks,
      model: str,
      image: str = "",
      session_id: str = "",
      params: str = Form("{}"),
      file: UploadFile = File(None),
      label: UploadFile = File(None),
      output: Optional[ResultType] = None,
  ):
      request = {"model": model, "image": image}
  
      if not file and not image and not session_id:
          raise HTTPException(
              status_code=500,
              detail="Neither Image nor File not Session ID input is provided",
          )
  
      instance: MONAILabelApp = app_instance()
  
      if file:
          file_ext = (
              "".join(pathlib.Path(file.filename).suffixes)
              if file.filename
              else ".nii.gz"
          )
          image_file = tempfile.NamedTemporaryFile(suffix=file_ext).name
  
          with open(image_file, "wb") as buffer:
              shutil.copyfileobj(file.file, buffer)
              request["image"] = image_file
              background_tasks.add_task(remove_file, image_file)
  
      if label:
          file_ext = (
              "".join(pathlib.Path(label.filename).suffixes)
              if label.filename
              else ".nii.gz"
          )
          label_file = tempfile.NamedTemporaryFile(suffix=file_ext).name
  
          with open(label_file, "wb") as buffer:
              shutil.copyfileobj(label.file, buffer)
              background_tasks.add_task(remove_file, label_file)
  
          # if binary file received, e.g. scribbles from OHIF - then convert using reference image
          if file_ext == ".bin":
              image_uri = instance.datastore().get_image_uri(image)
              label_file = binary_to_image(image_uri, label_file)
  
          request["label"] = label_file
  
      config = instance.info().get("config", {}).get("infer", {})
      request.update(config)
  
      p = json.loads(params) if params else {}
      request.update(p)
  
      if session_id:
          session = instance.sessions().get_session(session_id)
          if session:
              request["image"] = session.image
              request["session"] = session.to_json()
  
      logger.info(f"Infer Request: {request}")
      result = instance.infer(request)
      if result is None:
          raise HTTPException(
              status_code=500, detail="Failed to execute infer"
          )
  
      # Dicom Seg Integration
      if output == "dicom_seg":
          dicom_seg_file = None
          if not isinstance(instance.datastore(), DICOMWebDatastore):
              raise HTTPException(
                  status_code=500,
                  detail="DICOM SEG format is not supported in a non-DICOM datastore",
              )
          elif p.get("label_info") is None:
              raise HTTPException(
                  status_code=404,
                  detail="Parameters for DICOM SEG inference cannot be empty!",
              )
          # Transform image uri to id (similar to _to_id in local datastore)
          image_uri = instance.datastore().get_image_uri(image)
          suffixes = [".nii", ".nii.gz", ".nrrd"]
          image_path = [
              image_uri.replace(suffix, "")
              for suffix in suffixes
              if image_uri.endswith(suffix)
          ][0]
          res_img = (
              result.get("file")
              if result.get("file")
              else result.get("label")
          )
          dicom_seg_file = nifti_to_dicom_seg(
              image_path, res_img, p.get("label_info"), use_itk=True
          )
          result["dicom_seg"] = dicom_seg_file
  
      return send_response(
          instance.datastore(), result, output, background_tasks
      )
  
imports: import json
  import logging
  import os
  import pathlib
  import shutil
  import tempfile
  from enum import Enum
  from typing import Optional
  from fastapi import APIRouter, Depends, File, Form, HTTPException, UploadFile
  from fastapi.background import BackgroundTasks
  from fastapi.responses import FileResponse, Response
  from requests_toolbelt import MultipartEncoder
  from monailabel.config import RBAC_USER, settings
  from monailabel.datastore.dicom import DICOMWebDatastore
  from monailabel.datastore.utils.convert import binary_to_image, nifti_to_dicom_seg
  from monailabel.endpoints.user.auth import RBAC, User
  from monailabel.interfaces.app import MONAILabelApp
  from monailabel.interfaces.utils.app import app_instance
  from monailabel.utils.others.generic import get_mime_type, remove_file
label_desc: Use image node_id 2 for calling a global function with example usage: run_inference(background_tasks, model, image, session_id, params, file, label, output) and returns: send_response