File size: 1,323 Bytes
a2a5367
 
5d45da0
 
a2a5367
 
 
 
 
 
 
 
 
 
 
 
 
 
f4f018e
a2a5367
 
 
2b36ce3
 
a2a5367
5d45da0
 
 
 
 
 
 
 
a2a5367
5d45da0
 
 
 
a2a5367
 
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
import google.generativeai as genai
import streamlit as st
from PIL import Image
import io

# Set up the API key
GOOGLE_API_KEY = st.secrets["GOOGLE_API_KEY"]
genai.configure(api_key=GOOGLE_API_KEY)

# Create the model
generation_config = {
    "temperature": 1,
    "top_p": 0.95,
    "top_k": 64,
    "max_output_tokens": 8192,
}

model = genai.GenerativeModel(
    model_name="gemini-1.5-pro",
    generation_config=generation_config,
)

def get_meme_template_description(image_bytes):
    """Get a description of the meme template from the image bytes."""
    try:
        image = Image.open(io.BytesIO(image_bytes))
        prompt = """
        You are an AI specialized in describing meme templates. Please provide a detailed description of the meme template in this image. Include:
        1. The name of the meme template (if it's a well-known one)
        2. A description of the visual layout (number of panels, arrangement)
        3. Key visual elements in each panel
        4. The typical use or purpose of this meme template
        5. Where text is usually placed in this template

        Format your response as a concise paragraph.
        """
        response = model.generate_content([prompt, image])
        return response.text
    except Exception as e:
        return f"Error processing image: {e}"