A sophisticated AI-powered video content detection system that automatically identifies and validates milk-related campaign content using Twelve Labs' multimodal video understanding API.
This Flask web application simulates a social media platform that can automatically detect and validate "Got Milk" campaign videos. It uses advanced AI to analyze video content for milk-related activities (drinking, pouring, etc.) and organizes validated content into themed communities called "Milk Mobs."
- Twelve Labs Integration: Uses state-of-the-art multimodal AI for video understanding
- Content Detection: Automatically identifies milk drinking, white liquids, dairy products
- Semantic Search: Natural language queries like "person drinking milk" or "glass of milk"
- Multi-format Support: Handles MP4, MOV, AVI, WEBM, and other video formats
- Multi-tier Validation: Twelve Labs API โ Enhanced Validation โ Simple Fallback
- Strict Requirements: 35% content score + 50% total confidence required
- Smart Weighting: 70% video content analysis + 30% campaign hashtags
- Rate Limit Handling: Graceful fallbacks when API limits are reached
Videos are automatically classified into themed communities:
- ๐โโ๏ธ Extreme Milk: Adventure and sports content
- ๐จ Milk Artists: Creative and aesthetic content
- ๐ฝ๏ธ Mukbang Masters: Food and eating shows
- ๐ช Fitness Fuel: Workout and nutrition content
- ๐ฅ Daily Milk: Everyday moments and family content
- Google Cloud Storage: Automatic file upload for processing
- Direct File Upload: Local file processing with Twelve Labs
- URL Processing: Direct video file URLs supported
- Cleanup: Automatic temporary file management
- Campaign Metrics: Detection accuracy, video counts, mob distribution
- API Usage Tracking: Monitor Twelve Labs API calls and performance
- Live Dashboard: Real-time campaign analytics and insights
- Python 3.7+
- Flask and dependencies
- Twelve Labs API account and key
- Google Cloud Storage (optional)
git clone https://github.com/JamesMcDaniel04/twelvelabs_SDK.git
cd got-milk-campaign
pip install flask twelvelabs google-cloud-storage werkzeug
Create src/config.py
:
import os
class Config:
TWELVE_LABS_API_KEY = "your_twelve_labs_api_key_here"
UPLOAD_FOLDER = "uploads"
MAX_CONTENT_LENGTH = 2048 * 1024 * 1024 # 2GB
# Set up authentication
export GOOGLE_APPLICATION_CREDENTIALS="path/to/your/service-account.json"
# Install Google Cloud SDK
pip install google-cloud-storage
- Sign up at Twelve Labs
- Create a video index for your campaign
- Update
MILK_CAMPAIGN_INDEX_ID
inapp.py
with your index ID - Add your API key to
config.py
python app.py
- Main App: http://localhost:5001/social-feed
- Upload Interface: http://localhost:5001/upload
- Campaign Dashboard: http://localhost:5001/campaign-dashboard
POST /upload
- Upload and validate videosGET /explore/<mob_id>
- Browse mob communitiesGET /api/campaign-analytics
- Get campaign metrics
GET /debug/test-twelve-labs-basic
- Test Twelve Labs connectivityGET /debug/test-video/<video_id>
- Test specific video detectionGET /api/twelve-labs-status
- Check API statusGET /debug/list-indexes
- List available Twelve Labs indexes
GET /api/search-milk-content
- Search indexed video contentGET /api/video-preview
- Get video metadata preview
The system includes comprehensive debugging tools:
# Test basic Twelve Labs functionality
curl http://localhost:5001/debug/test-twelve-labs-basic
# Test specific video content detection
curl http://localhost:5001/debug/test-video/VIDEO_ID_HERE
# Check API connectivity
curl http://localhost:5001/api/twelve-labs-status
Upload test videos with different content:
- โ Should Pass: Clear milk drinking videos with campaign hashtags
- โ Should Fail: Non-milk content, videos without hashtags, low-quality content
- Search Terms: 10 comprehensive queries including "person drinking", "glass of milk", "white beverage"
- Multimodal: Visual and audio analysis
- Threshold: Low sensitivity for broader matching
- Minimum: 35% content score required
- Campaign Tags:
#gotmilk
,#milkmob
,#milk
,#dairy
- Weight: Fixed 30% if any campaign hashtags present
- Bonus: Additional scoring for multiple hashtags
- AND Logic: Both content AND confidence requirements must be met
- Minimum Total: 50% combined confidence required
- Strict: No fallback bonuses for failed content detection
โโโ app.py # Main Flask application
โโโ src/
โ โโโ config.py # Configuration settings
โโโ templates/ # HTML templates
โโโ uploads/ # Temporary file storage
โโโ README.md # This file
twelve_labs_validate_video_url()
- URL-based video validationtwelve_labs_validate_video_file()
- File upload validationtest_basic_detection_for_video()
- Debug content detectionclassify_into_mob()
- Community classification logicsimple_validate_video_fallback()
- Fallback validation
Video Upload โ Cloud Storage โ Twelve Labs API โ Content Analysis โ Validation โ Mob Classification โ Storage
- File Validation: Strict file type checking
- Secure Filenames: Automatic sanitization
- Temporary Storage: Automatic cleanup after processing
- API Rate Limiting: Graceful handling of API limits
- Error Handling: Comprehensive exception management
"No content detected" for obvious milk videos:
- Check video quality and lighting
- Verify video duration (very short clips may fail)
- Test with
/debug/test-video/<video_id>
endpoint - Try different video formats
API Rate Limit Errors:
- Wait for rate limit reset (shown in error message)
- System automatically falls back to enhanced validation
- Check
/api/twelve-labs-status
for current limits
Upload Failures:
- Verify file format is supported
- Check file size limits (2GB max)
- Ensure Google Cloud Storage is configured
- Review Flask upload configuration
- Test Basic Connectivity:
/debug/test-twelve-labs-basic
- Verify Index Configuration:
/debug/list-indexes
- Test Specific Video:
/debug/test-video/<video_id>
- Check API Status:
/api/twelve-labs-status
- Cloud Storage: Reduces local storage requirements
- Rate Limit Handling: Automatic fallback mechanisms
- Efficient Search: Optimized query strategies
- Cleanup Automation: Prevents storage accumulation
- API Quotas: Monitor Twelve Labs usage limits
- Storage: Configure appropriate cloud storage buckets
- Processing: Consider async processing for large files
- Caching: Implement result caching for repeated content
- Batch Processing: Multiple video upload support
- Advanced Analytics: Detailed campaign performance metrics
- User Authentication: Multi-user support with permissions
- Content Moderation: Additional safety and quality filters
- Mobile Support: Responsive design improvements
- Social Media APIs: Direct platform integration
- CDN Support: Global content delivery
- Machine Learning: Custom model training
- Real-time Processing: Live stream analysis
This project is developed for demonstration purposes. Please ensure compliance with Twelve Labs API terms of service and applicable privacy regulations.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
For issues and questions:
- Check the debug endpoints for troubleshooting
- Review Twelve Labs documentation for API issues
- Verify configuration settings in
config.py
- Test with known working video content
Built with โค๏ธ using Twelve Labs AI Video Understanding