Unable to locate tflite file from bucket in cloud functions

Hello, I have created a cloud function with python 3.10 that should update a custom model in my firebase project, everything seems to be working as expected, except for when I need to update the tflite file to the newly generated trained model.

I create the tflite file and upload it to my bucket prior to trying to update the model on firebase, the error I get is “[Errno 2] No such file or directory: ‘price_prediction_model.tflite’”, which is weird because when I try to print all the files in my bucket, the tflite file I’m looking for indeed appears in the logs.

If someone could enlighten me, I would appreciate.

Here is the code :

#update the model to firebase machine learning
def update_tflite_model(model_name, model_display_name, tflite_model):
     try:
          model = get_model_by_display_name(model_display_name)
          print(model.model_format)
          print('OK 1')
          source = ml.TFLiteGCSModelSource.from_tflite_model_file(f'{model_name}.tflite') # <= NO SUCH FILE OR DIRECTORY ??
          print('OK 2')
          model.model_format = ml.TFLiteFormat(model_source=tflite_model_source)
          updated_model = ml.update_model(model)
          ml.publish_model(updated_model.model_id)
          print("TensorFlow Lite model updated in Firebase Machine Learning successfully!")
     except Exception as e:
          print("Error updating TensorFlow Lite model in Firebase Machine Learning:", e)

Hello @Fawful ,

Welcome to the Google Cloud Community!

In your code, you’re constructing the file path using f-strings:

source = ml.TFLiteGCSModelSource.from_tflite_model_file(f'{model_name}.tflite')

Your code snippet is attempting to access a local file (f'{model_name}.tflite'), but you’ve indicated that the file has already been uploaded to a GCS bucket. Instead of accessing the file from the local file system, you should reference the Google Cloud Storage path of your uploaded .tflite file when creating the TFLiteGCSModelSource.

Additionally, ensure you have set up the necessary permissions for your Cloud Function to access the Cloud Storage bucket containing the .tflite file.