How to load a Google Sheet into Gemini API

Hi all,

I created a prompt in Google AI studio loading a simple Google sheet to calculate the average of salaries directly with the LLM and a second option with code execution.

As expected, the average is correct with code execution and incorrect if it is not used.

Following this, I wanted to import the Python code generated by Google AI Studio (Get code button) into Colab but the code doesn’t work:

# TODO Make these files available on the local file system
# You may need to update the file paths
files = [
  upload_file(path_of_salaries, mime_type="application/vnd.google-apps.spreadsheet"),
]

Even if the path is correct, the upload_file function seems not working with Google Sheet.

Strangely, Google AI Studio could load the Google Sheet but its generated Python code seems wrong.

Is it possible to load Google sheets into Gemini API when we are in Colab?

  • If yes, is there any documentation to understand better?
  • If no, is it better to convert the Google sheet into CSV before loading onto Google API?

Many thanks for your help.

Hi @Bensan, welcome to the forum!

According to the documentation, the Google Sheets MIME type is not on the supported list.

I would recommend converting it into a CSV file if you are using the Gemini API.

Thanks

Thanks Gunand for your quick reply.