def Callback()

in utils/import_conversations_v2.py [0:0]


  def Callback(future):
    try:
      response = future.result()
      # print('response generated')
    except google.api_core.exceptions.GoogleAPICallError as e:
      print(
          'Error `{}`: failed to transcribe audio uri `{}` with operation `{}`'
          ' and error `{}`.'.format(
              e, audio_uri, future.operation.name, future.exception()
          )
      )
      return

    # time.sleep(1)
    try:
      if should_redact == 'True':
        # print('redacting')
        response = _Redact(response, project_id, impersonated_service_account)
    except google.api_core.exceptions.GoogleAPICallError as e:
      print(
          'Error `{}`: failed to redact transcription from audio uri `{}`.'
          .format(e, audio_uri)
      )
      return
    # print('After redacting')
    # time.sleep(1)
    transcript_name = '{}.txt'.format(
        os.path.basename(os.path.splitext(audio_uri)[0])
    )
    try:
      _UploadTranscript(
          response,
          dest_bucket,
          transcript_name,
          project_id,
          impersonated_service_account,
      )
      # print('uploaded transcript')
    except google.api_core.exceptions.GoogleAPICallError as e:
      print(
          'Error `{}`: failed to upload transcription from audio uri `{}`.'
          .format(e, audio_uri)
      )
      return
    # time.sleep(1)

    transcript_uri = _GetGcsUri(dest_bucket, transcript_name)
    try:
      # print('transcript_uri',transcript_uri)

      meta_data = {}
      if xml_bucket != 'None':
        tname = transcript_name.replace('.txt', '.xml')
        xml_file_path = f'/tmp/{tname}'  # f'{xml_path}/{tname}'
        _DownloadFileFromGcs(
            xml_bucket,
            tname,
            xml_file_path,
            project_id,
            impersonated_service_account,
        )
        meta_data = _GetMetaData(xml_file_path)
        # print("meta_data",meta_data)
        os.remove(xml_file_path)
      elif agent_id != 'None':
        meta_data['agent_id'] = agent_id

      conversation_name = _CreateInsightsConversation(
          insights_endpoint,
          api_version,
          project_id,
          audio_uri,
          transcript_uri,
          meta_data,
          impersonated_service_account,
          medium=None,
          agent_channel=agent_channel,
      )
      # print('conversation_name',conversation_name)
      # Note: Appending to a python list is thread-safe, hence no lock.
      conversation_names.append(conversation_name)
    except requests.exceptions.HTTPError as e:
      print(
          'Error `{}`: failed to create insights conversation from audio uri '
          '{} and transcript uri `{}`.'.format(e, audio_uri, transcript_uri)
      )