diff --git a/flatland/__init__.py b/flatland/__init__.py index 1a4304c9bb3ad7fc5873c18ae638bdc8b6f54b05..3a36fdee3e3c2dbc78ada96aed0464d2032db889 100644 --- a/flatland/__init__.py +++ b/flatland/__init__.py @@ -4,4 +4,4 @@ __author__ = """S.P. Mohanty""" __email__ = 'mohanty@aicrowd.com' -__version__ = '0.3.4' +__version__ = '0.3.5' diff --git a/flatland/evaluators/aicrowd_helpers.py b/flatland/evaluators/aicrowd_helpers.py index f368c4cc2eee848fc8277ea0df061780ef3187ae..662ab17930d5ef7c88ea86dfb6e1d8f889c6ed0f 100644 --- a/flatland/evaluators/aicrowd_helpers.py +++ b/flatland/evaluators/aicrowd_helpers.py @@ -2,6 +2,8 @@ import os import boto3 import uuid import subprocess +import glob +import random ############################################################### # Expected Env Variables @@ -44,6 +46,25 @@ def is_grading(): os.getenv("AICROWD_IS_GRADING", False) +def upload_random_frame_to_s3(frames_folder): + all_frames = glob.glob(os.path.join(frames_folder, "*.png")) + random_frame = random.choice(all_frames) + s3 = get_boto_client() + if not S3_UPLOAD_PATH_TEMPLATE: + raise Exception("S3_UPLOAD_PATH_TEMPLATE not provided...") + if not S3_BUCKET: + raise Exception("S3_BUCKET not provided...") + + image_target_key = S3_UPLOAD_PATH_TEMPLATE.replace(".mp4", ".png").format(str(uuid.uuid4())) + s3.put_object( + ACL="public-read", + Bucket=S3_BUCKET, + Key=image_target_key, + Body=open(random_frame, 'rb') + ) + return image_target_key + + def upload_to_s3(localpath): s3 = get_boto_client() if not S3_UPLOAD_PATH_TEMPLATE: diff --git a/flatland/evaluators/service.py b/flatland/evaluators/service.py index e66161163dcdee48acc0ebcfb0bd6ba397ea72d0..21a5e63f3a0e58ff915c3743eac56250435b5ee4 100644 --- a/flatland/evaluators/service.py +++ b/flatland/evaluators/service.py @@ -483,9 +483,14 @@ class FlatlandRemoteEvaluationService: video_thumb_s3_key = aicrowd_helpers.upload_to_s3( video_thumb_output_path ) + static_thumbnail_s3_key = aicrowd_helpers.upload_random_frame_to_s3( + self.vizualization_folder_name + ) self.evaluation_state["score"]["media_content_type"] = "video/mp4" self.evaluation_state["score"]["media_large"] = video_s3_key self.evaluation_state["score"]["media_thumbnail"] = video_thumb_s3_key + + self.evaluation_state["meta"]["static_media_frame"] = static_thumbnail_s3_key else: print("[WARNING] Ignoring uploading of video to S3") diff --git a/setup.cfg b/setup.cfg index 53c0917acdea5ccd64e0136daed612cbe98b8c5d..a50cc62ffe2a857937342a8fca0ff600f06ed660 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.3.4 +current_version = 0.3.5 commit = True tag = True diff --git a/setup.py b/setup.py index 2b187eb4da425f42a8ad8674ccaa9afc1e9e307a..ae45f16e04eb260d8385826c4f45c297a74406db 100644 --- a/setup.py +++ b/setup.py @@ -79,6 +79,6 @@ setup( test_suite='tests', tests_require=test_requirements, url='https://gitlab.aicrowd.com/flatland/flatland', - version='0.3.4', + version='0.3.5', zip_safe=False, )