Skip to content

dbish/x-vui

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

X Visual Understanding Using Moondream.ai - Image Tweet Deletion Chrome Extension

A Chrome extension that automatically deletes entire tweets from your timeline based on image content analysis using Python Flask service with moondream.ai AI-powered filtering and configurable analysis queries.

Never look at a screenshotted tweet that gets around your mute filter again.

🚀 Features

  • Smart Tweet Deletion: Uses Moondream AI to analyze tweet images and delete entire tweets containing inappropriate content
  • 🆕 Configurable Queries: Choose from predefined analysis queries or create your own custom prompts
  • 🆕 Query Dropdown Interface: Easy-to-use popup interface for selecting analysis types
  • 🆕 Quote Tweet Processing: Also analyzes images in quote tweets (one layer deep)
  • Timeline-Only Processing: Only runs on Twitter timelines, not individual tweet pages
  • Real-time Processing: Processes images as they load on Twitter/X and removes problematic tweets instantly
  • Selective Filtering: Only processes tweet media images, not profile pictures or UI elements
  • Console Logging: Logs deleted tweet links to browser console for reference
  • Smooth Animations: Tweets fade out smoothly when deleted
  • Fallback System: Falls back to random decisions if API is unavailable
  • Easy Toggle: Enable/disable via Chrome extension popup
  • Tweet Restoration: Can restore deleted tweets when extension is disabled

🎯 Query Types

The extension now supports multiple analysis types:

Predefined Queries

  • Twitter Screenshot Detection: Identifies Twitter/X screenshots
  • Inappropriate Content: Flags adult or inappropriate content
  • Violence Detection: Detects violent or disturbing content
  • Spam/Promotional: Identifies spam or promotional content

Custom Queries

  • Custom Query: Write your own analysis prompt for specific filtering needs

📁 Project Structure

cluely-b-gone/
├── backend/
│   ├── image_processor_service.py  # Flask service with configurable queries
│   ├── test_queries.py            # Test script for query system
│   ├── test_logging.py            # Test script for logging functionality
│   ├── config.py                  # Configuration file
│   └── requirements.txt           # Python dependencies
├── chrome_extension/
│   ├── manifest.json              # Chrome extension manifest
│   ├── content.js                 # Main content script (handles tweet deletion)
│   ├── popup.html                 # Extension popup interface (with query dropdown)
│   ├── popup.js                   # Popup functionality (query management)
│   ├── styles.css                 # Extension styling
│   ├── test.html                  # Test page for extension functionality
│   ├── icon.svg                   # Extension icon (SVG format)
│   ├── icon16.png                 # Extension icon (16x16)
│   ├── icon48.png                 # Extension icon (48x48)
│   └── icon128.png                # Extension icon (128x128)
├── venv/                          # Python virtual environment
├── .gitignore                     # Git ignore rules
└── README.md                      # This file

🛠️ Setup Instructions

1. Get Moondream API Key

  1. Visit Moondream AI and sign up for an account
  2. Get your API key from the dashboard
  3. Keep this key secure - you'll need it for the setup

2. Clone and Setup the Project

First, set up the Python environment and install dependencies:

# Create and activate virtual environment
python3 -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Navigate to backend directory and install dependencies
cd backend
pip install -r requirements.txt

# Set up environment variables
cp .env.example .env
# Edit .env and add your Moondream API key:
# MOONDREAM_API_KEY=your_actual_api_key_here

# Test the query system (optional)
python3 test_queries.py

# Run the service
python3 image_processor_service.py

The service will start on http://localhost:5002

Important: Make sure to set your MOONDREAM_API_KEY environment variable. Without it, the service will fall back to random decisions.

3. Chrome Extension Setup

  1. Open Chrome and navigate to chrome://extensions/
  2. Enable "Developer mode" (toggle in top right)
  3. Click "Load unpacked"
  4. Select the chrome_extension directory
  5. The extension should now appear in your extensions list

4. Usage

  1. Start the Flask service first (see step 2 above)
  2. Navigate to Twitter/X (twitter.com or x.com) timeline
  3. Click the extension icon in your toolbar
  4. Select your desired query type from the dropdown:
    • Choose from predefined queries (Twitter Screenshots, Inappropriate Content, etc.)
    • Or select "Custom Query" to write your own analysis prompt
  5. Toggle processing on/off using the switch
  6. Tweets with problematic images will be deleted automatically as they load
  7. Check the browser console (F12) for deleted tweet links and processing logs

🎮 Using the Query Interface

Selecting Predefined Queries

  1. Click the extension icon
  2. Click the "Analysis Query" dropdown button
  3. Select from available options:
    • Twitter Screenshot Detection
    • Inappropriate Content
    • Violence Detection
    • Spam/Promotional

Creating Custom Queries

  1. Click the extension icon
  2. Select "Custom Query" from the dropdown
  3. Enter your custom analysis prompt in the text area
  4. Your custom query will be sent to the AI for analysis

Example Custom Queries

"Does this image contain any text? Answer with just 'yes' or 'no'."
"Is this image a meme? Answer with just 'yes' or 'no'."
"Does this image show food? Answer with just 'yes' or 'no'."
"Is this image politically related? Answer with just 'yes' or 'no'."

🔧 API Endpoints

The Flask service provides several endpoints with configurable query support:

  • POST /analyze - Analyze a single image with custom query
  • POST /analyze-batch - Analyze multiple images with custom queries
  • GET /stats - Get processing statistics
  • GET /health - Health check
  • GET /config - Get current configuration

Example API Usage with Custom Queries

# Analyze an image with custom query
curl -X POST http://localhost:5002/analyze \
  -H "Content-Type: application/json" \
  -d '{
    "image_url": "https://pbs.twimg.com/media/example.jpg",
    "query": "Does this image contain inappropriate content? Answer with just yes or no.",
    "query_type": "inappropriate_content"
  }'

# Analyze with default query
curl -X POST http://localhost:5002/analyze \
  -H "Content-Type: application/json" \
  -d '{"image_url": "https://pbs.twimg.com/media/example.jpg"}'

🎯 How It Works

The extension identifies tweet media images (including in quote tweets) and sends them to a local Flask service with the selected analysis query. The service uses Moondream AI to analyze each image based on your chosen criteria. Entire tweets containing problematic images are deleted from the timeline.

Processing Flow

  1. Image Detection: Extension finds images in tweets and quote tweets
  2. Query Selection: Uses the query type selected in the popup
  3. AI Analysis: Moondream AI analyzes the image with your custom prompt
  4. Decision Making: Based on AI response, tweet is kept or deleted
  5. Visual Feedback: Processing indicators show analysis status

🔄 Current Processing Logic

The service now uses configurable Moondream AI queries:

  1. Image Download: Service downloads the image from Twitter's CDN
  2. Custom Query Analysis: AI model analyzes the image with your selected query
  3. Decision Making:
    • If AI responds "yes" to blocking query → Entire tweet is deleted
    • If AI responds "no" → Tweet remains visible
    • If API fails → Falls back to random decision
  4. High Confidence: API-based decisions have 95% confidence vs 60-95% for random fallbacks
  5. Console Logging: Deleted tweet links and query types are logged to browser console

📊 Visual Indicators & Console Output

  • 🔍 Analyzing [query_type]... - Image is being processed with selected query
  • 🗑️ DELETED TWEET --> [tweet_link] - Tweet was deleted (logged to console)
  • Blocked image was in: [main tweet/quote tweet] - Shows where the problematic image was found
  • ✅ Allowed - Tweet was allowed to remain
  • Smooth fade-out animation when tweets are deleted

🛠️ Development

Adding New Predefined Queries

Edit the queries object in chrome_extension/popup.js:

this.queries = {
  'your_query_type': {
    title: 'Your Query Name',
    desc: 'Description of what this query does',
    prompt: 'Your analysis question for the AI'
  }
};

Modifying the Analysis Logic

Edit the analyze_with_moondream method in backend/image_processor_service.py:

async def analyze_with_moondream(self, image, custom_query=None):
    # Use custom_query parameter for dynamic prompts
    question = custom_query or "Default analysis question"
    # ... rest of analysis logic

Adding New Features

  • Popup Interface: Modify chrome_extension/popup.html and popup.js
  • Content Logic: Edit chrome_extension/content.js
  • Service Logic: Modify backend/image_processor_service.py
  • Styling: Edit chrome_extension/styles.css
  • Testing: Use chrome_extension/test.html for extension testing

🧪 Testing

Use the included test scripts to verify functionality:

# Navigate to backend directory
cd backend

# Test all query types
python3 test_queries.py

# Test logging functionality
python3 test_logging.py

# Test specific functionality
curl -X POST http://localhost:5002/analyze \
  -H "Content-Type: application/json" \
  -d '{"image_url": "test_url", "query": "test query", "query_type": "test"}'

For extension testing, open chrome_extension/test.html in your browser.

🐛 Troubleshooting

Common Issues

  1. Extension not working: Check that Flask service is running on port 5002
  2. Custom queries not working: Ensure the query is properly formatted for the AI
  3. CORS errors: Flask-CORS is included to handle cross-origin requests
  4. Tweets not being deleted: Check browser console for error messages and query responses
  5. Service errors: Check Flask service logs in terminal
  6. Query not updating: Make sure to select a new query type from the dropdown

Debug Mode

  • Browser Console: F12 → Console tab for extension logs, query types, and deleted tweet links
  • Flask Logs: Check terminal running the Flask service for query processing
  • Extension Popup: Click extension icon to see current query selection

📈 Statistics

The service tracks:

  • Total images processed
  • Tweets deleted
  • Tweets allowed
  • Query types used
  • API errors

Access via the /stats endpoint or browser console logs.

🔒 Security Notes

  • Service runs on localhost only (not exposed externally)
  • No image data is stored permanently
  • Custom queries are processed locally
  • CORS enabled for browser extension access
  • All processing happens locally
  • Deleted tweets can be restored by disabling the extension

🚀 Future Enhancements

  • ✅ Configurable analysis queries
  • ✅ Quote tweet image processing
  • ✅ Timeline-only processing
  • Query templates and sharing
  • Batch query processing
  • Query performance analytics
  • Whitelist/blacklist functionality
  • Export deleted tweet logs with query information
  • Advanced analytics dashboard with query breakdowns

📝 License

This project is for educational/development purposes. Modify as needed for your use case.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published