A Flask-based web application that generates YouTube thumbnails using AI. This application uses OpenAI's GPT-3.5 for generating image descriptions and Stability AI's Stable Diffusion XL for creating high-quality thumbnails.
- AI-Powered Thumbnail Generation: Generate custom YouTube thumbnails using Stable Diffusion XL
- Text-to-Image: Create thumbnails from text descriptions
- Image-to-Image: Transform existing images into thumbnails with AI
- Text Overlay: Add custom text to generated thumbnails
- Multiple Orientations: Support for both horizontal and vertical thumbnail formats
- Style Presets: Various artistic styles for thumbnail generation
- Order Management: Track available images per order via PostgreSQL database
- Webhook Integration: Handle Stripe webhook events for order processing
- Monthly Generation Limits: Built-in limit tracking for image generation
- Backend: Flask (Python)
- AI Services:
- OpenAI GPT-3.5 Turbo (for description generation)
- Stability AI Stable Diffusion XL (for image generation)
- Database: PostgreSQL
- Image Processing: Pillow (PIL)
- Payment Processing: Stripe (via webhooks)
aiThumbnailGenerator/
├── main.py # Main Flask application
├── requirements.txt # Python dependencies
├── static/
│ ├── generated_images/ # Generated thumbnails storage
│ │ ├── demoFace.jpeg # Example thumbnail with face
│ │ └── demoText.jpeg # Example thumbnail with text overlay
│ ├── html/ # HTML templates
│ │ ├── index.html
│ │ ├── index2.html
│ │ └── countdown.html
│ ├── fonts/ # Custom fonts
│ │ └── BebasNeue-Regular.ttf
│ ├── stock/ # Stock images and assets
│ ├── script.js # Frontend JavaScript
│ ├── style.css # Stylesheet
│ └── webhook_data.json # Webhook data storage
└── images/ # User-uploaded images
The static/generated_images/ folder contains example thumbnails generated by the application:
- demo4.png - Example horizontal thumbnail
- demoFace.jpeg - Example thumbnail featuring a person/face
- demoText.jpeg - Example thumbnail with text overlay applied
The demoText.jpeg file demonstrates the text overlay feature, showing how custom text can be added to AI-generated thumbnails to create professional-looking YouTube thumbnails.
-
Clone the repository
git clone <repository-url> cd aiThumbnailGenerator
-
Install dependencies
pip install -r requirements.txt
-
Set up environment variables Create a
.envfile or set the following environment variables:PGHOST- PostgreSQL hostPGDATABASE- PostgreSQL database namePGUSER- PostgreSQL usernamePGPASSWORD- PostgreSQL passwordDREAMSTUDIO- Stability AI API keyOPENAI- OpenAI API key
-
Set up PostgreSQL database Create the required table:
CREATE TABLE webhook_orders ( order_id VARCHAR PRIMARY KEY, contact_email VARCHAR, created_at TIMESTAMP, expiration_time TIMESTAMP, total_price DECIMAL, available_images INTEGER );
-
Run the application
python main.py
The application will be available at
http://localhost:5000
Retrieve order information and available images for a given email.
Request:
{
"contact_email": "user@example.com"
}Response:
{
"order_id": "order_123",
"available_images": 10
}Generate AI thumbnails based on provided parameters.
Request:
{
"title": "Video Title",
"description": "Additional description",
"order_id": "order_123",
"orientacion": "horizontal",
"style": "photographic",
"textused": "MINIATURA CON TEXTO",
"img": null,
"similarity": 0.5
}Upload an image file to the server.
Request: Multipart form data with image field
Response:
{
"image_url": "images/filename.jpg"
}Handle Stripe webhook events for order processing.
Get list of recently generated images.
- Width/Height: Automatically calculated based on orientation
- Horizontal: 1344x768 (16:9 aspect ratio)
- Vertical: 768x1344
- Steps: 50 (generation quality)
- CFG Scale: 8-8.5 (guidance scale)
- Style Presets: Various options including photographic, digital-art, etc.
The application tracks generated images per month and enforces limits to prevent overuse of API quotas.
- Access the web interface at the root URL
- Enter order information (email/order ID)
- Provide thumbnail details:
- Video title
- Description (optional)
- Orientation (horizontal/vertical)
- Style preset
- Text overlay option
- Upload base image (optional, for image-to-image generation)
- Generate thumbnails - The AI will create two variations
- Download or use the generated thumbnails
Key dependencies include:
- Flask 2.3.2
- OpenAI 0.27.8
- Pillow 10.0.0
- requests 2.31.0
- psycopg2-binary 2.9.9
- numpy 1.25.2
- stripe 6.0.0
See requirements.txt for the complete list.
- The application requires active API keys for both OpenAI and Stability AI
- Generated images are stored in
static/generated_images/ - User-uploaded images are stored in the
images/folder - The database tracks available images per order to manage usage limits
- Webhook integration handles payment processing and order creation
[Add your license information here]