Spaces:
Sleeping
Sleeping
| import google.generativeai as genai | |
| from PIL import Image | |
| class StoryGenerator: | |
| def __init__(self): | |
| self.model = genai.GenerativeModel('gemini-1.5-flash') | |
| def process_image(self, image_path): | |
| try: | |
| img = Image.open(image_path) | |
| prompt = self.createstory_prompt() | |
| response = self.model.generate_content([prompt, img]) | |
| return response.text | |
| except Exception as e: | |
| return f"Error processing image: {str(e)}" | |
| def createstory_prompt(self): | |
| return """You are a skilled children's story writer. Your task is to create a simple, engaging children's story that naturally incorporates the provided image captions into a cohesive narrative. | |
| Context: | |
| - Target audience: Young children | |
| - Output format: Markdown file | |
| - Story length: 4-5 sentences in line by line separated by \n | |
| Image Captions to incorporate: | |
| {captions} | |
| Writing Guidelines: | |
| - Use age-appropriate vocabulary | |
| - Avoid complex sentence structures | |
| - Create clear connections between events | |
| - Keep the narrative positive and engaging | |
| Your response should be formatted as a proper Markdown file""" | |