{"id":36956790,"url":"https://github.com/KOKOSde/localmod","last_synced_at":"2026-01-20T15:00:37.894Z","repository":{"id":330652493,"uuid":"1123476895","full_name":"KOKOSde/localmod","owner":"KOKOSde","description":"Self-hosted content moderation API that outperforms Amazon Comprehend. 100% offline, your data never leaves your server. Text + Image moderation.","archived":false,"fork":false,"pushed_at":"2026-01-01T09:03:52.000Z","size":186,"stargazers_count":9,"open_issues_count":7,"forks_count":3,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-06T01:58:44.119Z","etag":null,"topics":["content-moderation","docker","fastapi","image-moderation","llm-security","machine-learning","nsfw-detection","offline-first","pii-detection","privacy","prompt-injection","self-hosted","spam-detection","toxicity-detection"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KOKOSde.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-12-27T00:37:26.000Z","updated_at":"2026-01-05T23:26:04.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/KOKOSde/localmod","commit_stats":null,"previous_names":["kokosde/localmod"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/KOKOSde/localmod","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KOKOSde%2Flocalmod","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KOKOSde%2Flocalmod/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KOKOSde%2Flocalmod/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KOKOSde%2Flocalmod/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KOKOSde","download_url":"https://codeload.github.com/KOKOSde/localmod/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KOKOSde%2Flocalmod/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28605915,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T14:45:23.139Z","status":"ssl_error","status_checked_at":"2026-01-20T14:44:16.929Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["content-moderation","docker","fastapi","image-moderation","llm-security","machine-learning","nsfw-detection","offline-first","pii-detection","privacy","prompt-injection","self-hosted","spam-detection","toxicity-detection"],"created_at":"2026-01-13T15:00:23.173Z","updated_at":"2026-01-20T15:00:37.872Z","avatar_url":"https://github.com/KOKOSde.png","language":"Python","funding_links":[],"categories":["Defense \u0026 Security Controls"],"sub_categories":["Input/Output Guardrails"],"readme":"# LocalMod\n\n[![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Tests](https://img.shields.io/badge/tests-109%20passed-brightgreen.svg)]()\n\n**Fully offline content moderation API** — Free, self-hosted, and private. Your data never leaves your infrastructure.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"docs/architecture.svg\" alt=\"LocalMod Architecture\" width=\"800\"/\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"docs/examples.svg\" alt=\"LocalMod Examples\" width=\"900\"/\u003e\n\u003c/p\u003e\n\n---\n\n## Benchmark Results\n\n### Toxicity Detection\n\nBenchmarked using [CHI 2025 \"Lost in Moderation\"](https://arxiv.org/html/2503.01623) methodology (HateXplain, Civil Comments, SBIC datasets):\n\n| System | Balanced Accuracy | Type |\n|--------|------------------|------|\n| OpenAI Moderation API | 0.83 | Commercial |\n| Azure Content Moderator | 0.81 | Commercial |\n| **LocalMod** | **0.75** ⭐ | Open Source |\n| Amazon Comprehend | 0.74 | Commercial |\n| Perspective API | 0.62 | Commercial |\n\n### Spam Detection\n\n| System | Balanced Accuracy | Dataset |\n|--------|------------------|---------|\n| **LocalMod** | **0.998** | [UCI SMS Spam Collection](https://archive.ics.uci.edu/ml/datasets/sms+spam+collection) |\n\n---\n\n## Installation\n\n```bash\ngit clone https://github.com/KOKOSde/localmod.git\ncd localmod\npip install -e .\n\n# Download ML models (~3.5GB - includes image model)\npython scripts/download_models.py\n```\n\n## Quick Start\n\n```bash\n# Run demo\npython examples/demo.py\n```\n\n### Python Usage\n\n```python\nfrom localmod import SafetyPipeline\n\npipeline = SafetyPipeline()\nreport = pipeline.analyze(\"Check this text for safety issues\")\n\nprint(f\"Flagged: {report.flagged}\")\nprint(f\"Severity: {report.severity}\")\n```\n\n### API Server\n\n```bash\nlocalmod serve --port 8000\n\n# Test\ncurl -X POST http://localhost:8000/analyze \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"text\": \"Hello world\", \"classifiers\": [\"toxicity\", \"pii\"]}'\n```\n\n### Docker\n\n```bash\ndocker build -f docker/Dockerfile -t localmod:latest .\ndocker run -p 8000:8000 localmod:latest\n```\n\n### Discord Bot 🆕\n\n```bash\n# Install Discord dependency\npip install -e \".[discord]\"\n\n# Set your bot token\nexport DISCORD_BOT_TOKEN=your_token_here\n\n# Run the bot\npython examples/discord_bot.py\n```\n\nFeatures: Real-time text \u0026 image moderation, auto-delete, timeout, logging.\n\n---\n\n## Classifiers\n\n### Text Moderation\n\n| Classifier | Detects | Model |\n|------------|---------|-------|\n| **PII** | Emails, phones, SSNs, credit cards | Regex + Validation |\n| **Toxicity** | Hate speech, harassment, threats | Weighted Ensemble (4 models) |\n| **Prompt Injection** | LLM jailbreaks, instruction override | DeBERTa |\n| **Spam** | Promotional content, scams | RoBERTa |\n| **NSFW Text** | Sexual content, adult themes | NSFW Classifier |\n\n### Image Moderation 🆕\n\n| Classifier | Detects | Model |\n|------------|---------|-------|\n| **NSFW Image** | Explicit/adult images | [Falconsai/nsfw_image_detection](https://huggingface.co/Falconsai/nsfw_image_detection) (ViT) |\n\n*71M+ downloads on HuggingFace • Apache 2.0 license*\n\n### Toxicity Ensemble\n\n| Model | Weight | Purpose |\n|-------|--------|---------|\n| [`unitary/toxic-bert`](https://huggingface.co/unitary/toxic-bert) | 50% | Multi-label toxicity |\n| [`Hate-speech-CNERG/dehatebert-mono-english`](https://huggingface.co/Hate-speech-CNERG/dehatebert-mono-english) | 20% | Hate speech |\n| [`s-nlp/roberta_toxicity_classifier`](https://huggingface.co/s-nlp/roberta_toxicity_classifier) | 15% | Toxicity |\n| [`facebook/roberta-hate-speech-dynabench-r4-target`](https://huggingface.co/facebook/roberta-hate-speech-dynabench-r4-target) | 15% | Adversarial robustness |\n\n---\n\n## API Endpoints\n\n### Text Moderation\n\n| Endpoint | Method | Description |\n|----------|--------|-------------|\n| `/analyze` | POST | Analyze single text |\n| `/analyze/batch` | POST | Analyze multiple texts |\n| `/redact` | POST | Redact PII from text |\n\n### Image Moderation 🆕\n\n| Endpoint | Method | Description |\n|----------|--------|-------------|\n| `/analyze/image` | POST | Analyze image from URL |\n| `/analyze/image/upload` | POST | Analyze uploaded image file |\n\n### System\n\n| Endpoint | Method | Description |\n|----------|--------|-------------|\n| `/health` | GET | Health check |\n| `/classifiers` | GET | List text classifiers |\n| `/classifiers/image` | GET | List image classifiers |\n\n### Example: Text Analysis\n\n```json\nPOST /analyze\n{\n  \"text\": \"You are an idiot!\",\n  \"classifiers\": [\"toxicity\"]\n}\n\nResponse:\n{\n  \"flagged\": true,\n  \"results\": [{\"classifier\": \"toxicity\", \"flagged\": true, \"confidence\": 0.72, \"severity\": \"high\"}],\n  \"processing_time_ms\": 85.3\n}\n```\n\n### Example: Image Analysis 🆕\n\n```json\nPOST /analyze/image\n{\n  \"image_url\": \"https://example.com/image.jpg\"\n}\n\nResponse:\n{\n  \"flagged\": false,\n  \"results\": [{\"classifier\": \"nsfw_image\", \"flagged\": false, \"confidence\": 0.02, \"severity\": \"none\"}],\n  \"processing_time_ms\": 120.5\n}\n```\n\n---\n\n## Offline Mode\n\n```bash\n# Download models once\npython scripts/download_models.py --model-dir /path/to/models\n\n# Run offline\nexport LOCALMOD_MODEL_DIR=/path/to/models\nexport LOCALMOD_OFFLINE=1\nlocalmod serve\n```\n\nDocker:\n```bash\ndocker run -p 8000:8000 \\\n  -v /path/to/models:/models \\\n  -e LOCALMOD_MODEL_DIR=/models \\\n  -e LOCALMOD_OFFLINE=1 \\\n  localmod:latest\n```\n\n---\n\n## Configuration\n\n| Variable | Default | Description |\n|----------|---------|-------------|\n| `LOCALMOD_MODEL_DIR` | `~/.cache/localmod/models` | Model directory |\n| `LOCALMOD_OFFLINE` | `false` | Force offline mode |\n| `LOCALMOD_DEVICE` | `auto` | `cpu`, `cuda`, or `auto` |\n\n---\n\n## Performance\n\n| Classifier | CPU Latency | GPU Latency | Memory |\n|------------|-------------|-------------|--------|\n| PII (regex) | \u003c1ms | \u003c1ms | Minimal |\n| Single ML model (text) | ~50-200ms | ~10-30ms | ~1GB |\n| Toxicity ensemble (4 models) | ~200-500ms | ~30-80ms | ~3GB |\n| NSFW Image (ViT) | ~100-300ms | ~20-50ms | ~500MB |\n\n*Performance varies by hardware. GPU recommended for production workloads.*\n\n---\n\n## Development\n\n```bash\npip install -e \".[dev]\"\npytest tests/ -v\n```\n\n---\n\n## License\n\nMIT License — see [LICENSE](LICENSE).\n\n## Acknowledgments\n\nModels from [HuggingFace](https://huggingface.co/). Benchmark methodology from CHI 2025 \"Lost in Moderation\" (Hartmann et al.).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKOKOSde%2Flocalmod","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKOKOSde%2Flocalmod","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKOKOSde%2Flocalmod/lists"}