File size: 3,549 Bytes
a11d064
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
"""
Sample image generator for the Handwriting Assessment App
Creates realistic sample images for demonstration purposes.
Optimized for gemini3n series model requirements (768x768 resolution).
"""

from PIL import Image, ImageDraw, ImageFont

def create_sample_answer_key_image():
    """Create a sample answer key image optimized for gemini3n series (768x768)."""
    img_width, img_height = 768, 768  # Optimal resolution for gemini3n series
    img = Image.new('RGB', (img_width, img_height), color='white')
    draw = ImageDraw.Draw(img)
    
    # Try to use a font that looks more like handwriting
    try:
        # Try different handwriting-like fonts
        font_large = ImageFont.truetype("Brush Script MT.ttf", 50)
        font_medium = ImageFont.truetype("Brush Script MT.ttf", 45)
    except:
        try:
            font_large = ImageFont.truetype("Comic Sans MS.ttf", 45)
            font_medium = ImageFont.truetype("Comic Sans MS.ttf", 40)
        except:
            font_large = ImageFont.load_default()
            font_medium = ImageFont.load_default()
    
    # Sample answer key content
    lines = [
        ("Question 1: What is the capital of France?", font_medium),
        ("Answer: Paris", font_large),
        ("", font_medium),
        ("Question 2: Calculate 15 + 27", font_medium),
        ("Answer: 42", font_large),
        ("", font_medium),
        ("Question 3: Name three primary colors", font_medium),
        ("Answer: Red, Blue, Yellow", font_large)
    ]
    
    y_position = 80  # Start lower to center content better
    for line_text, font in lines:
        if line_text:  # Skip empty lines
            # Add slight randomness to make it look more natural
            x_offset = 60 + (hash(line_text) % 15)
            draw.text((x_offset, y_position), line_text, fill='black', font=font)
        y_position += 80  # Increase spacing for larger canvas
    
    return img

def create_sample_student_response_image():
    """Create a sample student response image optimized for gemini3n series (768x768)."""
    img_width, img_height = 768, 768  # Optimal resolution for gemini3n series
    img = Image.new('RGB', (img_width, img_height), color='white')
    draw = ImageDraw.Draw(img)
    
    try:
        font_large = ImageFont.truetype("Brush Script MT.ttf", 50)
        font_medium = ImageFont.truetype("Brush Script MT.ttf", 45)
    except:
        try:
            font_large = ImageFont.truetype("Comic Sans MS.ttf", 45)
            font_medium = ImageFont.truetype("Comic Sans MS.ttf", 40)
        except:
            font_large = ImageFont.load_default()
            font_medium = ImageFont.load_default()
    
    # Student response with slight variations
    lines = [
        ("Question 1: What is the capital of France?", font_medium),
        ("Answer: Paris", font_large),
        ("", font_medium),
        ("Question 2: Calculate 15 + 27", font_medium),
        ("Answer: 42", font_large),
        ("", font_medium),
        ("Question 3: Name three primary colors", font_medium),
        ("Answer: Red, Blue, Yellow", font_large)  # Same as answer key for high score
    ]
    
    y_position = 80  # Start lower to center content better
    for line_text, font in lines:
        if line_text:
            # Add different randomness for student response
            x_offset = 65 + (hash(line_text + "student") % 20)
            draw.text((x_offset, y_position), line_text, fill='black', font=font)
        y_position += 80  # Increase spacing for larger canvas
    
    return img