""" project @ LearnableAI created @ 2025-01-17 author @ github.com/ishworrsubedii """ import google.generativeai as genai from PIL import Image class ImageDescriptionGenerator: def __init__(self): self.model = genai.GenerativeModel('gemini-1.5-flash') def process_image(self, image_path, difficulty_level, ): try: img = Image.open(image_path) prompt = self._create_analysis_prompt(difficulty_level) response = self.model.generate_content([prompt, img]) return response.text except Exception as e: return f"Error processing image: {str(e)}" def _create_analysis_prompt(self, difficulty_level): return f""" # Image Analysis for Children Please analyze this image and create child-friendly content based on these parameters: - Difficulty Level: {difficulty_level} Generate the following: 1. Simple description of the image (2-3 sentences) 2. Three interesting details about what you see 3. Four age-appropriate questions about the image 4. One interactive activity related to the image Requirements: - Use simple, clear language appropriate for {difficulty_level} level - Questions should encourage observation and critical thinking - Include both easy and slightly challenging questions - Activity should be engaging and educational Format the response exactly like this: DESCRIPTION: [Image description] INTERESTING DETAILS: 1. [Detail 1] 2. [Detail 2] 3. [Detail 3] QUESTIONS: Q1: [Question 1] Q2: [Question 2] Q3: [Question 3] Q4: [Question 4] ACTIVITY: [Activity description] """