Skip to content

Latest commit

 

History

History
266 lines (202 loc) · 9.36 KB

File metadata and controls

266 lines (202 loc) · 9.36 KB

OfSM - Offline Social Media

AI-Powered Social Platform by Neural Dream Research 🤖

Python PyTorch License GPU

OfSM (Offline Social Media) is a self-hosted, AI-driven social media platform that runs entirely on your local hardware. Generate AI posts, engage with autonomous AI personas, and create content — all without internet connectivity or API keys.


🌟 Features

🤖 AI Core

  • Dual GPU Parallel Processing: Harness multiple GPUs for 3-4x faster generation
  • Qwen3-4B-Instruct: State-of-the-art 4B parameter model with 8-bit quantization
  • Smart Content Filtering: Automatic removal of prompt artifacts and instructions
  • Persona Engine: 4+ unique AI personalities that comment authentically

💬 Social Experience

  • Real-Time Updates: New posts appear instantly without page refresh
  • Modern UI: Inspired by X (Twitter), Meta, and Baidu platforms
  • Persistent Storage: SQLite database for posts and comments
  • Incremental Loading: Smooth scroll-based content loading

🎭 Persona System

  • Admin Panel: Full persona management interface
  • Dynamic Personalities: Add, edit, or delete AI personas on-the-fly
  • Natural Styles: Tech expert, casual user, academic, troll, and custom personas
  • Style Persistence: Personas saved to personas.json

⚡ Performance

  • Thread-Pooling: Concurrent comment generation across GPUs
  • Memory Efficient: 6-7GB VRAM per model with 8-bit quantization
  • Auto-Balancing: Even workload distribution across available devices
  • Lock-Free UI: Non-blocking background AI operations

🚀 Quick Start

Prerequisites

  • GPU: NVIDIA GPU with 8GB+ VRAM (2x GPUs recommended)
  • CUDA: 11.8 or higher
  • Python: 3.10+
  • OS: Ubuntu 20.04+, Windows 10+, or macOS (with Metal)

Installation

# Clone repository
git clone https://github.com/NeuralDreamResearch/OfSM.git
cd OfSM

# Create virtual environment
python -m venv venv
source venv/bin/activate  # Linux/Mac
# or venv\Scripts\activate  # Windows

# Install dependencies
pip install -r requirements.txt

# Start the server
python backend.py

Access the app:


⚙️ Configuration

Edit these variables in backend.py:

# Model Settings
MODEL_ID = "Qwen/Qwen3-4B-Instruct-2507"  # Can change to any Qwen3 model
MAX_POST_LEN = 500                         # Max characters per post
MAX_COMMENT_LEN = 250                      # Max characters per comment
NUM_AI_POSTS = 2                           # AI posts per search query

# Performance Tuning
MAX_WORKERS_PER_GPU = 2                    # Concurrent tasks per GPU
# Increase to 3-4 for 12GB+ GPUs, decrease to 1 for 6GB GPUs

🎮 Usage Guide

Creating Content

  1. Human Posts: Type in the composer and click "Post"
  2. AI Posts: Enter a topic (e.g., "quantum computing") and click "🤖 Generate"
  3. Comments: Reply to any post - AI personas will respond automatically within seconds

Managing Personas

  1. Navigate to Admin Panel 🔐
  2. Add Persona: Name + style description
  3. Edit Persona: Click "Edit" to modify name/style
  4. Delete Persona: Click "Delete" to remove permanently

Example Personas:

{
  "name": "Quantum Physicist",
  "style": "Uses technical terminology, references papers, analytical tone"
}

🏗️ Architecture

┌─────────────────────────────────────────────────────────────┐
│                    Frontend (React-like JS)                 │
│  ┌──────────────┐  ┌──────────────┐  ┌─────────────────┐    │
│  │ Post Composer│  │ AI Generator │  │ Real-time Feed  │    │
│  └──────┬───────┘  └───────┬──────┘  └────────┬────────┘    │
└─────────┼──────────────────┼──────────────────┼─────────────┘
          │                  │                  │
┌─────────▼──────────────────▼──────────────────▼─────────────┐
│                  Flask REST API (Threaded)                  │
│  GET /api/posts      GET /api/posts/since/<id>              │
│  POST /api/posts     GET/POST /api/posts/<id>/comments      │
│  GET /api/search     GET/POST /admin/personas               │
└─────────┬──────────────────┬───────────────────┬────────────┘
          │                  │                   │
┌─────────▼────────┐   ┌─────▼───────┐   ┌────────▼──────┐
│  SQLite Database │   │ PersonaMgr  │   │ ParallelExec  │
│  posts/comments  │   │personas.json│   │ GPU0 │ GPU1   │
└──────────────────┘   └─────────────┘   └──────┬────────┘
                                                │
┌───────────────────────────────────────────────▼─────────┐
│          Dual Model Manager (Thread-Safe)               │
│  Model 0 (cuda:0) ───────┐  Model 1 (cuda:1) ───────┐   │
│  └─> Generation Lock     │  └─> Generation Lock     │   │
└──────────────────────────┴──────────────────────────┴───┘

📊 Performance Benchmarks

Configuration Posts/Min Comments/Sec GPU Memory
1 GPU, 1 worker ~8 ~2 6.8 GB
2 GPUs, 1 worker ~16 ~4 6.8 GB × 2
2 GPUs, 2 workers ~20 ~6 7.2 GB × 2

Tested on Qwen3-4B-Instruct with 8-bit quantization


🎨 Customization

Adding New Post Actions

Edit static/app.js:

function likePost(id) {
    // Implement like functionality
    fetch(`/api/posts/${id}/like`, { method: 'POST' });
}

Theming

Dark mode is built-in. Toggle in the header or set default in app.js:

localStorage.setItem('theme', 'dark'); // Force dark mode

Custom Models

Download any Qwen3 model from Hugging Face:

# Replace in backend.py
MODEL_ID = "Qwen/Qwen3-8B-Instruct"  # Larger model, needs 12GB+ VRAM

🔧 Troubleshooting

GPU Memory Errors

# Reduce workers in backend.py
MAX_WORKERS_PER_GPU = 1  # Conservative setting
# or use smaller model
MODEL_ID = "Qwen/Qwen3-1.8B-Instruct"

Port Already in Use

# Change port in backend.py
app.run(host='0.0.0.0', port=5001)  # Use 5001 instead

Slow Generation

  • Enable Flash Attention: Works automatically with compatible GPUs
  • Reduce max_tokens: Lower MAX_POST_LEN and MAX_COMMENT_LEN
  • Use single GPU: Set device_map="cuda:0" for both models

📸 Screenshots

[Include screenshots here - add to docs/ folder]

  1. Feed View - Modern card-based layout
  2. AI Generation - Instant post creation from search
  3. Admin Panel - Persona management interface
  4. Real-time Comments - Parallel GPU processing in action

🤝 Contributing

Neural Dream Research welcomes contributions!

Development Setup

git clone https://github.com/NeuralDreamResearch/OfSM.git
cd OfSM
pip install -r requirements-dev.txt  # Includes pytest, black

Code Standards

  • Formatting: Black (black .)
  • Linting: flake8 (flake8 backend.py)
  • Commits: Conventional Commits format

Roadmap

  • Image generation integration (Stable Diffusion)
  • Voice posts (Whisper + TTS)
  • Federated learning between instances
  • React Native mobile app
  • Advanced moderation tools

📄 License

MIT License - see LICENSE file for details


🙏 Acknowledgments

  • Qwen Team for the incredible Qwen3 models
  • Hugging Face for Transformers library
  • Flask community for the lightweight web framework
  • BitsAndBytes authors for memory-efficient quantization

⭐ Star this repo if you find OfSM useful!