Skip to content

davidpuertolas/AIThumbnailGenerator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

AI Thumbnail Generator

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.

Example Thumbnail with Text Overlay

Features

  • 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

Tech Stack

  • 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)

Project Structure

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

Demo 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.

Installation

  1. Clone the repository

    git clone <repository-url>
    cd aiThumbnailGenerator
  2. Install dependencies

    pip install -r requirements.txt
  3. Set up environment variables Create a .env file or set the following environment variables:

    • PGHOST - PostgreSQL host
    • PGDATABASE - PostgreSQL database name
    • PGUSER - PostgreSQL username
    • PGPASSWORD - PostgreSQL password
    • DREAMSTUDIO - Stability AI API key
    • OPENAI - OpenAI API key
  4. 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
    );
  5. Run the application

    python main.py

    The application will be available at http://localhost:5000

API Endpoints

/get-order-data (POST)

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 (POST)

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 (POST)

Upload an image file to the server.

Request: Multipart form data with image field

Response:

{
  "image_url": "images/filename.jpg"
}

/webhook (POST)

Handle Stripe webhook events for order processing.

/recent_images (GET)

Get list of recently generated images.

Configuration

Image Generation Settings

  • 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.

Monthly Limits

The application tracks generated images per month and enforces limits to prevent overuse of API quotas.

Usage

  1. Access the web interface at the root URL
  2. Enter order information (email/order ID)
  3. Provide thumbnail details:
    • Video title
    • Description (optional)
    • Orientation (horizontal/vertical)
    • Style preset
    • Text overlay option
  4. Upload base image (optional, for image-to-image generation)
  5. Generate thumbnails - The AI will create two variations
  6. Download or use the generated thumbnails

Dependencies

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.

Notes

  • 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

License

[Add your license information here]

Author

@me https://www.linkedin.com/in/david-puertolas-merenciano/

About

A 2023 Flask-based web application that generates YouTube thumbnails using AI.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors