🪄 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
- A browser (e.g. Melon) collects candidate page elements and, on first visit to a site, asks an LLM which are ads.
- Each verdict is appended to
data/ad_dataset.jsonlas labeled training data and pushed here. scripts/build_rules.pyre-derives high-precision class/id token rules + per-domain CSS selectors intomagic_eraser/rules.json.magic-eraserthen 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.
Metadata
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| magic_eraser-0.1.0.tar.gz | 8.5 kB | Without provenance | Details for magic_eraser-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| magic_eraser-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for magic_eraser-0.1.0-py3-none-any.whl |
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
|
Security for magic-eraser 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.