Agent with Image Input
AWS Bedrock supports image input with models like amazon.nova-pro-v1:0. You can use this to analyze images and get information about them.
Code
1from pathlib import Path2from kern.agent import Agent3from kern.media import Image4from kern.models.aws import AwsBedrock5from kern.tools.hackernews import HackerNewsTools67agent = Agent(8 model=AwsBedrock(id="amazon.nova-pro-v1:0"),9 tools=[HackerNewsTools()],10 markdown=True,11)1213image_path = Path(__file__).parent.joinpath("sample.jpg")1415# Read the image file content as bytes16with open(image_path, "rb") as img_file:17 image_bytes = img_file.read()1819agent.print_response(20 "Tell me about this image and give me the latest news about it.",21 images=[22 Image(content=image_bytes, format="jpeg"),23 ],24)Usage
Set up your virtual environment
1uv venv --python 3.122source .venv/bin/activate1uv venv --python 3.122.venv\Scripts\activateSet your AWS Credentials
1export AWS_ACCESS_KEY_ID=***2export AWS_SECRET_ACCESS_KEY=***3export AWS_REGION=***Install dependencies
1uv pip install -U boto3 kern-aiAdd an Image
Place an image file named sample.jpg in the same directory as your script.
Run Agent
1python image_agent.py