-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsample6_upscale_image.go
More file actions
49 lines (41 loc) · 1.07 KB
/
Copy pathsample6_upscale_image.go
File metadata and controls
49 lines (41 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"context"
"fmt"
"os"
"google.golang.org/genai"
)
// To run this sample with a VertexAI Google Cloud project:
//
// $ export GOOGLE_GENAI_USE_VERTEXAI=true
// $ export GOOGLE_CLOUD_PROJECT=xxxxxxxxx
// $ export GOOGLE_CLOUD_LOCATION=us-central1
// $ gcloud auth application-default login
// $ gcloud services enable aiplatform.googleapis.com
// $ go run . -n=6
func sample6_upscaleImage(ctx context.Context) error {
modelName := "imagen-4.0-upscale-preview"
imgdata, err := os.ReadFile("./testdata/lion.jpg")
if err != nil {
return err
}
var config *genai.UpscaleImageConfig = &genai.UpscaleImageConfig{
OutputMIMEType: "image/jpeg",
IncludeRAIReason: true,
}
image := &genai.Image{
ImageBytes: imgdata,
MIMEType: "image/jpeg",
}
result, err := client.Models.UpscaleImage(ctx, modelName, image, "x4", config)
if err != nil {
return err
}
path := fmt.Sprintf("upscaled_image.jpg")
fmt.Println("Writing file", path)
err = os.WriteFile(path, result.GeneratedImages[0].Image.ImageBytes, 0777)
if err != nil {
return err
}
return nil
}