BuildTheFuture / demo_imagen.py
Abs6187's picture
Upload 13 files
8b8c9d3 verified
"""
Demo script for BuildTheFuture application with Imagen integration
Creates sample construction images and demonstrates the enhanced application
"""
import os
import sys
from PIL import Image, ImageDraw, ImageFont
import numpy as np
import random
def create_advanced_sample_images():
"""Create advanced sample construction site images optimized for Imagen"""
# Create samples directory
os.makedirs("samples_imagen", exist_ok=True)
# Sample 1: Modern skyscraper construction
create_skyscraper_construction("samples_imagen/skyscraper_construction.jpg")
# Sample 2: Suspension bridge construction
create_suspension_bridge("samples_imagen/suspension_bridge.jpg")
# Sample 3: Highway construction
create_highway_construction("samples_imagen/highway_construction.jpg")
# Sample 4: Residential building construction
create_residential_construction("samples_imagen/residential_construction.jpg")
print("✅ Advanced sample construction images created in 'samples_imagen' directory")
def create_skyscraper_construction(filename):
"""Create an image of an incomplete modern skyscraper"""
width, height = 800, 1000
img = Image.new('RGB', (width, height), color=(135, 206, 235)) # Sky blue background
draw = ImageDraw.Draw(img)
# Ground level
draw.rectangle([0, height-100, width, height], fill=(105, 105, 105)) # Concrete ground
# Foundation (completed)
draw.rectangle([200, height-200, 600, height-100], fill=(169, 169, 169)) # Gray foundation
# Incomplete steel frame (only partially built)
for i in range(8):
x = 220 + i * 45
# Steel columns
draw.rectangle([x, height-800, x+15, height-200], fill=(64, 64, 64))
# Horizontal beams
if i < 7:
draw.rectangle([x, height-600, x+60, height-590], fill=(64, 64, 64))
draw.rectangle([x, height-400, x+60, height-390], fill=(64, 64, 64))
# Construction crane
draw.rectangle([100, height-300, 130, height-200], fill=(255, 165, 0)) # Crane base
draw.line([115, height-300, 115, height-500], fill=(255, 165, 0), width=5) # Crane mast
draw.line([115, height-500, 300, height-500], fill=(255, 165, 0), width=3) # Crane arm
# Construction materials
draw.rectangle([50, height-150, 150, height-100], fill=(192, 192, 192)) # Steel beams pile
draw.rectangle([650, height-150, 750, height-100], fill=(139, 69, 19)) # Concrete blocks
# Add some construction workers (simplified)
for _ in range(3):
x = random.randint(200, 600)
y = random.randint(height-180, height-120)
draw.ellipse([x, y, x+20, y+30], fill=(255, 255, 0)) # Hard hat
img.save(filename)
print(f"Created: {filename}")
def create_suspension_bridge(filename):
"""Create an image of an incomplete suspension bridge"""
width, height = 1000, 600
img = Image.new('RGB', (width, height), color=(135, 206, 235)) # Sky blue
draw = ImageDraw.Draw(img)
# Water
draw.rectangle([0, height-200, width, height], fill=(0, 100, 200)) # Blue water
# Bridge towers (completed)
draw.rectangle([200, height-500, 250, height-200], fill=(105, 105, 105)) # Left tower
draw.rectangle([750, height-500, 800, height-200], fill=(105, 105, 105)) # Right tower
# Suspension cables (incomplete)
for i in range(5):
y = height-400 + i * 20
# Left side cables
draw.line([250, y, 300, y], fill=(64, 64, 64), width=2)
# Right side cables
draw.line([700, y, 750, y], fill=(64, 64, 64), width=2)
# Bridge deck (incomplete - missing middle section)
draw.rectangle([150, height-250, 300, height-220], fill=(192, 192, 192)) # Left deck
draw.rectangle([700, height-250, 850, height-220], fill=(192, 192, 192)) # Right deck
# Missing middle section (just cables)
for i in range(10):
x = 300 + i * 40
draw.line([x, height-300, x, height-200], fill=(64, 64, 64), width=1)
# Construction equipment
draw.rectangle([400, height-300, 450, height-250], fill=(255, 0, 0)) # Construction barge
draw.rectangle([500, height-300, 550, height-250], fill=(255, 255, 0)) # Crane barge
img.save(filename)
print(f"Created: {filename}")
def create_highway_construction(filename):
"""Create an image of an incomplete highway"""
width, height = 1200, 600
img = Image.new('RGB', (width, height), color=(135, 206, 235)) # Sky blue
draw = ImageDraw.Draw(img)
# Ground
draw.rectangle([0, height-300, width, height], fill=(34, 139, 34)) # Green ground
# Completed highway sections
draw.rectangle([0, height-200, 400, height-100], fill=(64, 64, 64)) # Left highway
draw.rectangle([800, height-200, width, height-100], fill=(64, 64, 64)) # Right highway
# Incomplete middle section (gravel/dirt)
draw.rectangle([400, height-200, 800, height-100], fill=(139, 69, 19)) # Dirt/gravel
# Highway supports (for elevated sections)
for i in range(3):
x = 200 + i * 300
draw.rectangle([x, height-300, x+20, height-200], fill=(105, 105, 105)) # Support columns
# Construction equipment
draw.rectangle([450, height-300, 500, height-250], fill=(255, 255, 0)) # Excavator
draw.rectangle([600, height-300, 650, height-250], fill=(255, 0, 0)) # Dump truck
draw.rectangle([750, height-300, 800, height-250], fill=(0, 255, 0)) # Paver
# Road barriers and signs
for i in range(5):
x = 380 + i * 80
draw.rectangle([x, height-250, x+20, height-200], fill=(255, 255, 0)) # Barriers
# Construction signs
draw.rectangle([500, height-350, 600, height-300], fill=(255, 255, 255)) # Sign
draw.text((520, height-330), "CONSTRUCTION", fill='red')
img.save(filename)
print(f"Created: {filename}")
def create_residential_construction(filename):
"""Create an image of an incomplete residential building"""
width, height = 600, 500
img = Image.new('RGB', (width, height), color=(135, 206, 235)) # Sky blue background
draw = ImageDraw.Draw(img)
# Ground
draw.rectangle([0, height-100, width, height], fill=(139, 69, 19)) # Brown ground
# Foundation (completed)
draw.rectangle([100, height-150, 500, height-100], fill=(169, 169, 169)) # Gray foundation
# Incomplete walls (only partially built)
# First floor (completed)
draw.rectangle([120, height-250, 480, height-150], fill=(192, 192, 192)) # First floor walls
# Second floor (incomplete)
draw.rectangle([120, height-350, 200, height-250], fill=(192, 192, 192)) # Left wall
draw.rectangle([300, height-320, 380, height-250], fill=(192, 192, 192)) # Right wall
# Third floor (just framework)
for i in range(4):
x = 150 + i * 80
draw.rectangle([x, height-450, x+10, height-350], fill=(64, 64, 64)) # Steel beams
# Roof (incomplete)
draw.rectangle([120, height-480, 200, height-450], fill=(139, 69, 19)) # Partial roof
# Windows (some completed, some missing)
for i in range(3):
x = 150 + i * 100
draw.rectangle([x, height-200, x+30, height-170], fill=(173, 216, 230)) # Windows
# Construction equipment
draw.rectangle([50, height-200, 80, height-150], fill=(255, 165, 0)) # Small crane
draw.rectangle([520, height-200, 550, height-150], fill=(255, 0, 0)) # Construction vehicle
# Construction materials
draw.rectangle([50, height-100, 90, height-50], fill=(192, 192, 192)) # Bricks
draw.rectangle([510, height-100, 550, height-50], fill=(139, 69, 19)) # Wood
img.save(filename)
print(f"Created: {filename}")
def run_imagen_demo():
"""Run a demonstration of the enhanced Imagen application"""
print("🏗️ BuildTheFuture Imagen Demo")
print("=" * 50)
# Create advanced sample images
create_advanced_sample_images()
print("\n📁 Advanced sample images created:")
print(" - samples_imagen/skyscraper_construction.jpg")
print(" - samples_imagen/suspension_bridge.jpg")
print(" - samples_imagen/highway_construction.jpg")
print(" - samples_imagen/residential_construction.jpg")
print("\n🚀 To run the enhanced Imagen application:")
print(" 1. Set up your Google AI API key in .env file")
print(" 2. Run: python app_imagen.py")
print(" 3. Upload one of the advanced sample images")
print(" 4. Select 'Imagen (Recommended)' as the AI model")
print(" 5. Choose your preferred style and settings")
print(" 6. Click 'Complete Construction'")
print("\n💡 Imagen Features:")
print(" - Higher quality image generation")
print(" - Multiple aspect ratios (1:1, 4:3, 16:9, etc.)")
print(" - 1K and 2K image quality options")
print(" - Specialized prompts for construction completion")
print(" - Fallback to Gemini 2.5 Flash if needed")
print("\n🎨 Recommended Settings:")
print(" - Realistic style: 4:3 aspect ratio, 2K quality")
print(" - Futuristic style: 16:9 aspect ratio, 2K quality")
print(" - Artistic style: 1:1 aspect ratio, 1K quality")
if __name__ == "__main__":
run_imagen_demo()