Spaces:
Sleeping
Sleeping
Nur Arifin Akbar
Fix sample data loading by using static image files instead of dynamic generation
b6de031
| """ | |
| Generate static sample images for the Handwriting Assessment App | |
| """ | |
| 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 | |
| img = Image.new('RGB', (img_width, img_height), color='white') | |
| draw = ImageDraw.Draw(img) | |
| # Use default font to avoid font loading issues | |
| try: | |
| font_large = ImageFont.truetype("/System/Library/Fonts/Arial.ttf", 40) | |
| font_medium = ImageFont.truetype("/System/Library/Fonts/Arial.ttf", 35) | |
| 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 | |
| for line_text, font in lines: | |
| if line_text: | |
| x_offset = 60 | |
| draw.text((x_offset, y_position), line_text, fill='black', font=font) | |
| y_position += 80 | |
| 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 | |
| img = Image.new('RGB', (img_width, img_height), color='white') | |
| draw = ImageDraw.Draw(img) | |
| try: | |
| font_large = ImageFont.truetype("/System/Library/Fonts/Arial.ttf", 40) | |
| font_medium = ImageFont.truetype("/System/Library/Fonts/Arial.ttf", 35) | |
| 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) | |
| ] | |
| y_position = 80 | |
| for line_text, font in lines: | |
| if line_text: | |
| x_offset = 65 | |
| draw.text((x_offset, y_position), line_text, fill='black', font=font) | |
| y_position += 80 | |
| return img | |
| if __name__ == "__main__": | |
| # Generate and save sample images | |
| answer_key_img = create_sample_answer_key_image() | |
| answer_key_img.save("sample_answer_key.png") | |
| print("Created sample_answer_key.png") | |
| student_response_img = create_sample_student_response_image() | |
| student_response_img.save("sample_student_response.png") | |
| print("Created sample_student_response.png") |