MAD Social Automation is a comprehensive AI-powered social media content generation system designed for climate action organizations. The application automates the creation of platform-optimized social media posts using advanced AI APIs (OpenAI GPT-4 and Leonardo.AI) and provides a complete workflow from content generation to approval and distribution.
- Primary Function: Automated generation of climate-focused social media content
- Target Users: Climate activists, designers, content creators, and organizations
- Content Types: Posts, Stories, Reels, Carousels, and Videos
- Supported Platforms: Instagram, Facebook, TikTok, Twitter
| Component | Technology | Purpose |
|---|---|---|
| Backend Framework | Flask | Web server and API endpoints |
| AI Text Generation | OpenAI GPT-4 | Caption, headline, and hashtag generation |
| AI Image Generation | Leonardo.AI | Custom image creation with photorealistic quality |
| Database | SQLite | Post history and metadata storage |
| Frontend | HTML/CSS/JavaScript + Bootstrap 5 | Web interface for content approval |
| Environment Management | python-dotenv | Secure API key management |
| Image Processing | Pillow | Image manipulation and optimization |
| HTTP Client | requests | API communication |
| Data Processing | pandas | Data analysis and manipulation |
┌─────────────────┐ ┌──────────────┐ ┌─────────────────┐
│ CLI Interface │ │ Web Interface│ │ Scheduled Tasks │
│ (main.py) │ │ (web.py) │ │ (cron/scheduler)│
└─────────┬───────┘ └──────┬───────┘ └─────────┬───────┘
│ │ │
└───────────────────┼──────────────────────┘
│
┌─────────▼──────────┐
│ Content Generator │
│ (main.py) │
└─────────┬──────────┘
│
┌─────────▼──────────┐
│ Caption Generator │
│ (OpenAI GPT-4 API) │
└─────────┬──────────┘
│
┌─────────▼──────────┐
│ Image Generator │
│ (Leonardo.AI API) │
└─────────┬──────────┘
│
┌─────────▼──────────┐
│ Database │
│ (SQLite Storage) │
└─────────┬──────────┘
│
┌─────────▼──────────┐
│ Email Notification│
│ (notifier.py) │
└────────────────────┘
- Entry Point: Orchestrates the complete content generation workflow
- CLI Support: Accepts command-line arguments for automated execution
- Scheduling Integration: Supports Google Sheets calendar integration
- Error Handling: Comprehensive error logging and recovery mechanisms
- GPT-4 Integration: Uses OpenAI's latest API for structured content generation
- Platform Optimization: Tailors content format for each social media platform
- Brand Consistency: Maintains MAD Impact's voice and messaging guidelines
- Output Structure:
{ "headline": "Compelling 8-12 word hook", "caption": "150-300 word engaging content", "hashtags": ["#MADImpact", "#ClimateTech", "..."], "cta": "Action-driving call to action" }
- Leonardo.AI Integration: Multiple model configurations for photorealistic results
- OpenAI Prompt Enhancement: Uses GPT-4 to create optimized image prompts
- Platform-Specific Dimensions: Automatically adjusts image sizes per platform requirements
- Fallback System: Local image pool backup when API fails
- Quality Control: Advanced negative prompting to avoid artificial-looking results
- SQLite Implementation: Lightweight, file-based storage solution
- Post Management: Complete CRUD operations for generated content
- Metadata Tracking: Stores creation dates, channels, status, and performance data
- Query Optimization: Indexed searches for efficient data retrieval
- Content Preview: Visual approval system before publishing
- History Management: Browse and manage previously generated content
- Email Integration: Send approved content via email
- API Endpoints: RESTful API for external integrations
- Environment Variables: Secure API key management
- Platform Dimensions: Optimized image sizes for each social media platform
- Path Management: Organized file system structure
- Validation: Runtime checks for required configurations
- Topic Selection: Manual input or Google Sheets calendar integration
- Platform Selection: Choose target social media platform(s)
- Content Type: Specify post type (post, story, reel, etc.)
- Caption Generation: GPT-4 creates platform-optimized copy with MAD Impact branding
- Prompt Enhancement: GPT-4 optimizes image generation prompts for Leonardo.AI
- Image Creation: Leonardo.AI generates photorealistic images with multiple fallback configurations
- Content Preview: Web interface displays generated content for approval
- Edit Capability: Manual adjustments to captions and metadata
- Image Validation: Multiple quality checks and fallback options
- Database Storage: All approved content saved with full metadata
- Email Notifications: Optional email delivery for review/approval
- File Organization: Systematic storage in organized directory structure
- Environment variable-based configuration
- No hardcoded credentials in source code
- Validation checks for required API keys
- Comprehensive exception catching and logging
- Graceful degradation with fallback options
- Detailed error reporting for debugging
- Local SQLite database (no cloud storage of content)
- User-controlled data retention
- No logging of sensitive information
- Smart Retry Logic: Multiple Leonardo.AI model configurations
- Prompt Optimization: GPT-4 enhanced prompts for better image quality
- Caching Strategy: Local image pool for offline functionality
- Rate Limiting: Appropriate delays between API calls
- Indexed Queries: Optimized search performance
- Connection Management: Context managers for proper resource cleanup
- Batch Operations: Efficient bulk data operations
- Python 3.8+ with virtual environment support
- Internet connection for AI API access
- Sufficient disk space for image storage (100MB+ recommended)
- Email server configuration (for notifications)
- OpenAI API: GPT-4 access required
- Leonardo.AI API: PhotoReal v2 subscription recommended
- Google Sheets API: Optional for calendar integration
- SMTP Server: For email notifications
mad_social_automation/
├── app/ # Core application modules
│ ├── __init__.py # Package initialization
│ ├── main.py # Content generation orchestrator
│ ├── web.py # Flask web interface
│ ├── caption_generator.py # GPT-4 text generation
│ ├── image_generator.py # Leonardo.AI image generation
│ ├── database.py # SQLite database management
│ ├── config.py # Configuration and settings
│ ├── notifier.py # Email notification system
│ ├── history.py # Legacy JSON post tracking
│ ├── calendar_reader.py # Google Sheets integration
│ ├── logger.py # Error logging system
│ └── utils.py # Utility functions
├── images/ # Image storage directories
│ ├── export/ # Generated images output
│ └── pool/ # Fallback image library
├── logs/ # Application logs and history
├── static/ # Web interface assets
│ ├── css/ # Stylesheets
│ └── js/ # JavaScript files
├── templates/ # Flask HTML templates
├── requirements.txt # Python dependencies
├── mad_social.db # SQLite database file
└── README.md # User documentation
- Text Generation: OpenAI GPT-4 for compelling, brand-consistent copy
- Image Generation: Leonardo.AI for photorealistic, non-AI-looking visuals
- Cross-Enhancement: GPT-4 optimizes prompts for Leonardo.AI
- Dimension Optimization: Automatic image sizing per platform requirements
- Content Adaptation: Platform-specific copy formatting and tone
- Hashtag Strategy: Targeted hashtag selection per platform audience
- Visual Preview: Web-based approval system before publishing
- Multiple Fallbacks: Local image pool when AI generation fails
- Error Recovery: Comprehensive retry logic and graceful degradation
- Brand Consistency: MAD Impact messaging and tone guidelines
- Topic Expertise: Climate tech and sustainability content specialization
- Cultural Relevance: Youth-focused, authentic environmental messaging
- Multi-language Support: International content generation
- Video Generation: AI-powered video content creation
- Performance Analytics: Engagement tracking and optimization
- Batch Processing: Multiple platform content generation
- Social Media APIs: Direct publishing to platforms
- CRM Integration: Contact and campaign management
- Analytics Platforms: Performance tracking and insights
- Collaboration Tools: Team-based content workflows
MAD Social Automation represents a sophisticated, production-ready solution for automated climate action content creation. The system effectively combines cutting-edge AI technologies with practical workflow management, delivering a comprehensive tool that maintains brand consistency while scaling content production. The architecture demonstrates best practices in API integration, error handling, and user experience design, making it suitable for both individual creators and organizational deployment.
The codebase shows professional-level development practices with comprehensive error handling, security considerations, and scalable architecture. The dual AI approach (GPT-4 + Leonardo.AI) with intelligent prompt enhancement creates a unique competitive advantage in generating authentic, engaging climate action content.