ai-content-detector / DEPLOYMENT_GUIDE.md
mayankpuvvala's picture
Create DEPLOYMENT_GUIDE.md
4cd3de5 verified

A newer version of the Gradio SDK is available: 6.14.0

Upgrade

πŸš€ Hugging Face Spaces Deployment Guide

Quick Deployment Steps

1. Create a New Space on Hugging Face

  1. Go to Hugging Face Spaces
  2. Click "Create new Space"
  3. Choose settings:
    • Owner: Your username
    • Space name: ai-content-detector (or your preferred name)
    • License: MIT
    • SDK: Gradio
    • Space hardware: CPU (free tier)

2. Upload Files

Upload these files to your Space:

Required Files:

  • app.py - Main Gradio application
  • requirements.txt - Python dependencies
  • README.md - Project documentation

Optional Files:

  • DEPLOYMENT_GUIDE.md - This guide
  • AI_DETECTION_EXPLANATION.md - Technical explanation

3. Automatic Deployment

Once you upload the files, Hugging Face will automatically:

  1. Install dependencies from requirements.txt
  2. Start the Gradio app
  3. Make it available at https://huggingface.co/spaces/YOUR_USERNAME/ai-content-detector

πŸ“ File Structure

ai-content-detector/
β”œβ”€β”€ app.py                 # Main Gradio application
β”œβ”€β”€ requirements.txt       # Python dependencies
β”œβ”€β”€ README.md             # Project documentation
β”œβ”€β”€ DEPLOYMENT_GUIDE.md   # This deployment guide
└── AI_DETECTION_EXPLANATION.md  # Technical details

πŸ”§ Configuration Details

Gradio App Configuration

The app is configured with:

  • Title: "πŸ€– AI Content Detector"
  • Theme: Soft theme for better UX
  • Tabs: Three main analysis methods
  • Interactive Plots: Plotly visualizations

Dependencies

All required packages are listed in requirements.txt:

  • gradio>=4.0.0 - Web app framework
  • requests>=2.31.0 - HTTP requests
  • beautifulsoup4>=4.12.0 - Web scraping
  • numpy>=1.24.0 - Numerical computations
  • pandas>=2.0.0 - Data manipulation
  • plotly>=5.15.0 - Interactive visualizations
  • lxml>=4.9.0 - XML/HTML parser

🌐 Features Available

1. Text Analysis Tab

  • Direct text input
  • Real-time analysis
  • Detailed metrics
  • Interactive charts

2. Website URL Analysis Tab

  • Enter any website URL
  • Automatic content scraping
  • AI detection analysis
  • Visual results

3. News Site Analysis Tab

  • Pre-configured news sites:
    • BBC News
    • Reuters
    • The Guardian
    • CNN
    • TechCrunch
  • One-click analysis
  • Comparative results

πŸ“Š Analysis Capabilities

Detection Methods

  1. Perplexity Analysis - Text predictability
  2. Burstiness Calculation - Sentence variation
  3. Vocabulary Diversity - Word variety
  4. Repetitive Patterns - AI phrase detection
  5. Sentence Structure - Length and complexity
  6. Readability Scores - Flesch metrics
  7. Semantic Coherence - Topic consistency

Visualizations

  • Radar Charts - Individual scores
  • Bar Charts - Metric comparisons
  • Color-coded Results - Probability indicators
  • Interactive Elements - Hover details

πŸ” Usage Examples

Example 1: Analyze Text Input

  1. Go to "πŸ“ Text Analysis" tab
  2. Paste any text
  3. Click "Analyze Text"
  4. View AI probability and detailed metrics

Example 2: Analyze a Website

  1. Go to "🌐 Website Analysis" tab
  2. Enter: https://www.bbc.com/news
  3. Click "Analyze Website"
  4. View scraped content analysis

Example 3: News Site Comparison

  1. Go to "πŸ“° News Site Analysis" tab
  2. Choose "BBC News"
  3. Click "Analyze News Site"
  4. Repeat with other sites for comparison

πŸ› οΈ Customization Options

Adding New News Sites

Edit the news_sites dictionary in app.py:

news_sites = {
    "BBC News": "https://www.bbc.com/news",
    "Reuters": "https://www.reuters.com",
    "Your Site": "https://yoursite.com"
}

Adjusting Detection Weights

Modify the weights in the calculate_ai_probability method:

weights = {
    'perplexity_score': 0.2,      # 20%
    'burstiness_score': 0.15,     # 15%
    'vocab_diversity_score': 0.15, # 15%
    'repetitive_patterns_score': 0.2, # 20%
    'sentence_structure_score': 0.1,  # 10%
    'readability_score': 0.1,     # 10%
    'semantic_coherence_score': 0.1   # 10%
}

Adding New Detection Methods

  1. Create new analysis method in AIContentDetector class
  2. Add to calculate_ai_probability method
  3. Update weights dictionary
  4. Add visualization in create_visualizations function

πŸ”§ Troubleshooting

Common Issues

1. Deployment Fails

  • Check requirements.txt format
  • Ensure all dependencies are compatible
  • Verify Python version compatibility

2. Web Scraping Errors

  • Some sites block automated requests
  • Add more user agents to headers
  • Implement rate limiting

3. Memory Issues

  • Reduce text processing size
  • Optimize visualization generation
  • Use smaller data samples

4. Performance Issues

  • Cache analysis results
  • Implement lazy loading
  • Optimize algorithm efficiency

Debug Mode

Add debug information to the app:

# Add debug output
print(f"Debug: Processing text of length {len(text)}")

πŸ“ˆ Monitoring and Analytics

Hugging Face Analytics

  • View Space usage statistics
  • Monitor deployment status
  • Check error logs

Custom Analytics

Add analytics tracking:

# Track usage
import time
start_time = time.time()
# ... analysis code ...
processing_time = time.time() - start_time

πŸ”„ Updates and Maintenance

Regular Updates

  1. Dependencies: Update requirements.txt regularly
  2. Detection Methods: Improve algorithms based on feedback
  3. News Sites: Add new sites and remove broken ones
  4. UI/UX: Enhance user interface

Version Control

  • Use Git for version control
  • Tag releases with version numbers
  • Maintain changelog

🌟 Advanced Features

Potential Enhancements

  1. Machine Learning Models: Integrate BERT-based classifiers
  2. API Endpoints: Create REST API for programmatic access
  3. Batch Processing: Analyze multiple URLs at once
  4. Custom Models: Train on specific domains
  5. Real-time Detection: Live content analysis
  6. Export Options: PDF reports, CSV data
  7. User Accounts: Save analysis history
  8. Collaborative Features: Share and compare results

πŸ“ž Support

Getting Help

  • Documentation: Check README.md
  • Issues: Report on Hugging Face or GitHub
  • Community: Join AI detection discussions

Contributing

  • Fork the repository
  • Create feature branches
  • Submit pull requests
  • Follow coding standards

🎯 Success Metrics

Deployment Success Indicators

  • βœ… App loads without errors
  • βœ… All features work correctly
  • βœ… Visualizations render properly
  • βœ… Web scraping functions
  • βœ… Analysis produces results

Performance Metrics

  • Load Time: < 5 seconds
  • Analysis Speed: < 10 seconds for typical text
  • Accuracy: > 80% on test cases
  • Uptime: > 99% availability

πŸ”„ Gradio vs Streamlit

Why Gradio for Hugging Face?

  • Better Integration: Native Hugging Face support
  • Faster Deployment: Optimized for Spaces
  • Interactive Components: Better for ML/AI apps
  • Community Support: Strong HF community

Key Differences

  • Interface: Tabs vs sidebar navigation
  • Visualizations: Plotly integration vs native charts
  • Styling: Theme-based vs component-based
  • Deployment: Direct HF integration vs manual setup

Ready to deploy? Follow the steps above and your AI Content Detector will be live on Hugging Face Spaces! πŸš€