From ea73a94697010a4e06af48e63cfdf60e1ef8f8bb Mon Sep 17 00:00:00 2001 From: Marcus Messer Date: Wed, 14 Jan 2026 09:41:47 +0000 Subject: [PATCH 1/2] Switched response to use S3 images and added logic to check if no images are uploaded --- evaluation_function/evaluation.py | 38 +++++++++++++++++++------------ 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/evaluation_function/evaluation.py b/evaluation_function/evaluation.py index db7c7b8..88e9035 100755 --- a/evaluation_function/evaluation.py +++ b/evaluation_function/evaluation.py @@ -2,10 +2,11 @@ from typing import Any from lf_toolkit.evaluation import Result, Params from ultralytics import YOLO -import base64 from PIL import Image import io import re +import requests +from requests.exceptions import RequestException _model_cache = None @@ -60,18 +61,15 @@ def evaluation_function( def get_best_detection(images): best_detection = None best_conf = 0.0 - - for img_obj in images: - if isinstance(img_obj, dict) and 'data' in img_obj: - base64_img = img_obj['data'] - else: + analysed_images = 0 + + for image_url in images: + try: + image_response = requests.get(image_url) + img = Image.open(io.BytesIO(image_response.content)) + except RequestException as e: + print('Failed to get image: ', e) continue - #base64_img = img_obj # Assume it's a string if not dict - - # Decode base64 to image - base64_img = re.sub('^data:.*;base64,','',base64_img) - img_data = base64.b64decode(base64_img) - img = Image.open(io.BytesIO(img_data)) # Run YOLO prediction results = model.predict(img, conf=0.5) # Adjust conf threshold if needed @@ -116,11 +114,23 @@ def get_best_detection(images): best_conf = conf best_detection = cls + analysed_images += 1 + - return best_conf, best_detection + return best_conf, best_detection, analysed_images - response_conf, response_detection = get_best_detection(response) + response_conf, response_detection, analysed_image_count = get_best_detection(response) + + if analysed_image_count == 0: + is_correct = False + feedback_items = [] + feedback_items.append(('Response', 'Please upload at least one image')) + + return Result( + is_correct=is_correct, + feedback_items=feedback_items + ) #print(target_class) #print(response_detection) From 0852f011989a247155e76ef665e54374e7aaf16b Mon Sep 17 00:00:00 2001 From: Marcus Messer Date: Wed, 14 Jan 2026 09:43:44 +0000 Subject: [PATCH 2/2] Added debug message for answer --- evaluation_function/evaluation.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/evaluation_function/evaluation.py b/evaluation_function/evaluation.py index 88e9035..f754ac0 100755 --- a/evaluation_function/evaluation.py +++ b/evaluation_function/evaluation.py @@ -38,6 +38,8 @@ def evaluation_function( to output the evaluation response. """ global _model_cache + # Answer is where the teacher uploaded images as extra data can be loaded from + print("### Answer: ", answer) print("### Response: ", response) print("### Params: ", params)