Skip to content
Snippets Groups Projects
Commit e271ea3f authored by mohanty's avatar mohanty
Browse files

Merge branch 'spm/code-improvements' into 'master'

Spm/code improvements

See merge request flatland/flatland!136
parents 3ec11100 f14ddb70
No related branches found
No related tags found
No related merge requests found
...@@ -4,4 +4,4 @@ ...@@ -4,4 +4,4 @@
__author__ = """S.P. Mohanty""" __author__ = """S.P. Mohanty"""
__email__ = 'mohanty@aicrowd.com' __email__ = 'mohanty@aicrowd.com'
__version__ = '0.3.4' __version__ = '0.3.5'
...@@ -2,6 +2,8 @@ import os ...@@ -2,6 +2,8 @@ import os
import boto3 import boto3
import uuid import uuid
import subprocess import subprocess
import glob
import random
############################################################### ###############################################################
# Expected Env Variables # Expected Env Variables
...@@ -44,6 +46,25 @@ def is_grading(): ...@@ -44,6 +46,25 @@ def is_grading():
os.getenv("AICROWD_IS_GRADING", False) 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): def upload_to_s3(localpath):
s3 = get_boto_client() s3 = get_boto_client()
if not S3_UPLOAD_PATH_TEMPLATE: if not S3_UPLOAD_PATH_TEMPLATE:
......
...@@ -483,9 +483,14 @@ class FlatlandRemoteEvaluationService: ...@@ -483,9 +483,14 @@ class FlatlandRemoteEvaluationService:
video_thumb_s3_key = aicrowd_helpers.upload_to_s3( video_thumb_s3_key = aicrowd_helpers.upload_to_s3(
video_thumb_output_path 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_content_type"] = "video/mp4"
self.evaluation_state["score"]["media_large"] = video_s3_key self.evaluation_state["score"]["media_large"] = video_s3_key
self.evaluation_state["score"]["media_thumbnail"] = video_thumb_s3_key self.evaluation_state["score"]["media_thumbnail"] = video_thumb_s3_key
self.evaluation_state["meta"]["static_media_frame"] = static_thumbnail_s3_key
else: else:
print("[WARNING] Ignoring uploading of video to S3") print("[WARNING] Ignoring uploading of video to S3")
......
[bumpversion] [bumpversion]
current_version = 0.3.4 current_version = 0.3.5
commit = True commit = True
tag = True tag = True
......
...@@ -79,6 +79,6 @@ setup( ...@@ -79,6 +79,6 @@ setup(
test_suite='tests', test_suite='tests',
tests_require=test_requirements, tests_require=test_requirements,
url='https://gitlab.aicrowd.com/flatland/flatland', url='https://gitlab.aicrowd.com/flatland/flatland',
version='0.3.4', version='0.3.5',
zip_safe=False, zip_safe=False,
) )
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment