Holiday Pic: Daily Stylized Avatar/Brand Image Generator
This Python script generates a unique daily image based on a holiday theme and sends it via email. It uses AI-powered image generation and integrates with various services to create a personalized experience.
Features
- Generates a daily holiday prompt using AI
- Creates a custom image using Replicate's AI image generation
- Sends the generated image via email
- Uses environment variables for configuration
- Provides interactive prompts for missing configuration
Prerequisites
- Python 3.6+
- A Gmail account (for sending emails)
- Replicate API access
Installation
- Clone this repository or download the
holidaypic.pyscript. - Create a new virtual environment using built-in
venvmodule:
- Activate the virtual environment:
source .venv/bin/activate- Install the required Python packages:
pip install -r requirements.txt
- Create a
.env.localfile in the same directory as the script with the following variables:
SENDER_EMAIL=your_gmail@gmail.com SENDER_PASSWORD=your_gmail_password RECEIVER_EMAIL=recipient@example.com CONTROL_IMAGE=https://example.com/path/to/control/image.jpg
- (Optional) To deactivate the virtual environment, run:
Usage
Run the script using Python:
python3 holidaypic.py [options]
If any required environment variables are missing, the script will prompt you to enter them interactively.
Command-line Arguments
The script supports several command-line arguments to customize its behavior:
--no-email: Skip sending the generated image via email.--control-image PATH: Specify a custom control image to use instead of the default.--no-depth-processing: Skip depth map processing for the control image.
Examples
-
Generate an image and send it via email (default behavior):
-
Generate an image without sending an email:
python3 holidaypic.py --no-email
-
Use a custom control image:
python3 holidaypic.py --control-image path/to/your/image.jpg
-
Use a custom control image that's already a black and white depth map:
python3 holidaypic.py --control-image path/to/depth_map.jpg --no-depth-processing
Argument Details
-
--no-email: Use this flag when you want to generate the image but don't want to send it via email. This is useful for testing or when you want to manually handle the generated image. -
--control-image PATH: This argument allows you to specify a custom image to use as the control for the AI image generation. The control image influences the structure and composition of the generated image. If not provided, the script uses a default control image. -
--no-depth-processing: By default, the script processes the control image to create a depth map. Use this flag if your control image is already a black and white depth map and you want to skip this processing step. This can be useful when you have pre-processed images or want more direct control over the depth information used in image generation.
How It Works
- The script generates a holiday prompt using AI.
- It uses the generated prompt to create a custom image with Replicate's AI image generation service.
- The generated image is then sent via email to the specified recipient.
Configuration
SENDER_EMAIL: The Gmail address used to send the emailSENDER_PASSWORD: An App Password for your Gmail account (see script output for instructions on creating one)RECEIVER_EMAIL: The email address that will receive the generated imageCONTROL_IMAGE: URL of the control image used in the AI image generation processREPLICATE_API: Your Replicate API key for accessing the AI image generation service
Note
Warning
Make sure to keep your .env.local file secure and never commit it to version control systems.
Setting Up Daily Execution
-
Create
run_holidaypic.sh:#!/bin/bash cd /path/to/script/directory /path/to/python3 holidaypic.py
Adjust paths as needed. Add
--no-emailat the end to skip sending emails. -
Make it executable:
chmod +x run_holidaypic.sh
-
Add to crontab:
Add this line to run daily at 9 AM:
0 9 * * * /path/to/run_holidaypic.sh -
Save and exit the crontab editor.
The script will now run automatically every day at 9 AM, generating an image and emailing it by default.
