ysharma HF Staff commited on
Commit
1563f41
·
verified ·
1 Parent(s): 36f92e5

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +36 -3
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: Dummy Opf 2
3
  emoji: 🦀
4
  colorFrom: yellow
5
  colorTo: pink
@@ -8,7 +8,40 @@ sdk_version: 6.13.0
8
  app_file: app_v2.py
9
  pinned: false
10
  license: apache-2.0
11
- short_description: dummy opf demo
12
  ---
13
 
14
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: OPF Image Anonymizer
3
  emoji: 🦀
4
  colorFrom: yellow
5
  colorTo: pink
 
8
  app_file: app_v2.py
9
  pinned: false
10
  license: apache-2.0
11
+ short_description: Use OAI's Privacy Filter to redact PII info from any image
12
  ---
13
 
14
+
15
+ # Image Anonymizer
16
+
17
+ 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.
18
+
19
+ ## Features
20
+
21
+ - **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.
22
+ - **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.
23
+ - **Eight PII categories**: Person, Address, Email, Phone, URL, Date, Account Number, Secret — each toggleable from the sidebar.
24
+ - **Export locally**: download as PNG or copy to clipboard. No upload of edits, no server round-trip.
25
+
26
+ ## Architecture
27
+
28
+ - **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.
29
+ - **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.
30
+ - **Model**: `charles-first-org/second-model` loaded with the same hand-rolled inference path used in the sibling `PII Reveal` Space.
31
+
32
+ ## How it works
33
+
34
+ 1. User drops a screenshot (PNG/JPG/WebP) or pastes from clipboard.
35
+ 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.
36
+ 3. The full text is passed through the privacy filter (single forward pass, 128k context).
37
+ 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.
38
+ 5. The frontend renders the image and boxes on a canvas. User edits locally and exports.
39
+
40
+ ## API
41
+
42
+ ```python
43
+ from gradio_client import Client, file
44
+ client = Client("YOUR_SPACE_ID")
45
+ result = client.predict(file("screenshot.png"), api_name="/anonymize_screenshot")
46
+ # -> {"width": ..., "height": ..., "boxes": [{"x","y","w","h","label","text"}, ...], ...}
47
+ ```