|
|
import google.generativeai as genai |
|
|
import streamlit as st |
|
|
from PIL import Image |
|
|
import io |
|
|
|
|
|
|
|
|
GOOGLE_API_KEY = st.secrets["GOOGLE_API_KEY"] |
|
|
genai.configure(api_key=GOOGLE_API_KEY) |
|
|
|
|
|
|
|
|
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}" |