-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_forest.py
More file actions
executable file
·66 lines (54 loc) · 2.18 KB
/
generate_forest.py
File metadata and controls
executable file
·66 lines (54 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python3
"""
Generate a high-quality forest image using DALL-E 3
"""
import os
from openai import OpenAI
from datetime import datetime
from pathlib import Path
import httpx
def generate_forest_image():
# Setup
api_key = os.environ.get("OPENAI_API_KEY")
if not api_key:
print("Error: OPENAI_API_KEY not found in environment")
return None
client = OpenAI(api_key=api_key)
output_dir = Path.home() / "Pictures" / "dalle_generated"
output_dir.mkdir(parents=True, exist_ok=True)
# High-quality forest prompt
prompt = """A breathtaking high-resolution photograph of a pristine ancient forest at golden hour.
Towering old-growth trees with moss-covered trunks reaching toward the sky, dappled sunlight
filtering through dense green canopy creating dramatic light rays (god rays).
Lush ferns carpeting the forest floor, a soft mist hovering near the ground.
Rich depth of field with incredible detail in the bark textures and foliage.
Cinematic composition, nature photography, 8K quality, professional landscape photography."""
print(f"Generating forest image with DALL-E 3...")
print(f"Prompt: {prompt[:100]}...")
# Generate image
response = client.images.generate(
model="dall-e-3",
prompt=prompt,
size="1792x1024", # High quality landscape format
quality="hd", # HD quality
n=1
)
# Download and save
image_url = response.data[0].url
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
filename = f"forest_{timestamp}.png"
filepath = output_dir / filename
print(f"Downloading image from: {image_url}")
# Download the image
img_response = httpx.get(image_url)
with open(filepath, 'wb') as f:
f.write(img_response.content)
print(f"✓ Image saved to: {filepath}")
print(f"✓ Size: {filepath.stat().st_size / 1024 / 1024:.2f} MB")
return str(filepath)
if __name__ == "__main__":
result = generate_forest_image()
if result:
print(f"\nSuccess! Your forest image is ready at:\n{result}")
else:
print("\nFailed to generate image.")