def process_single_product()

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


def process_single_product(row):
    """Process a single product and return the result."""
    product_id = row['id']
    row_data = row.to_dict()
    
    try:
        # Start processing and mark in Firestore
        firestore_client.start_product_processing(product_id, row_data)
        
        # Generate safe filename using product ID
        safe_filename = f"product_{product_id}.png"
        
        # Generate image using Imagen client
        image = generate_image(row, PROJECT_ID)
        if not image:
            raise Exception("Failed to generate image")
            
        # Get image description using Gemini client - Updated to pass product_data
        description = get_image_description(image._image_bytes, PROJECT_ID, row_data)
        if not description:
            raise Exception("Failed to generate description")
        
        # Upload to GCS and get URI
        image_uri = upload_to_gcs(image, safe_filename)
        
        # Mark as completed in Firestore
        firestore_client.complete_product_processing(product_id, image_uri, description)
        
        # Add to processed rows for CSV
        row_data['image_uri'] = image_uri
        row_data['description'] = description
        
        print(f"Generated and uploaded image for product ID {product_id}: {image_uri}")
        print(f"Generated description: {description[:100]}...")
        
        return row_data, None
        
    except Exception as e:
        error_message = f"Error processing product: {str(e)}"
        print(error_message)
        firestore_client.mark_product_failed(product_id, error_message)
        return None, error_message