Skip to content

Commit 09d5a6c

Browse files
author
Dinesh Sajwan
committed
feat(visualqa): review comments implemented
1 parent af69009 commit 09d5a6c

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

lambda/aws-qa-appsync-opensearch/question_answering/src/qa_agent/chain.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ def run_question_answering(arguments):
9494
send_job_status(status_variables)
9595
return ''
9696

97-
model_max_tokens = get_max_tokens()
97+
model_id=qa_model['modelId']
98+
model_max_tokens = get_max_tokens(model_id)
9899
logger.info(
99100
f'For the current question, we have a max model length of {model_max_tokens} and a document containing {document_number_of_tokens} tokens')
100101

lambda/aws-qa-appsync-opensearch/question_answering/src/qa_agent/helper.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# and limitations under the License.
1212
#
1313
import os
14+
import tempfile
1415
import boto3
1516
import json
1617
import base64
@@ -195,7 +196,7 @@ def get_presigned_url(bucket,key) -> str:
195196

196197
def download_file(bucket,key )-> str:
197198
try:
198-
file_path = "/tmp/" + os.path.basename(key)
199+
file_path = os.path.join(tempfile.gettempdir(), os.path.basename(image_file))
199200
s3.download_file(bucket, key,file_path)
200201
logger.info(f"file downloaded {file_path}")
201202
return file_path

lambda/aws-rag-appsync-stepfn-opensearch/embeddings_job/src/helpers/image_loader.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#
1313

1414
import os
15+
import tempfile
1516
import time
1617
import base64
1718
import json
@@ -52,7 +53,7 @@ def __init__(self, bucket: str, image_file: str,image_detail_file: str,modelid:s
5253
def encode_image_to_base64(self,image_file_path,image_file) -> str:
5354
with open(image_file_path, "rb") as image_file:
5455
b64_image = base64.b64encode(image_file.read()).decode('utf8')
55-
b64_image_path = os.path.join("/tmp/", f"{Path(image_file_path).stem}.b64")
56+
b64_image_path = os.path.join(tempfile.gettempdir(), f"{Path(image_file_path).stem}.b64")
5657
with open(b64_image_path, "wb") as b64_image_file:
5758
b64_image_file.write(bytes(b64_image, 'utf-8'))
5859
return b64_image_path
@@ -107,8 +108,8 @@ def get_presigned_url(self) -> str:
107108

108109
@tracer.capture_method
109110
def download_file(self,key )-> str:
110-
try:
111-
file_path = "/tmp/" + os.path.basename(key)
111+
try:
112+
file_path = os.path.join(tempfile.gettempdir(), os.path.basename(key))
112113
s3_client.download_file(self.bucket, key,file_path)
113114
print(f"file downloaded {file_path}")
114115
return file_path

lambda/aws-rag-appsync-stepfn-opensearch/s3_file_transformer/src/helpers/image_transformer.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# and limitations under the License.
1212
#
1313
import os
14+
import tempfile
1415
import boto3
1516

1617

@@ -104,9 +105,9 @@ def image_resize(self)-> str:
104105
Image.MAX_IMAGE_PIXELS = 100000000
105106
fileshort = os.path.basename(self.file_name)
106107

107-
print(f'fileshort {fileshort} ')
108-
file_tmp = "/tmp/" + fileshort
109-
108+
109+
file_tmp = os.path.join(tempfile.gettempdir(), os.path.basename(self.file_name))
110+
110111
with Image.open(file_tmp) as image:
111112
image.verify()
112113
with Image.open(file_tmp) as image:

lambda/aws-rag-appsync-stepfn-opensearch/s3_file_transformer/src/helpers/utils.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#
1313

1414
import os
15+
import tempfile
1516
import boto3
1617
import json
1718
from botocore.exceptions import ClientError
@@ -128,7 +129,7 @@ def convert_lables_to_sentence(labels_str)-> str:
128129

129130
def download_file(bucket, object )-> str:
130131
try:
131-
file_path = "/tmp/" + os.path.basename(object)
132+
file_path = os.path.join(tempfile.gettempdir(), os.path.basename(object))
132133
s3.Bucket(bucket).download_file(object, file_path)
133134
return file_path
134135
except ClientError as client_err:
@@ -139,7 +140,7 @@ def download_file(bucket, object )-> str:
139140

140141
def upload_file(bucket, file_name,key )-> str:
141142
try:
142-
file_path = "/tmp/" + os.path.basename(file_name)
143+
file_path = os.path.join(tempfile.gettempdir(), os.path.basename(file_name))
143144
s3.meta.client.upload_file(file_path, bucket,key)
144145
return file_path
145146
except ClientError as client_err:

0 commit comments

Comments
 (0)