Skip to content

Instantly share code, notes, and snippets.

@alexandre-bruffa
Created October 2, 2023 06:07
Show Gist options
  • Save alexandre-bruffa/537e19a9ab05748ac77b4a10370cc20b to your computer and use it in GitHub Desktop.
Save alexandre-bruffa/537e19a9ab05748ac77b4a10370cc20b to your computer and use it in GitHub Desktop.
import boto3
import json
def lambda_handler(event, context):
bedrock = boto3.client(service_name='bedrock-runtime')
body = json.loads(event["body"])
message = body["message"]
body = json.dumps({
"text_prompts": [
{
"text": message
}
],
"cfg_scale":10,
"seed":20,
"steps":50
})
modelId = "stability.stable-diffusion-xl-v0"
accept = "application/json"
contentType = "application/json"
response = bedrock.invoke_model(
body=body, modelId=modelId, accept=accept, contentType=contentType
)
response_body = json.loads(response.get("body").read())
answer = response_body.get("artifacts")[0].get("base64")
return {
'statusCode': 200,
'body': json.dumps({"answer": answer})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment