Skip to content
Snippets Groups Projects
Commit b85dd6f8 authored by spmohanty's avatar spmohanty
Browse files

Upload and save reference to a randomly chosen static frame

parent 3ec11100
No related branches found
No related tags found
No related merge requests found
...@@ -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")
......
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