def script_from_saved_model(saved_model_dir, output_file, input_arrays,
                            output_arrays):
  """Generates a script for saved model to convert from TF to TF Lite."""
  return u"""# --- Python code ---
import tensorflow as tf
lite = tf.compat.v1.lite

saved_model_dir = '{saved_model_dir}'
output_file = '{output_file}'
converter = lite.TFLiteConverter.from_saved_model(
    saved_model_dir,
    input_arrays={input_arrays},
    output_arrays={output_arrays})
tflite_model = converter.convert()
with tf.io.gfile.GFile(output_file, 'wb') as f:
  f.write(tflite_model)
  print('Write file: %s' % output_file)
""".format(
    saved_model_dir=saved_model_dir,
    output_file=output_file,
    input_arrays=input_arrays,
    output_arrays=output_arrays)