File size: 2,669 Bytes
9b16060
1563f41
9b16060
 
 
 
 
1d8fad0
9b16060
 
1563f41
9b16060
 
1563f41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e17e9e0
1563f41
e17e9e0
1563f41
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
---
title: OPF Image Anonymizer
emoji: 🦀
colorFrom: yellow
colorTo: pink
sdk: gradio
sdk_version: 6.13.0
app_file: app_v2.py
pinned: false
license: apache-2.0
short_description: Use OAI's Privacy Filter to redact PII info from any image
---


# Image Anonymizer

Drop in a screenshot of a chat, email, or document or any image for that matter. The app runs OCR, feeds the recognised text through **OpenAI Privacy Filter**, maps detected PII spans back to their original pixel positions, and overlays black bars in a canvas editor. Toggle, move, add or delete bars — then save a ready-for-Twitter PNG or copy it straight to the clipboard.

## Features

- **OCR + privacy filter in one pass**: Tesseract extracts word-level boxes, the filter model finds PII char spans, the backend unions the two into redaction rectangles.
- **Canvas editor**: not expressible with `gr.Blocks` but possible with `gr.Server`. Drag to draw bars, click to select, drag to move, Delete to remove. Paste from clipboard to upload.
- **Eight PII categories**: Person, Address, Email, Phone, URL, Date, Account Number, Secret — each toggleable from the sidebar.
- **Export locally**: download as PNG or copy to clipboard. No upload of edits, no server round-trip.

## Architecture

- **Backend**: `gr.Server` — FastAPI route `POST /api/detect` accepts an image, runs OCR + the filter on GPU, returns the PNG as a base64 data URL plus a list of pixel boxes. Also exposes a `anonymize_screenshot` Gradio API.
- **Frontend**: custom HTML/CSS/JS served from the same server. Uses `<canvas>` at natural image resolution (scaled for display); final export is rendered to an offscreen canvas at full resolution.
- **Model**: `charles-first-org/second-model` loaded with the same hand-rolled inference path used in the sibling `PII Reveal` Space.

## How it works

1. User drops a screenshot (PNG/JPG/WebP) or pastes from clipboard.
2. `pytesseract.image_to_data` returns per-word text + bounding boxes. We reconstruct the full text with line breaks, keeping a char-offset → box map.
3. The full text is passed through the privacy filter (single forward pass, 128k context).
4. Detected char spans are looked up against the word map; overlapping words are grouped by line and unioned into rectangles with a small padding.
5. The frontend renders the image and boxes on a canvas. User edits locally and exports.

## API

```python
from gradio_client import Client, handle_file
client = Client("YOUR_SPACE_ID")
result = client.predict(handle_file("screenshot.png"), api_name="/anonymize_screenshot")
# -> {"width": ..., "height": ..., "boxes": [{"x","y","w","h","label","text"}, ...], ...}
```