code: def compile_gr_request(
      app: App,
      body: PredictBody,
      fn_index_inferred: int,
      username: Optional[str],
      request: Optional[fastapi.Request],
  ):
      # If this fn_index cancels jobs, then the only input we need is the
      # current session hash
      if app.get_blocks().dependencies[fn_index_inferred]["cancels"]:
          body.data = [body.session_hash]
      if body.request:
          if body.batched:
              gr_request = [Request(username=username, request=request)]
          else:
              gr_request = Request(
                  username=username, request=body.request
              )
      else:
          if request is None:
              raise ValueError(
                  "request must be provided if body.request is None"
              )
          gr_request = Request(username=username, request=request)
  
      return gr_request
  
imports: from __future__ import annotations
  import hashlib
  import json
  from collections import deque
  from dataclasses import dataclass
  from tempfile import NamedTemporaryFile, _TemporaryFileWrapper
  from typing import TYPE_CHECKING, AsyncGenerator, BinaryIO, List, Optional, Tuple, Union
  import fastapi
  import httpx
  import multipart
  from gradio_client.documentation import document, set_documentation_group
  from multipart.multipart import parse_options_header
  from starlette.datastructures import FormData, Headers, UploadFile
  from starlette.formparsers import MultiPartException, MultipartPart
  from gradio import utils
  from gradio.data_classes import PredictBody
  from gradio.exceptions import Error
  from gradio.helpers import EventData
  from gradio.state_holder import SessionState
label_desc: Use image node_id 2 for calling a global function with example usage: compile_gr_request(app, body, fn_index_inferred, username, request) and returns: gr_request