Spaces:
Sleeping
Sleeping
A newer version of the Gradio SDK is available: 6.14.0
π Hugging Face Spaces Deployment Guide
Quick Deployment Steps
1. Create a New Space on Hugging Face
- Go to Hugging Face Spaces
- Click "Create new Space"
- 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 applicationrequirements.txt- Python dependenciesREADME.md- Project documentation
Optional Files:
DEPLOYMENT_GUIDE.md- This guideAI_DETECTION_EXPLANATION.md- Technical explanation
3. Automatic Deployment
Once you upload the files, Hugging Face will automatically:
- Install dependencies from
requirements.txt - Start the Gradio app
- 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 frameworkrequests>=2.31.0- HTTP requestsbeautifulsoup4>=4.12.0- Web scrapingnumpy>=1.24.0- Numerical computationspandas>=2.0.0- Data manipulationplotly>=5.15.0- Interactive visualizationslxml>=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
- Perplexity Analysis - Text predictability
- Burstiness Calculation - Sentence variation
- Vocabulary Diversity - Word variety
- Repetitive Patterns - AI phrase detection
- Sentence Structure - Length and complexity
- Readability Scores - Flesch metrics
- 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
- Go to "π Text Analysis" tab
- Paste any text
- Click "Analyze Text"
- View AI probability and detailed metrics
Example 2: Analyze a Website
- Go to "π Website Analysis" tab
- Enter:
https://www.bbc.com/news - Click "Analyze Website"
- View scraped content analysis
Example 3: News Site Comparison
- Go to "π° News Site Analysis" tab
- Choose "BBC News"
- Click "Analyze News Site"
- 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
- Create new analysis method in
AIContentDetectorclass - Add to
calculate_ai_probabilitymethod - Update weights dictionary
- Add visualization in
create_visualizationsfunction
π§ Troubleshooting
Common Issues
1. Deployment Fails
- Check
requirements.txtformat - 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
- Dependencies: Update
requirements.txtregularly - Detection Methods: Improve algorithms based on feedback
- News Sites: Add new sites and remove broken ones
- UI/UX: Enhance user interface
Version Control
- Use Git for version control
- Tag releases with version numbers
- Maintain changelog
π Advanced Features
Potential Enhancements
- Machine Learning Models: Integrate BERT-based classifiers
- API Endpoints: Create REST API for programmatic access
- Batch Processing: Analyze multiple URLs at once
- Custom Models: Train on specific domains
- Real-time Detection: Live content analysis
- Export Options: PDF reports, CSV data
- User Accounts: Save analysis history
- 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! π