Error 403 means - Permission Denied
This error means your application is trying to access the Gemini Pro Vision API, but it doesn't have the necessary permissions. The "ACCESS_TOKEN_SCOPE_INSUFFICIENT" message specifically indicates that the service account being used lacks the required scopes (permissions)
Try below to resolve:
Authenticate your Streamlit Cloud application with GCP is to use a service account:
Create a Service Account:
Go to the Google Cloud Console. Navigate to "IAM & Admin" -> "Service Accounts." Click "Create Service Account." Give your service account a descriptive name (e.g., "streamlit-gemini-vision"). Grant the service account the "Vertex AI User" role (or a more specific role if you prefer). This role provides the necessary permissions to use the Gemini Pro Vision API. Click "Continue" and then "Done." Create a Service Account Key:
Find the service account you just created in the list. Click the three dots (Actions) and select "Manage Keys." Click "Add Key" -> "Create New Key." Choose "JSON" as the key type. Click "Create." This will download a JSON file containing the service account's credentials. Keep this file secure! Store the Key as a Streamlit Secret:
Go to your Streamlit Cloud application's dashboard. Click the three dots (Settings) and select "Secrets." Copy the entire contents of the downloaded JSON key file. In the Streamlit Secrets section, create a new secret with the name GOOGLE_CREDENTIALS (or any name you prefer). Paste the JSON content into the value field. Click "Add."
Modify Your Streamlit Application:
In your Python code, you need to load the credentials from the Streamlit secret and use them to authenticate with the Gemini Pro Vision API. Use the google-auth library to load the credentials.