-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathaudio_understanding.py
28 lines (23 loc) · 1.22 KB
/
audio_understanding.py
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
import vertexai
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor
from vertexai.generative_models import GenerativeModel, Part
from openinference.instrumentation.vertexai import VertexAIInstrumentor
endpoint = "http://127.0.0.1:4317"
tracer_provider = TracerProvider()
tracer_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint)))
tracer_provider.add_span_processor(SimpleSpanProcessor(ConsoleSpanExporter()))
VertexAIInstrumentor().instrument(tracer_provider=tracer_provider)
vertexai.init(location="us-central1")
model = GenerativeModel("gemini-1.5-flash")
prompt = """Please provide a summary for the audio.
Provide chapter titles, be concise and short, no need to provide chapter summaries.
Do not make up any information that is not part of the audio and do not be verbose.
"""
audio_file_uri = "gs://cloud-samples-data/generative-ai/audio/pixel.mp3"
audio_file = Part.from_uri(audio_file_uri, mime_type="audio/mpeg")
contents = [audio_file, prompt]
if __name__ == "__main__":
response = model.generate_content(contents)
print(response)