Skip to main content

🪄 magic-eraser

People who don't know what to sell, sell advertisements.

Rule-based web ad/clutter eraser, learned from a continuously-growing, crowd-labeled dataset of real page elements. No LLM needed at inference time — the rules are distilled from labels that an LLM (or a human) produced once.

pip install magic-eraser
from magic_eraser import is_ad, css, detect_ads, AdEraser

is_ad({"cls": "ad-slot leaderboard", "eid": "div-gpt-ad-1", "w": 728, "h": 90})
# True

css("www.washingtonpost.com")
# '[class*="ad-slot"],...{display:none !important;height:0 !important;...}'

eraser = AdEraser("example.com")
eraser.detect([{"id": 0, "cls": "advert", "w": 300, "h": 250, "iframe": True},
               {"id": 1, "cls": "article-body", "w": 680, "h": 1200}])
# [0]

How it works

  1. A browser (e.g. Melon) collects candidate page elements and, on first visit to a site, asks an LLM which are ads.
  2. Each verdict is appended to data/ad_dataset.jsonl as labeled training data and pushed here.
  3. scripts/build_rules.py re-derives high-precision class/id token rules + per-domain CSS selectors into magic_eraser/rules.json.
  4. magic-eraser then blocks ads with zero LLM calls — and gets better every time the dataset grows.

The dataset

data/ad_dataset.jsonl — one JSON object per labeled page element:

field meaning
host, url, ts where/when it was seen
tag element tag (DIV, IFRAME, …)
cls, eid class string, element id
w, h rendered size (px)
iframe is it an iframe
txt short visible-text snippet
is_ad label — ad/clutter (true) or content (false)

Load it with HuggingFace datasets:

from datasets import load_dataset

ds = load_dataset(
    "json",
    data_files="https://raw.githubusercontent.com/alvations/magic-eraser/main/data/ad_dataset.jsonl",
    split="train",
)
ds[0]  # {'host': ..., 'cls': ..., 'is_ad': True, ...}

Train a model to replace the rules

pip install "magic-eraser[train]"
python scripts/build_rules.py     # regenerate rule-based detector from data

The labeled dataset is designed to train a small local classifier (features → is_ad) that can replace both the rules and the LLM entirely.

License

MIT.

Release files for magic-eraser 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for magic-eraser 0.1.0
File Size Uploaded
magic_eraser-0.1.0.tar.gz 8.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for magic-eraser 0.1.0
File Interpreter ABI Platform
magic_eraser-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.7 kB

Release files / magic_eraser-0.1.0.tar.gz

Download URL magic_eraser-0.1.0.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a115663688ec112922ea08387f2e080021ddf507ae9611f13e6eb25ccff776d0
BLAKE2b-256 checksum
How to use checksums
39a88e5cd719373e181c2dac8b5b0d358925b0316fba5a1aae73c89c41d8c2a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.12

Release files / magic_eraser-0.1.0-py3-none-any.whl

Download URL magic_eraser-0.1.0-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a8a057592d732f7ed917426d0ed4d278d530abb80a9c4a902f8fa4398a05694f
BLAKE2b-256 checksum
How to use checksums
103102625448f9f50e6af23dd06cfa1f4d81c54b844b4a0ae5829c0148447917
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.12

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page