def generate_image()

in tooling/enrichment/imagen_client.py [0:0]


def generate_image(row_data, project_id):
    """Generate image based on product data using Vertex AI Imagen."""
    init_imagen(project_id)
    
    # Create a more detailed prompt with specific product attributes
    prompt = f"""Create a professional product image for an e-commerce listing:
Product: {row_data['name']}
Brand: {row_data['brand']}
Category: {row_data['category']} in {row_data['department']} department
Style: Clean, well-lit product photography style with white background
Focus: Show the product clearly with attention to detail and key features"""

    model = ImageGenerationModel.from_pretrained("imagen-3.0-generate-002")
    
    try:
        images = model.generate_images(
            prompt=prompt,
            number_of_images=1,
            language="en",
            aspect_ratio="1:1",
            safety_filter_level="block_some",
            person_generation="allow_adult",
        )
        
        if not images:
            print(f"No images generated for product: {row_data['name']}")
            return None
            
        # Return the first image from the list
        return images[0]
    except Exception as e:
        print(f"Error generating image for product {row_data['name']}: {str(e)}")
        print(f"Prompt used: {prompt}")
        return None