#!/usr/bin/env python3 """ VERTEX AI IMAGEN - SIMPLE SETUP Using Application Default Credentials (easiest method) """ import vertexai from vertexai.preview.vision_models import ImageGenerationModel import os from pathlib import Path # ======================================== # CONFIGURATION # ======================================== PROJECT_ID = "gen-lang-client-0428644398" # Your Google Cloud project LOCATION = "us-central1" # Imagen location # Initialize Vertex AI vertexai.init(project=PROJECT_ID, location=LOCATION) # ======================================== # IMAGE GENERATION # ======================================== def generate_image_vertex(prompt, output_path): """Generate image using Vertex AI Imagen""" print(f"šŸŽØ Generating: {output_path.name}") print(f"šŸ“ Prompt: {prompt[:80]}...") try: # Load the model model = ImageGenerationModel.from_pretrained("imagegeneration@006") # Generate image response = model.generate_images( prompt=prompt, number_of_images=1, aspect_ratio="1:1", safety_filter_level="block_some", person_generation="allow_adult" ) # Save image output_path.parent.mkdir(parents=True, exist_ok=True) response.images[0].save(location=str(output_path)) print(f"āœ… Saved: {output_path}") return True except Exception as e: print(f"āŒ Error: {e}") return False # ======================================== # EXAMPLE USAGE # ======================================== if __name__ == "__main__": # Test generation test_prompt = "2D game prop, cartoon vector art with bold black outlines, flat vibrant colors. Asset: DINOSAUR SKULL with teeth. Background: SOLID BRIGHT GREEN (#00FF00)" test_output = Path("test_vertex_output.png") print("="*60) print("šŸ¦– VERTEX AI IMAGEN - TEST") print("="*60) success = generate_image_vertex(test_prompt, test_output) if success: print("\nāœ… SUCCESS! Vertex AI is working!") print(f"šŸ“ Check: {test_output}") else: print("\nāŒ FAILED! Check credentials.")