CoolFace
Apppublic

madhumitaj/marketing-content-comparison-agent

sourceHugging Faceupdated 11mo agoView on Hugging Face
0likes
App README

Content Generation & Monitoring Platform

![Python 3.8+](https://www.python.org/downloads/) ![Streamlit](https://streamlit.io/) ![FloTorch](https://flotorch.ai/) ![License: MIT](https://opensource.org/licenses/MIT)

A comprehensive AI-powered content generation platform with advanced monitoring, analytics, and safety features. Built for marketing teams, content creators, and enterprises who need reliable, high-quality content generation with full observability.

πŸš€ Key Features

Multi-Model Content Generation

  • β€”FloTorch Integration: Native support for flotorch/gflash and flotorch/awsnova models
  • β€”Provider Flexibility: Extensible architecture supporting OpenAI, Anthropic, and custom models
  • β€”Intelligent Routing: Automatic model selection based on content type and requirements
  • β€”Parallel Processing: Generate multiple variants simultaneously for A/B testing

Advanced Analytics & Monitoring

  • β€”Real-time Performance Metrics: Latency, token usage, and cost tracking
  • β€”Content Quality Analysis: Readability scores, sentiment analysis, and bias detection
  • β€”Comparative Analytics: Side-by-side model performance comparison
  • β€”Visual Dashboards: Interactive charts and comprehensive data tables

Safety & Compliance

  • β€”Content Moderation: Automated safety checks with policy violation detection
  • β€”Bias Detection: Inclusive language analysis and recommendations
  • β€”Automated Rewriting: AI-powered content improvement for policy compliance
  • β€”Guardrails Integration: Extensible safety framework with custom rules

Enterprise-Ready Features

  • β€”Cost Optimization: Real-time cost estimation and budget tracking
  • β€”Scalable Architecture: Designed for high-throughput production environments
  • β€”Comprehensive Logging: Full audit trails and debugging capabilities
  • β€”Security First: Secure API key management and data protection

πŸ“‹ Table of Contents

⚑ Quick Start

IMPORTANT: Before using this application, you MUST set up your FloTorch account and create your own models.

Step 1: FloTorch Account Setup (Required)

  1. 1.Create FloTorch Account: Visit FloTorch Platform and sign up
  2. 2.Get API Key: Generate your API key from the FloTorch dashboard
  3. 3.Create Your Models: Follow the FloTorch Setup Guide to create at least 2 custom models
  4. 4.Note Your Model Names: Save the exact model names you created (e.g., "your-username/my-model-1")

Step 2: Application Setup

bash
# 1. Clone the repository
git clone https://github.com/your-org/content-gen-monitoring.git
cd content-gen-monitoring

# 2. Install dependencies
pip install -r requirements.txt

# 3. Launch the application
streamlit run app.py

Step 3: Configure in the App

  1. 1.Open your browser to http://localhost:8501
  2. 2.FIRST: In the left sidebar, enter your FloTorch credentials:
  3. 3.Your FloTorch API Key
  4. 4.Your first model name
  5. 5.Your second model name
  6. 6.THEN: Proceed to the main content generation area

Note: You must complete the FloTorch setup and enter your credentials before generating content!

πŸ›  Installation

Prerequisites

  • β€”Python 3.8+ (3.9+ recommended)
  • β€”pip package manager
  • β€”Git for version control

System Requirements

  • β€”Memory: 4GB RAM minimum, 8GB recommended
  • β€”Storage: 1GB free space
  • β€”Network: Internet connection for API access

Step-by-Step Installation

  1. 1.Clone the Repository
bash
   git clone https://github.com/your-org/content-gen-monitoring.git
   cd content-gen-monitoring
  1. 1.Create Virtual Environment (Recommended)
bash
   python -m venv venv
   
   # Windows
   venv\Scripts\activate
   
   # macOS/Linux
   source venv/bin/activate
  1. 1.Install Dependencies
bash
   pip install -r requirements.txt
  1. 1.Verify Installation
bash
   python test_flo_stream.py

Dependencies Overview

PackageVersionPurpose
streamlitβ‰₯1.28.0Web application framework
flotorch-sdkLatestFloTorch platform integration
openaiβ‰₯1.0.0OpenAI API client
pandasβ‰₯1.5.0Data analysis and manipulation
matplotlibβ‰₯3.6.0Data visualization
textstatβ‰₯0.7.0Readability analysis
vaderSentimentβ‰₯3.3.0Sentiment analysis
rouge-scoreβ‰₯0.1.0Content similarity metrics

βš™οΈ Configuration

Environment Variables

Create a .env file in the project root:

bash
# FloTorch Configuration
FLOTORCH_API_KEY=your_flotorch_api_key_here
FLOTORCH_BASE_URL=https://gateway.flotorch.cloud

# OpenAI Configuration (for fallback/comparison)
OPENAI_API_KEY=your_openai_api_key_here
OPENAI_BASE_URL=https://api.openai.com/v1

# Application Settings
STREAMLIT_SERVER_PORT=8501
STREAMLIT_SERVER_ADDRESS=localhost
LOG_LEVEL=INFO

FloTorch Setup (REQUIRED)

You MUST complete this setup before using the application:

  1. 1.Create FloTorch Account
  2. 2.Visit FloTorch Platform
  3. 3.Sign up for a new account
  4. 4.Verify your email and complete account setup
  1. 1.Generate API Key
  2. 2.Log into your FloTorch dashboard
  3. 3.Navigate to API Keys section
  4. 4.Generate a new API key
  5. 5.SAVE THIS KEY - you'll need it in the app
  1. 1.Create Your Custom Models
  2. 2.Follow the detailed FloTorch Setup Guide
  3. 3.Create at least 2 custom models for comparison
  4. 4.IMPORTANT: Note the exact model names (format: "your-username/model-name")
  5. 5.Example model names: "john-doe/marketing-model", "john-doe/creative-model"
  1. 1.Test Your Setup
  2. 2.Ensure your models are active and accessible
  3. 3.Verify your API key has proper permissions

Without completing these steps, the application will not work!

Advanced Configuration

Custom Model Configuration
python
# In app.py or orchestrator.py
CUSTOM_MODELS = [
    {
        "name": "Custom GPT-4",
        "type": "openai",
        "model_id": "gpt-4",
        "cost_tier": "premium",
        "max_tokens": 8192
    },
    {
        "name": "FloTorch Optimized",
        "type": "flotorch",
        "model_id": "flotorch/custom-model",
        "cost_tier": "standard"
    }
]
Safety Configuration
python
# Content moderation thresholds
SAFETY_THRESHOLDS = {
    "marketing": 0.8,      # High safety for marketing
    "social_media": 0.7,   # Moderate for social
    "internal": 0.6,       # Lower for internal use
}

πŸ“– Usage Guide

Basic Content Generation

  1. 1.Launch Application
bash
   streamlit run app.py
  1. 1.Configure Settings (Sidebar)
  2. 2.Select content type (LinkedIn post, Marketing Email, Blog Intro)
  3. 3.Choose tone (professional, friendly, playful, urgent)
  4. 4.Set length (short, medium, long)
  5. 5.Select models to use
  1. 1.Input Content Requirements
  2. 2.Topic: Describe your product/campaign/topic
  3. 3.Product Name: Specific product being promoted
  4. 4.Target Audience: Intended audience demographic
  5. 5.Call-to-Action: Desired action for readers
  1. 1.Generate Content
  2. 2.Click "πŸš€ Generate Content Variants"
  3. 3.Review generated variants
  4. 4.Analyze performance metrics
  5. 5.Use rewrite feature if needed

Advanced Features

Multi-Model Comparison
python
# Generate content with multiple models
from orchestrator import generate_candidates

prompt_spec = {
    "type": "LinkedIn post",
    "topic": "AI-powered marketing automation",
    "cta": "Learn more at our website"
}

results = generate_candidates(
    prompt_spec, 
    tone="professional",
    length="medium",
    models=["flotorch/gflash", "flotorch/awsnova"]
)
Content Quality Analysis
python
# Analyze content quality
from evaluator import readability_score, sentiment_score, bias_checks

content = "Your generated content here"

# Get comprehensive analysis
readability = readability_score(content)
sentiment = sentiment_score(content)
bias = bias_checks(content)

print(f"Readability: {readability['flesch_reading_ease']}")
print(f"Sentiment: {sentiment['compound']}")
print(f"Bias detected: {bias['flagged']}")
Safety and Moderation
python
# Content safety checks
from guardrails import moderate_text, rewrite_safe

content = "Your content to check"

# Check for policy violations
moderation_result = moderate_text(content)

if moderation_result.get("flagged"):
    # Automatically rewrite problematic content
    safe_content = rewrite_safe(content)
    print(f"Rewritten: {safe_content}")

Batch Processing

For high-volume content generation:

python
from orchestrator import batch_generate

# Multiple prompts
prompts = [
    {"type": "email", "topic": "Product launch"},
    {"type": "social", "topic": "Customer testimonial"},
    {"type": "blog", "topic": "Industry insights"}
]

# Generate all at once
batch_results = batch_generate(prompts, tone="professional")

πŸ”§ API Reference

Core Functions

generate_content_variant(prompt, model_name)

Generate content using specified model with performance monitoring.

Parameters:

  • β€”prompt (str): Input prompt for generation
  • β€”model_name (str): Model identifier (e.g., "flotorch/gflash")

Returns:

  • β€”dict: Contains text, tokens, latency, cost estimate, model name
build_enhanced_prompt(topic, product_name, tone, length, content_type, target_audience, cta)

Construct optimized prompt from user inputs.

Parameters:

  • β€”topic (str): Main subject or theme
  • β€”product_name (str): Product being promoted
  • β€”tone (str): Communication style
  • β€”length (str): Target content length
  • β€”content_type (str): Format type
  • β€”target_audience (str): Intended audience
  • β€”cta (str): Call-to-action text

Returns:

  • β€”str: Formatted prompt optimized for LLM generation

Evaluation Functions

readability_score(text)

Calculate readability metrics using Flesch formulas.

sentiment_score(text)

Perform sentiment analysis using VADER analyzer.

bias_checks(text)

Detect potential bias in content.

rouge_scores(candidate, reference)

Calculate content similarity scores.

Safety Functions

moderate_text(text)

Check content for policy violations using OpenAI moderation.

rewrite_safe(text, style)

Automatically rewrite content to remove violations.

πŸ— Architecture

System Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Streamlit UI  │────│   Orchestrator   │────│  FloTorch API   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                       β”‚                       β”‚
         β”‚              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”             β”‚
         β”‚              β”‚                 β”‚             β”‚
         β–Ό              β–Ό                 β–Ό             β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Evaluator     β”‚ β”‚Guardrailsβ”‚ β”‚ FloTorch     β”‚ β”‚ OpenAI   β”‚
β”‚   (Quality)     β”‚ β”‚(Safety)  β”‚ β”‚ Bridge       β”‚ β”‚ Client   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Component Responsibilities

ComponentPurposeKey Features
app.pyMain UI and workflow orchestrationStreamlit interface, user interactions
orchestrator.pyMulti-model content generationModel routing, performance monitoring
evaluator.pyContent quality analysisReadability, sentiment, bias detection
guardrails.pySafety and complianceModeration, automated rewriting
flotorch_bridge.pyFloTorch platform integrationSDK utilities, configuration helpers
test_flo_stream.pyTesting and validationIntegration tests, performance benchmarks

Data Flow

  1. 1.User Input β†’ Streamlit UI collects requirements
  2. 2.Prompt Construction β†’ Enhanced prompt building with context
  3. 3.Model Selection β†’ Intelligent routing based on requirements
  4. 4.Content Generation β†’ Parallel processing across selected models
  5. 5.Quality Analysis β†’ Comprehensive evaluation of generated content
  6. 6.Safety Checks β†’ Moderation and compliance validation
  7. 7.Results Display β†’ Analytics dashboard with actionable insights

Security Architecture

  • β€”API Key Management: Secure environment variable handling
  • β€”Content Filtering: Multi-layer safety checks
  • β€”Audit Logging: Comprehensive activity tracking
  • β€”Data Protection: No persistent storage of sensitive content
  • β€”Network Security: HTTPS-only communications

πŸš€ Deployment

Local Development

bash
# Development server
streamlit run app.py --server.port 8501

# With debugging
streamlit run app.py --logger.level debug

Production Deployment

Docker Deployment
  1. 1.Create Dockerfile
dockerfile
   FROM python:3.9-slim
   
   WORKDIR /app
   COPY requirements.txt .
   RUN pip install -r requirements.txt
   
   COPY . .
   EXPOSE 8501
   
   CMD ["streamlit", "run", "app.py", "--server.address", "0.0.0.0"]
  1. 1.Build and Run
bash
   docker build -t content-gen-monitoring .
   docker run -p 8501:8501 --env-file .env content-gen-monitoring
Cloud Deployment

Streamlit Cloud:

  1. 1.Connect GitHub repository
  2. 2.Set environment variables in dashboard
  3. 3.Deploy with one click

AWS/GCP/Azure:

  • β€”Use container services (ECS, Cloud Run, Container Instances)
  • β€”Configure load balancing and auto-scaling
  • β€”Set up monitoring and logging

Environment-Specific Configuration

Development
bash
# .env.development
LOG_LEVEL=DEBUG
STREAMLIT_SERVER_PORT=8501
ENABLE_PERFORMANCE_MONITORING=true
Production
bash
# .env.production
LOG_LEVEL=INFO
STREAMLIT_SERVER_PORT=80
ENABLE_CACHING=true
MAX_CONCURRENT_REQUESTS=100

Performance Optimization

  • β€”Caching: Enable Streamlit caching for model initialization
  • β€”Connection Pooling: Reuse API connections
  • β€”Async Processing: Parallel model execution
  • β€”Resource Monitoring: Track memory and CPU usage

🀝 Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

Development Setup

  1. 1.Fork the Repository
  2. 2.Create Feature Branch
bash
   git checkout -b feature/amazing-feature
  1. 1.Install Development Dependencies
bash
   pip install -r requirements-dev.txt
  1. 1.Run Tests
bash
   python -m pytest tests/
  1. 1.Submit Pull Request

Code Standards

  • β€”Python Style: Follow PEP 8 guidelines
  • β€”Documentation: Comprehensive docstrings for all functions
  • β€”Testing: Unit tests for new features
  • β€”Security: No hardcoded credentials or sensitive data

Reporting Issues

Please use our Issue Template when reporting bugs or requesting features.

πŸ” Troubleshooting

Common Issues

"FloTorch API Key Invalid"
bash
# Check environment variables
echo $FLOTORCH_API_KEY

# Test API connectivity
python test_flo_stream.py
"Model Not Available"
  • β€”Verify model ID spelling
  • β€”Check FloTorch dashboard for model availability
  • β€”Ensure sufficient API credits
"Streamlit Won't Start"
bash
# Check port availability
netstat -an | grep 8501

# Try different port
streamlit run app.py --server.port 8502
"Performance Issues"
  • β€”Enable caching in Streamlit settings
  • β€”Reduce number of concurrent model calls
  • β€”Check network connectivity

Debug Mode

Enable comprehensive logging:

bash
# Set environment variable
export LOG_LEVEL=DEBUG

# Run with verbose output
streamlit run app.py --logger.level debug

Getting Help

  • β€”Documentation: Check this README and inline code documentation
  • β€”Issues: Search existing GitHub issues
  • β€”Community: Join our Discord server

πŸ“Š Performance Benchmarks

Typical Performance Metrics

ModelAvg LatencyTokens/secCost per 1K tokens
flotorch/gflash1.2s850$0.002
flotorch/awsnova2.1s480$0.008
gpt-3.5-turbo1.8s650$0.002
gpt-43.2s320$0.030

Scalability Testing

  • β€”Concurrent Users: Tested up to 10 simultaneous users
  • β€”Throughput: 500+ content generations per minute
  • β€”Uptime: 99.9% availability in production environments

πŸ”’ Security & Privacy

Data Handling

  • β€”No Persistent Storage: Generated content is not stored permanently
  • β€”API Key Security: Keys are encrypted and never logged
  • β€”Content Privacy: User inputs are not shared with third parties
  • β€”Audit Trails: All API calls are logged for security monitoring

Compliance

  • β€”GDPR: Full compliance with European data protection regulations
  • β€”SOC 2: Security controls aligned with SOC 2 Type II standards
  • β€”HIPAA: Healthcare-ready deployment options available

Long-term Vision

  • β€”AI-Powered Content Strategy: Intelligent content planning and optimization
  • β€”Real-time Collaboration: Multi-user editing and approval workflows
  • β€”Advanced Analytics: Predictive content performance modeling
  • β€”Integration Ecosystem: Native integrations with major marketing platforms

πŸ™ Acknowledgments

  • β€”FloTorch Team for providing the excellent AI platform
  • β€”Streamlit Community for the amazing web framework
  • β€”Open Source Contributors who made this project possible
  • β€”Beta Testers who provided valuable feedback

Built with ❀️ by the Technical Team

Empowering content creators with AI-driven insights and enterprise-grade reliability.