Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Fetch image/video from cloud bucket and send it+prompt to Gemini vision in Go

Hello hello

I am trying to get an image from my cloud bucket and send it + a user prompt to gemini vision. I managed to do it for locally stored images but cannot see how to do it when bickets are involved.

Below is the local version:

 

 

client, err := genai.NewClient(ctx, option.WithAPIKey(string(API_KEY)))
if err != nil {
log.Fatal(err)
}
defer client.Close()
modelfile, err := client.UploadFileFromPath(ctx, filepath.Join(uploadPath, dtf+".jpg"), nil)
if err != nil {
log.Fatal(err)
}
defer client.DeleteFile(ctx, modelfile.Name)
// ----------------------------- THIS ONE
model := client.GenerativeModel("gemini-1.5-flash")
resp, err := model.GenerateContent(ctx,
genai.FileData{URI: modelfile.URI},
genai.Text(prompt))

 

 

Thanks in advance for your help!

0 1 571
1 REPLY 1

Hi @Y-Noor,

Welcome to Google Cloud Community!

Here's an insight of how to fetch an image from a cloud bucket and send it to Gemini Vision in Go.

  1. Authentication and Setup:
  2. Download Image from Bucket:
  3. Upload Image to Gemini Vision:
  4. Send Prompt to Gemini Vision:
    • Construct a request to the Gemini Vision API.
    • Include the image URI from the previous step.
    • Add your user prompt (text description) about what you want Gemini Vision to analyze.
  5. Process Gemini Vision Response:
    • The Gemini Vision API will respond with an analysis of the image based on your prompt.
    • Parse the response (usually in JSON format) to extract relevant data.

Additionally, here are some useful documentation that you may check as well:

I hope the above information is helpful.