Skip to content

Commit 6383448

Browse files
gericdongpattishin
andauthored
feat(generative-ai): Add video with audio sample for Gemini 1.5 (#3663)
Co-authored-by: Patti Shin <[email protected]>
1 parent 7b740dc commit 6383448

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// [START generativeaionvertexai_gemini_video_with_audio]
16+
const {VertexAI} = require('@google-cloud/vertexai');
17+
18+
/**
19+
* TODO(developer): Update these variables before running the sample.
20+
*/
21+
async function analyze_video_with_audio(projectId = 'PROJECT_ID') {
22+
const vertexAI = new VertexAI({project: projectId, location: 'us-central1'});
23+
24+
const generativeModel = vertexAI.getGenerativeModel({
25+
model: 'gemini-1.5-pro-preview-0409',
26+
});
27+
28+
const filePart = {
29+
file_data: {
30+
file_uri: 'gs://cloud-samples-data/generative-ai/video/pixel8.mp4',
31+
mime_type: 'video/mp4',
32+
},
33+
};
34+
const textPart = {
35+
text: `
36+
Provide a description of the video.
37+
The description should also contain anything important which people say in the video.`,
38+
};
39+
40+
const request = {
41+
contents: [{role: 'user', parts: [filePart, textPart]}],
42+
};
43+
44+
const resp = await generativeModel.generateContent(request);
45+
const contentResponse = await resp.response;
46+
console.log(JSON.stringify(contentResponse));
47+
}
48+
// [END generativeaionvertexai_gemini_video_with_audio]
49+
50+
analyze_video_with_audio(...process.argv.slice(2)).catch(err => {
51+
console.error(err.message);
52+
process.exitCode = 1;
53+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
const {assert} = require('chai');
18+
const {describe, it} = require('mocha');
19+
const cp = require('child_process');
20+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
21+
22+
const projectId = process.env.CAIP_PROJECT_ID;
23+
24+
describe('Analyze video with audio', async () => {
25+
it('should analyze video with audio', async () => {
26+
const output = execSync(`node ./gemini-video-audio.js ${projectId}`);
27+
28+
assert(output.length > 0);
29+
});
30+
});

0 commit comments

Comments
 (0)