This guide walks through the practical implementation of a generative AI-powered word-guessing game—where players interpret images generated from hidden prompts and submit textual guesses. The system leverages three specialized large language and foundation models deployed on Amazon Web Services (AWS), demonstrating end-to-end application architecture for production-grade generative AI.
Setting Up the Development Environment
Begin by launching an Amazon SageMaker notebook instance. A ml.g4dn.2xlarge instance is recommended for cost-effective GPU acceleration during model deployment and inference testing. Ensure the attached IAM role grants permissions to access Amazon S3, SageMaker endpoints, and CloudFormation.
Once the instance reaches InService status (~5–10 minutes), open JupyterLab and launch a terminal session. Retrieve the reference implementation from the public S3 bucket:
$ cd /home/ec2-user/SageMaker
$ aws s3 cp s3://aws-jam-challenge-resources/genai-charades/generative-charades.zip .
$ unzip generative-charades.zip
After extraction, the generative-charades/ directory appears in the file browser—containing all source assets: notebooks, model deployment scripts, Streamlit UI components, and CDK infrastructure definitions.
System Architecture Overview
The application comprises three core inference services, each exposed as a managed SageMaker endpoint:
- Image Generator: A fine-tuned Stable Diffusion v2.1 model that renders visual clues from text prompts.
- Embedding Scorer: A sentence-transformer model (
all-MiniLM-L6-v2) computing cosine similarity between user guesses and ground-truth answers. - Hint Composer: A lightweight instruction-tuned LLM (e.g., Falcon-7B-Instruct) generating oblique, non-revealing hints when players request assistance.
Supporting infrastructure includes:
- Amazon S3 for model artifacts and static assets
- Amazon ECS with Fargate for containerized back end orchestration
- Amazon CloudFront for low-latency frontend delivery
Deploying Foundation Models via SageMaker JumpStart
The first notebook—deploy_charades_endpoints.ipynb—orchestrates endpoint creation using SageMaker JumpStart’s prebuilt containers and inference handlers.
For the image generator, the following logic retrieves compatible URIs and configures the endpoint:
from sagemaker import image_uris, model_uris, script_uris
from sagemaker.model import Model
MODEL_ID = "model-txt2img-stabilityai-stable-diffusion-v2-1-base"
INSTANCE_TYPE = "ml.g4dn.2xlarge"
VERSION = "1.1.0"
container = image_uris.retrieve(
framework=None,
model_id=MODEL_ID,
model_version=VERSION,
image_scope="inference",
region="us-east-1"
)
script_uri = script_uris.retrieve(
model_id=MODEL_ID,
model_version=VERSION,
script_scope="inference"
)
model_data = model_uris.retrieve(
model_id=MODEL_ID,
model_version=VERSION,
model_scope="inference"
)
env_vars = {"MMS_MAX_RESPONSE_SIZE": "20000000"}
model = Model(
image_uri=container,
model_data=model_data,
source_dir=script_uri,
env=env_vars,
role="arn:aws:iam::123456789012:role/SageMakerExecutionRole"
)
predictor = model.deploy(
initial_instance_count=1,
instance_type=INSTANCE_TYPE,
endpoint_name="charades-img-gen-v2"
)
Similar patterns apply for deploying the embedding and text-generation models—each with tailored instance types (ml.m5.xlarge suffices for CPU-bound embedding workloads) and environment configurations.
Frontend Delivery and CI/CD Automation
The second notebook—CDK-notebook.ipynb—uses the AWS Cloud Development Kit (CDK) to define and deploy the full-stack application. It provisions:
- A Streamlit web interface hosted on Amazon ECS/Fargate
- An API gateway routing requests to the three SageMaker endpoints
- CloudFront caching and TLS termination
- Automated CI/CD pipelines using AWS CodePipeline and CodeBuild
The CDK stack abstracts infrastructure complexity in to reusable Python constructs, enabling declarative version-controlled deployments. For example, the Streamlit service definition includes health checks, auto-scaling policies, and secure VPC networking—all expressed in code rather than manual console configuraton.
Subsequent articles will cover fine-tuning strategies, latency optimization techniques, and observability instrumentation for these endpoints—including metrics collection, request tracing, and prompt logging for responsible AI governance.