in tooling/enrichment/gemini_client.py [0:0]
def get_image_description(image_bytes, project_id, product_data):
"""Generate image description using Vertex AI Gemini Flash."""
init_gemini(project_id)
model = GenerativeModel("gemini-1.5-flash-001")
generation_config = {
"max_output_tokens": 8192,
"temperature": 0.2,
"top_p": 0.95,
}
safety_settings = [
SafetySetting(
category=SafetySetting.HarmCategory.HARM_CATEGORY_HATE_SPEECH,
threshold=SafetySetting.HarmBlockThreshold.OFF
),
SafetySetting(
category=SafetySetting.HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
threshold=SafetySetting.HarmBlockThreshold.OFF
),
SafetySetting(
category=SafetySetting.HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,
threshold=SafetySetting.HarmBlockThreshold.OFF
),
SafetySetting(
category=SafetySetting.HarmCategory.HARM_CATEGORY_HARASSMENT,
threshold=SafetySetting.HarmBlockThreshold.OFF
),
]
try:
image_part = Part.from_data(data=image_bytes, mime_type="image/png")
brand_name = product_data.get('brand', 'Unknown Brand')
product_name = product_data.get('name', '')
category = product_data.get('category', '')
retail_price = product_data.get('retail_price', '')
prompt = f"""Analyze this {brand_name} product image and provide a compelling e-commerce description that includes:
1. Product name: {product_name}
2. Brand highlights: Emphasize {brand_name}'s reputation and quality in the {category} category
3. Key product features and specifications
4. Materials and construction quality
5. Colors and design elements
6. Size and dimensions (if visible)
7. Unique selling points and value proposition (considering the retail price of ${retail_price})
8. Target audience or use cases
9. Any visible brand elements or distinctive features
Focus on creating persuasive content that highlights the {brand_name} brand value and helps shoppers make a confident purchase decision."""
response = model.generate_content(
[prompt, image_part],
generation_config=generation_config,
safety_settings=safety_settings,
)
return response.text
except Exception as e:
print(f"Error generating image description: {str(e)}")
return None