hammaster commited on
Commit
54660dc
·
1 Parent(s): fadb64a

fix: resolve libgl1 build error and update dependencies for HuggingFace deployment

Browse files
Files changed (5) hide show
  1. ASSETS.md +12 -0
  2. Dockerfile +1 -5
  3. README.md +16 -61
  4. api.py +20 -8
  5. requirements.txt +1 -0
ASSETS.md CHANGED
@@ -55,6 +55,18 @@
55
 
56
  ---
57
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  ## Related Projects
59
 
60
  | Project | Relationship |
 
55
 
56
  ---
57
 
58
+ ## Claude Code Quick Start
59
+
60
+ ```powershell
61
+ # Start Claude Code with CCR (Gemini backend)
62
+ $env:Path = "C:\Users\jonat_cau4\AppData\Local\nvm\v22.21.1;C:\Users\jonat_cau4\AppData\Roaming\npm;" + $env:Path
63
+ $env:CLAUDE_BASE_URL = "http://127.0.0.1:3456"
64
+ cd "C:\Users\jonat_cau4\.gemini\antigravity\scratch\background removal tool"
65
+ claude
66
+ ```
67
+
68
+ ---
69
+
70
  ## Related Projects
71
 
72
  | Project | Relationship |
Dockerfile CHANGED
@@ -9,11 +9,7 @@ ENV MPLCONFIGDIR=/app/cache
9
  ENV HOME=/home/user
10
 
11
  # Install system dependencies
12
- RUN apt-get update && apt-get install -y \
13
- build-essential \
14
- libgl1-mesa-glx \
15
- libglib2.0-0 \
16
- && rm -rf /var/lib/apt/lists/*
17
 
18
  # Set up a new user named "user" with UID 1000
19
  RUN useradd -m -u 1000 user
 
9
  ENV HOME=/home/user
10
 
11
  # Install system dependencies
12
+ RUN apt-get update && apt-get install -y build-essential libgl1 libglib2.0-0 && rm -rf /var/lib/apt/lists/*
 
 
 
 
13
 
14
  # Set up a new user named "user" with UID 1000
15
  RUN useradd -m -u 1000 user
README.md CHANGED
@@ -1,68 +1,23 @@
1
- # CutoutAI - Background Remover
 
 
 
 
 
 
 
 
2
 
3
- An enhanced, flawless background removal tool built on BiRefNet for perfect t-shirt mockup preparation.
4
 
5
- ## Features
6
 
7
- - **Flawless Removal**: No patchy faces, artifacts, or edge issues
8
- - **Multi-Element Capture**: Captures bubbles, decorations, and all design elements
9
- - **API Ready**: Webhook, HTTP API, terminal commands
10
- - **Cloud Hosted**: Designed for n8n, Make, and cloud automation
11
- - **Mockup Quality**: Optimized for Printify t-shirt mockups
12
 
13
- ## Quick Start
14
 
15
- ```python
16
- from cutoutai import remove_background
17
 
18
- # Basic usage
19
- result = remove_background("design.png")
20
- result.save("design_cutout.png")
21
 
22
- # With enhanced settings for complex designs
23
- result = remove_background(
24
- "design.png",
25
- capture_all_elements=True, # Get bubbles, small elements
26
- edge_refinement=True, # Smooth edges
27
- matting_mode="general" # or "portrait" for faces
28
- )
29
- ```
30
-
31
- ## API Endpoints
32
-
33
- | Endpoint | Method | Description |
34
- |----------|--------|-------------|
35
- | `/api/v1/remove` | POST | Remove background from image |
36
- | `/api/v1/batch` | POST | Process multiple images |
37
- | `/api/v1/health` | GET | Health check |
38
- | `/webhook` | POST | n8n/Make webhook endpoint |
39
-
40
- ## Workflow Integration
41
-
42
- ### n8n Webhook
43
- ```
44
- POST https://your-host/webhook
45
- Content-Type: multipart/form-data
46
-
47
- image: <file>
48
- options: {"capture_all_elements": true}
49
- ```
50
-
51
- ### CLI
52
- ```bash
53
- cutoutai process design.png --output cutout.png
54
- cutoutai batch ./designs/ --output ./cutouts/
55
- ```
56
-
57
- ## Quality Settings
58
-
59
- | Setting | Description | Use Case |
60
- |---------|-------------|----------|
61
- | `capture_all_elements` | Detect and preserve small elements (bubbles, decorations) | Complex designs |
62
- | `edge_refinement` | Smooth and feather edges | All mockups |
63
- | `matting_mode` | `general`, `portrait`, or `heavy` | Match content type |
64
- | `output_resolution` | Preserve or scale output | Printify requirements |
65
-
66
- ## License
67
-
68
- MIT License - Built on BiRefNet
 
1
+ ---
2
+ title: CutoutAI Background Remover
3
+ emoji: 🖼️
4
+ colorFrom: blue
5
+ colorTo: purple
6
+ sdk: docker
7
+ app_port: 7860
8
+ pinned: false
9
+ ---
10
 
11
+ # CutoutAI Background Removal Service
12
 
13
+ This space hosts a custom API for removing backgrounds from images using BiRefNet.
14
 
15
+ ## API Usage
 
 
 
 
16
 
17
+ **Endpoint:** `/remove-background`
18
 
19
+ **Method:** `POST`
 
20
 
21
+ **Body:** `multipart/form-data` with an `image` file.
 
 
22
 
23
+ **Response:** Returns the image PNG with transparent background.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
api.py CHANGED
@@ -12,6 +12,7 @@ import io
12
  import base64
13
  import time
14
  import logging
 
15
  from typing import Optional, Literal, Union
16
  from pathlib import Path
17
  from contextlib import asynccontextmanager
@@ -307,12 +308,13 @@ async def webhook_handler(
307
  # Handle potential header in base64
308
  if "," in image_base64:
309
  image_base64 = image_base64.split(",")[1]
 
 
310
  img_data = base64.b64decode(image_base64)
311
  logger.info("Using base64 image data")
312
  except Exception as e:
313
  return JSONResponse({"success": False, "error": f"Invalid base64 data: {e}"}, status_code=400)
314
  elif image_url:
315
- import httpx
316
  logger.info(f"Fetching image from URL: {image_url}")
317
  async with httpx.AsyncClient(timeout=30.0, follow_redirects=True) as client:
318
  try:
@@ -341,21 +343,31 @@ async def webhook_handler(
341
  edge_radius=edge_radius,
342
  threshold=threshold,
343
  soft_threshold=soft_threshold,
 
344
  output_format="base64"
345
  )
346
 
347
  processing_time = time.time() - start_time
348
 
349
- response_data = {
350
- "success": True,
351
- "image_base64": result,
352
- "model_used": model,
353
- "processing_time_seconds": round(processing_time, 2)
354
- }
 
 
 
 
 
 
 
 
 
 
355
 
356
  # If callback URL provided, send result there too
357
  if callback_url:
358
- import httpx
359
  logger.info(f"Sending callback to: {callback_url}")
360
  async with httpx.AsyncClient(timeout=10.0) as client:
361
  try:
 
12
  import base64
13
  import time
14
  import logging
15
+ import httpx
16
  from typing import Optional, Literal, Union
17
  from pathlib import Path
18
  from contextlib import asynccontextmanager
 
308
  # Handle potential header in base64
309
  if "," in image_base64:
310
  image_base64 = image_base64.split(",")[1]
311
+ # Clean whitespace
312
+ image_base64 = "".join(image_base64.split())
313
  img_data = base64.b64decode(image_base64)
314
  logger.info("Using base64 image data")
315
  except Exception as e:
316
  return JSONResponse({"success": False, "error": f"Invalid base64 data: {e}"}, status_code=400)
317
  elif image_url:
 
318
  logger.info(f"Fetching image from URL: {image_url}")
319
  async with httpx.AsyncClient(timeout=30.0, follow_redirects=True) as client:
320
  try:
 
343
  edge_radius=edge_radius,
344
  threshold=threshold,
345
  soft_threshold=soft_threshold,
346
+ return_mask=return_mask,
347
  output_format="base64"
348
  )
349
 
350
  processing_time = time.time() - start_time
351
 
352
+ if isinstance(result, dict):
353
+ response_data = {
354
+ "success": True,
355
+ "image_base64": result["result"],
356
+ "mask_base64": result["mask"],
357
+ "model_used": model,
358
+ "threshold_used": round(result.get("threshold_used", 0), 4),
359
+ "processing_time_seconds": round(processing_time, 2)
360
+ }
361
+ else:
362
+ response_data = {
363
+ "success": True,
364
+ "image_base64": result,
365
+ "model_used": model,
366
+ "processing_time_seconds": round(processing_time, 2)
367
+ }
368
 
369
  # If callback URL provided, send result there too
370
  if callback_url:
 
371
  logger.info(f"Sending callback to: {callback_url}")
372
  async with httpx.AsyncClient(timeout=10.0) as client:
373
  try:
requirements.txt CHANGED
@@ -6,6 +6,7 @@ torchvision>=0.15.0
6
  transformers>=4.35.0
7
  timm>=0.9.0
8
  kornia>=0.7.0
 
9
 
10
  # Image processing
11
  Pillow>=10.0.0
 
6
  transformers>=4.35.0
7
  timm>=0.9.0
8
  kornia>=0.7.0
9
+ einops>=0.7.0
10
 
11
  # Image processing
12
  Pillow>=10.0.0