Spaces:
Sleeping
Sleeping
File size: 1,826 Bytes
ca3fb9c |
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 |
"""
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]
"""
|