1from pathlib import Path
2
3from kern.agent import Agent
4from kern.media import Audio
5from kern.models.google import Gemini
6
7model = Gemini(id="gemini-2.0-flash-exp")
8agent = Agent(
9 model=model,
10 markdown=True,
11)
12
13# Please download a sample audio file to test this Agent and upload using:
14audio_path = Path(__file__).parent.joinpath("sample.mp3")
15audio_file = None
16
17remote_file_name = f"files/{audio_path.stem.lower()}"
18try:
19 audio_file = model.get_client().files.get(name=remote_file_name)
20except Exception as e:
21 print(f"Error getting file {audio_path.stem}: {e}")
22 pass
23
24if not audio_file:
25 try:
26 audio_file = model.get_client().files.upload(
27 file=audio_path,
28 config=dict(name=audio_path.stem, display_name=audio_path.stem),
29 )
30 print(f"Uploaded audio: {audio_file}")
31 except Exception as e:
32 print(f"Error uploading audio: {e}")
33
34agent.print_response(
35 "Tell me about this audio",
36 audio=[Audio(content=audio_file)],
37 stream=True,
38)