HHelpful_AI / README.md
Kaushal05's picture
Update README.md
9138f52 verified
|
Raw
History Blame Contribute Delete
6.45 kB
metadata
title: HHelpful AI
emoji: 🐒
colorFrom: green
colorTo: yellow
sdk: docker
app_file: app.py
pinned: false

⚑ Antigravity Studio - AI Image & Document Workspace

A complete, production-grade, state-of-the-art Image & PDF Manipulation Web Application consisting of two primary workspaces:

  1. AI Background Remover Workspace: Isolate foreground subjects with UΒ²-Net deep learning or GrabCut, refine fine hair details with Guided Filter matting, and generate customizable realistic drop shadows.
  2. AI In-Image Text Editor Workspace: Automatically detect, erase, and replace text in images or multi-page PDFs while perfectly matching original fonts, sizes, and ink colors.

Built with Streamlit (frontend) and Python + OpenCV + Deep Learning (backend).


✨ Workspace 1: AI Background Remover

Allows users to upload an image, extract the subject with professional-grade borders, and customize visual compositions.

  • AI UΒ²-Net Neural Network Mode: Leverages pre-trained deep learning to automatically segment complex shapes (like portraits, hair, and soft details) without bounding box configurations.
  • GrabCut General Subject Mode: Detects bounding boxes automatically or supports manual coordinate tuning.
  • Signature & Text (Ink Extraction) Mode: Uses color distance maps to isolate handwritten ink from paper backdrops (perfect for signatures).
  • Advanced Edge Matting:
    • Guided Filter Matting: An edge-preserving linear filtering algorithm that aligns alpha transitions to individual hair fibers.
    • Morphological Closing: Fills inner holes and smooths contours.
    • Speckle Filtering: Cleans isolated floating noise.
  • Realistic Drop Shadow Engine: Generates natural drop shadows beneath isolated subjects. Customize opacity, blur softness, offset distance, and angle.
  • Interactive Composite Studio: Composite transparent cutouts over Checkerboard grids, Solid colors, gradients (Midnight Glow, Sunset Studio, Neon Cyber), or uploaded background images.

✨ Workspace 2: AI Document & PDF Text Editor

Allows users to upload an image or multi-page PDF, find text, and perform clean in-place corrections.

  • Automated Layout Scan: Scans images or document page textures using EasyOCR to discover bounding boxes of all text segments.
  • Translucent OCR Overlays: Renders glowing overlays displaying editable text fields in the document.
  • Zero-Configuration PDF Engine: Powered by PyMuPDF (Fitz). Render multi-page PDFs, navigate pages, and compile edited page images back into a single multi-page PDF document.
  • Adaptive Ink & Paper Color Sampling: Extracts the median BGR ink color (foreground character strokes) and surrounding paper texture color (background) using Otsu's adaptive binarization of characters.
  • Seamless Texture-Preserving Eraser: Creates a character-level binary mask, dilates it by 2px, and runs OpenCV Fast Inpainting (Telea's algorithm). This erases old text while preserving paper folds, grain, gridlines, and shadows.
  • Adaptive Text Synthesis: Scales the replacement text according to the bounding box height, matches standard font families (Serif, Sans-Serif, Monospace), and renders it anti-aliased with the sampled ink color.

πŸ“‚ Project Structure

e:\bg remover\
β”œβ”€β”€ app.py                     # Main Streamlit dashboard routing entrypoint & CSS styles
β”œβ”€β”€ requirements.txt           # Unified dependency manifest
β”œβ”€β”€ README.md                  # Detailed workspace and setup documentation
β”‚
β”œβ”€β”€ frontend/                  # Modern UI Layout Modules
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ home.py                # Premium Glassmorphic Studio Navigation landing page
β”‚   β”œβ”€β”€ bg_remover_ui.py       # Custom Background Remover controls and workflows
β”‚   β”œβ”€β”€ text_editor_ui.py      # PDF page navigation, OCR list, Find/Replace editor
β”‚   β”œβ”€β”€ preview_ui.py          # Before/After comparison and backdrop composites
β”‚   └── download_ui.py         # Downscaled/lazy high-res download compiler
β”‚
└── backend/                   # Algorithms and Heavy Processing Backends
    β”œβ”€β”€ __init__.py
    β”œβ”€β”€ utilities.py           # Image format converters and checkerboard pattern generators
    β”‚
    β”œβ”€β”€ bg_remover/            # Background Remover Subpackage
    β”‚   β”œβ”€β”€ __init__.py
    β”‚   β”œβ”€β”€ segmentation.py    # GrabCut, contour analysis, and corner color GMM seeding
    β”‚   β”œβ”€β”€ edge_detection.py  # Fast Guided Filter matting and morphological refinements
    β”‚   β”œβ”€β”€ shadow_generator.py# Affine transformation drop shadow translations and blenders
    β”‚   └── image_processor.py # Background remover high-level pipeline orchestrator
    β”‚
    └── text_editor/           # Text Editor & Document Subpackage
        β”œβ”€β”€ __init__.py
        β”œβ”€β”€ pdf_processor.py   # PyMuPDF page extractors and PDF compilers
        β”œβ”€β”€ ocr_engine.py      # EasyOCR layout scanning engine
        β”œβ”€β”€ color_detector.py  # Character-level ink/paper color samplers
        β”œβ”€β”€ font_detector.py   # System TTF font loader and height-based size mapper
        β”œβ”€β”€ text_replacer.py   # Telea inpainter and PIL anti-aliased text renderer
        └── orchestrator.py    # Text correction orchestrator

πŸš€ Installation & Running Locally

Ensure you have Python 3.10+ installed. Follow these steps:

1. Install Dependencies

Open a terminal in the root of the workspace (e:\bg remover\) and run:

pip install -r requirements.txt

2. Run the Application

Start the Streamlit dashboard:

streamlit run app.py

3. Open in Browser

The local server will start and prompt you to open the dashboard at:

  • Local URL: http://localhost:8501

πŸ› οΈ Offline Verification & Test Suites

We have built extensive automated tests to guarantee system stability and code correctness:

  • Background Remover Tests:
    python "C:\Users\Asus\.gemini\antigravity\brain\76a54bfc-09a7-4a96-809d-8b8c797bd925\scratch\test_pipeline.py"
    
  • Document Text Editor Tests:
    python "C:\Users\Asus\.gemini\antigravity\brain\76a54bfc-09a7-4a96-809d-8b8c797bd925\scratch\test_text_editor.py"
    

Both test suites should print [SUCCESS] and pass seamlessly!