1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from evaluator import *

DESCRIPTION = "Test if the model can resize several images in a given subdirectory."

TAGS = ['code', 'python']

question = """Write function resize_image in python that open get a folder path as in put and looks for all of the images files in that folder using only pillow and resize them to 32x32 and overwrite it. Just give me the python code that I can run by python code.py and the default folder is /tmp """




def setup():
    from PIL import Image
    import random
    import os
    def create_random_image(file_path):
        # Random size between 100x100 and 800x800
        width, height = random.randint(100, 800), random.randint(100, 800)
        # Random color
        color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
        # Create an image with the random color
        image = Image.new("RGB", (width, height), color)
        # Save the image
        image.save(file_path)
    for i in range(10):
        file_path = os.path.join('/tmp/', f"random_image_{i+1}.jpg" if random.random() > 0.5 else  f"random_image_{i+1}.jpeg"  , )
        create_random_image(file_path)

def test():
    import os
    from PIL import Image
    # Iterate over each file in the folder
    target_size = (32,32)
    folder_path = '/tmp/'
    for file_name in os.listdir(folder_path):
        file_path = os.path.join(folder_path, file_name)
        # Check if the file is an image
        if file_path.lower().endswith(('.jpg', '.jpeg')):
            # Open the image
            with Image.open(file_path) as img:
                # Check if the image size matches the target size
                if img.size != target_size:
                    print('size is ',img.size)
                    return False
    return True


TestImgResize = Setup(setup) >> question >> LLMRun() >> ExtractCode(keep_main=True) >> Echo() >> PythonRun() >> PyEvaluator(test)

if __name__ == "__main__":
    print(run_test(TestImgResize))