ysharma's picture
ysharma HF Staff
Update README.md
e17e9e0 verified

A newer version of the Gradio SDK is available: 6.14.0

Upgrade
metadata
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

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"}, ...], ...}