code: def restore_session_state(app: App, body: PredictBody):
      event_id = body.event_id
      session_hash = getattr(body, "session_hash", None)
      if session_hash is not None:
          session_state = app.state_holder[session_hash]
          # The should_reset set keeps track of the fn_indices
          # that have been cancelled. When a job is cancelled,
          # the /reset route will mark the jobs as having been reset.
          # That way if the cancel job finishes BEFORE the job being cancelled
          # the job being cancelled will not overwrite the state of the iterator.
          if event_id is None:
              iterator = None
          elif event_id in app.iterators_to_reset:
              iterator = None
              app.iterators_to_reset.remove(event_id)
          else:
              iterator = app.iterators.get(event_id)
      else:
          session_state = SessionState(app.get_blocks())
          iterator = None
  
      return session_state, iterator
  
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 3 for calling a global function with example usage: restore_session_state(app, body) and returns: session_state,  iterator