Skip to content
This repository was archived by the owner on Sep 16, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
import base64
import io

from src.upload_image import upload_file_to_s3
from upload_image import upload_file_to_s3

# Import environment variables
AWS_REGION = os.environ.get("AWS_REGION", "us-east-1")
MODEL_ID = "amazon.nova-canvas-v1:0"
AWS_ACCESS_KEY_ID = os.environ.get("AWS_ACCESS_KEY")
AWS_SECRET_ACCESS_KEY = os.environ.get("AWS_SECRET_ACCESS_KEY")


async def create_image(prompt,negative_prompt, quality, width, height, seed_value):
"""
Expand All @@ -26,7 +25,7 @@ async def create_image(prompt,negative_prompt, quality, width, height, seed_valu
"""

# Initiate Bedrock Client
bedrock = boto3.client("bedrock-runtime", region_name=AWS_REGION, aws_access_key_id=AWS_ACCESS_KEY_ID, aws_secret_access_key=AWS_SECRET_ACCESS_KEY)
bedrock = boto3.client("bedrock-runtime", region_name=AWS_REGION)

# Set picture parameters
model_input = json.dumps({
Expand Down
13 changes: 2 additions & 11 deletions src/upload_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,13 @@ def upload_file_to_s3(file_object):
:param file_object: File-like object to upload
:return: Pre-signed URL string if successful, else None
"""
aws_access_key_id = os.environ["AWS_ACCESS_KEY"]
aws_secret_access_key = os.environ["AWS_SECRET_ACCESS_KEY"]
aws_region= os.environ['AWS_REGION']
aws_region = os.environ['AWS_REGION']
aws_bucket = os.environ["S3_BUCKET"]

if not aws_bucket or not aws_region or not aws_access_key_id or not aws_secret_access_key:
raise NoCredentialsError()

object_name = generate_unique_object_name()

# Create an S3 client
s3_client = boto3.client('s3', region_name=aws_region, aws_access_key_id= aws_access_key_id,
aws_secret_access_key= aws_secret_access_key, endpoint_url=f'https://s3.{aws_region}.amazonaws.com')
s3_client = boto3.client('s3', region_name=aws_region)

try:
# Upload the file to S3
Expand All @@ -50,9 +44,6 @@ def upload_file_to_s3(file_object):
except FileNotFoundError:
print(f"The file {file_object} was not found.")
return None
except NoCredentialsError:
print("AWS credentials are not available.")
return None
except ClientError as e:
print(f"Client error: {e}")
return None
11 changes: 4 additions & 7 deletions src/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
MODEL_ID = "amazon.nova-reel-v1:0"
S3_DESTINATION_BUCKET = os.environ.get("S3_BUCKET")
AWS_REGION = os.environ.get("AWS_REGION", "us-east-1")
AWS_ACCESS_KEY_ID = os.environ.get("AWS_ACCESS_KEY")
AWS_SECRET_ACCESS_KEY = os.environ.get("AWS_SECRET_ACCESS_KEY")


async def create_video(prompt):
"""
Expand All @@ -18,7 +17,7 @@ async def create_video(prompt):
"""

# Initiate Bedrock Client
bedrock_runtime = boto3.client("bedrock-runtime", region_name=AWS_REGION, aws_access_key_id =AWS_ACCESS_KEY_ID, aws_secret_access_key=AWS_SECRET_ACCESS_KEY)
bedrock_runtime = boto3.client("bedrock-runtime", region_name=AWS_REGION)

# Set video parameters
model_input = {
Expand All @@ -44,14 +43,12 @@ async def create_video(prompt):
s3_prefix = invocation_arn.split('/')[-1]

# Initiate S3 Client
s3_client = boto3.client('s3', region_name=AWS_REGION, aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
endpoint_url=f'https://s3.{AWS_REGION}.amazonaws.com')
s3_client = boto3.client('s3', region_name=AWS_REGION)

# Get pre-signed URL for the video to be generated
url = s3_client.generate_presigned_url('get_object',
Params={'Bucket': S3_DESTINATION_BUCKET,
'Key': f"{s3_prefix}/output.mp4"},
ExpiresIn=7200)

return url
return url