65 lines
2.5 KiB
Python
65 lines
2.5 KiB
Python
"""Regenerate only hero-technician and hero-before-after images."""
|
|
import os, sys
|
|
try:
|
|
from google import genai
|
|
from google.genai import types
|
|
except ImportError:
|
|
os.system(f"{sys.executable} -m pip install google-genai --quiet")
|
|
from google import genai
|
|
from google.genai import types
|
|
|
|
API_KEY = os.environ.get("GEMINI_API_KEY", "AIzaSyB_1p8KvaT_rdNJGPs8HKk8bKsvUlcL6Kg")
|
|
OUT_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), "assets", "images", "hero")
|
|
client = genai.Client(api_key=API_KEY)
|
|
|
|
TARGETS = [
|
|
{
|
|
"name": "hero-technician",
|
|
"aspect": "16:9",
|
|
"prompt": (
|
|
"Professional carpet cleaning technician pushing a large upright hot water "
|
|
"extraction machine across residential carpet in a bright modern home interior. "
|
|
"Machine resembles an oversized upright vacuum cleaner with a cylindrical body. "
|
|
"No steam visible anywhere, no water spraying, no hoses visible, completely dry. "
|
|
"Technician shown from behind or side, no face, plain black shirt, no logo. "
|
|
"High-end professional photography."
|
|
),
|
|
},
|
|
{
|
|
"name": "hero-before-after",
|
|
"aspect": "16:9",
|
|
"prompt": (
|
|
"Side-by-side residential living room carpet: left half heavily soiled with mud "
|
|
"and dark stains, right half same carpet after professional hot water extraction "
|
|
"cleaning, bright and pristine. No steam, no water, no machines visible anywhere. "
|
|
"Dramatic before-after contrast. Professional photography, no people."
|
|
),
|
|
},
|
|
]
|
|
|
|
for item in TARGETS:
|
|
out_path = os.path.join(OUT_DIR, f"{item['name']}.jpg")
|
|
print(f"Generating {item['name']}...")
|
|
try:
|
|
resp = client.models.generate_images(
|
|
model="imagen-4.0-generate-001",
|
|
prompt=item["prompt"],
|
|
config=types.GenerateImagesConfig(
|
|
number_of_images=1,
|
|
aspect_ratio=item["aspect"],
|
|
output_mime_type="image/jpeg",
|
|
safety_filter_level="block_low_and_above",
|
|
),
|
|
)
|
|
if resp.generated_images:
|
|
img_bytes = resp.generated_images[0].image.image_bytes
|
|
with open(out_path, "wb") as f:
|
|
f.write(img_bytes)
|
|
print(f" Saved {out_path} ({len(img_bytes)//1024}KB)")
|
|
else:
|
|
print(f" No image returned for {item['name']}")
|
|
except Exception as e:
|
|
print(f" Error: {e}")
|
|
|
|
print("\nDone.")
|