Spaces:
Sleeping
Sleeping
File size: 1,344 Bytes
d48c324 978360d d48c324 978360d |
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 |
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"""
|