Spaces:
Sleeping
Sleeping
Stanislav
commited on
Commit
·
6c8bcbc
1
Parent(s):
aa1c1e5
feat: dockerfile, yaml, requirements, readme
Browse files- Dockerfile +24 -0
- README.md +36 -0
- requirements.txt +0 -0
- run_fastapi.py +6 -1
- space.yaml +10 -0
Dockerfile
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Base Python image
|
2 |
+
FROM python:3.10-slim
|
3 |
+
|
4 |
+
# Install system dependencies
|
5 |
+
RUN apt-get update && apt-get install -y \
|
6 |
+
build-essential \
|
7 |
+
cmake \
|
8 |
+
libgl1-mesa-glx \
|
9 |
+
&& rm -rf /var/lib/apt/lists/*
|
10 |
+
|
11 |
+
# Upgrade pip
|
12 |
+
RUN pip install --upgrade pip
|
13 |
+
|
14 |
+
# Create app working directory
|
15 |
+
WORKDIR /app
|
16 |
+
|
17 |
+
# Copy all project files
|
18 |
+
COPY . .
|
19 |
+
|
20 |
+
# Install Python packages
|
21 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
22 |
+
|
23 |
+
# Start FastAPI server
|
24 |
+
CMD ["python", "run_fast_api.py"]
|
README.md
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: "Object Cutter 🧩"
|
3 |
+
emoji: "🧩"
|
4 |
+
colorFrom: "green"
|
5 |
+
colorTo: "green"
|
6 |
+
sdk: "docker"
|
7 |
+
sdk_version: "3.0"
|
8 |
+
python_version: "3.10"
|
9 |
+
app_file: "run_fastapi.py"
|
10 |
+
fullWidth: true
|
11 |
+
header: "default"
|
12 |
+
short_description: "AI-powered object cutter using Grounding DINO and SAM."
|
13 |
+
models:
|
14 |
+
- "stkrk/sam-vit-b-01ec64"
|
15 |
+
datasets:
|
16 |
+
- "None"
|
17 |
+
tags:
|
18 |
+
- "Object Detection"
|
19 |
+
- "Segmentation"
|
20 |
+
- "DINO"
|
21 |
+
- "SAM"
|
22 |
+
pinned: true
|
23 |
+
---
|
24 |
+
|
25 |
+
# Object Cutter 🧩
|
26 |
+
|
27 |
+
FastAPI-based web app for object detection and segmentation using Grounding DINO + SAM.
|
28 |
+
Upload an image, type your object (e.g., "a cat on a sofa") — get clean PNGs with transparent backgrounds.
|
29 |
+
|
30 |
+
## Features
|
31 |
+
|
32 |
+
- Prompt-based object detection (Grounding DINO)
|
33 |
+
- Precise segmentation (SAM)
|
34 |
+
- Simple UI, optimized for mobile
|
35 |
+
- Download only what you need — one click
|
36 |
+
- Automatic session cleanup
|
requirements.txt
ADDED
Binary file (672 Bytes). View file
|
|
run_fastapi.py
CHANGED
@@ -13,6 +13,8 @@ from database.crud import get_session, delete_session
|
|
13 |
from models.sam import SamWrapper
|
14 |
from models.dino import DinoWrapper
|
15 |
|
|
|
|
|
16 |
# --- Init app and database
|
17 |
app = FastAPI()
|
18 |
init_db()
|
@@ -26,10 +28,13 @@ app.mount("/outputs", StaticFiles(directory="outputs"), name="outputs")
|
|
26 |
app.mount("/static", StaticFiles(directory="static"), name="static")
|
27 |
templates = Jinja2Templates(directory="templates")
|
28 |
|
|
|
|
|
|
|
29 |
# --- Model initialization (once)
|
30 |
sam = SamWrapper(
|
31 |
model_type="vit_b",
|
32 |
-
checkpoint_path=
|
33 |
)
|
34 |
dino = DinoWrapper()
|
35 |
|
|
|
13 |
from models.sam import SamWrapper
|
14 |
from models.dino import DinoWrapper
|
15 |
|
16 |
+
from huggingface_hub import hf_hub_download
|
17 |
+
|
18 |
# --- Init app and database
|
19 |
app = FastAPI()
|
20 |
init_db()
|
|
|
28 |
app.mount("/static", StaticFiles(directory="static"), name="static")
|
29 |
templates = Jinja2Templates(directory="templates")
|
30 |
|
31 |
+
# --- Download checkpoint from model-repo
|
32 |
+
checkpoint_path = hf_hub_download(repo_id="stkrk/sam-vit-b-checkpoint", filename="sam_vit_b_01ec64.pth")
|
33 |
+
|
34 |
# --- Model initialization (once)
|
35 |
sam = SamWrapper(
|
36 |
model_type="vit_b",
|
37 |
+
checkpoint_path=checkpoint_path
|
38 |
)
|
39 |
dino = DinoWrapper()
|
40 |
|
space.yaml
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
title: "Object Cutter 🧩"
|
2 |
+
emoji: "🧩"
|
3 |
+
colorFrom: "green"
|
4 |
+
colorTo: "green"
|
5 |
+
sdk: "docker"
|
6 |
+
python_version: "3.10"
|
7 |
+
app_file: "run_fastapi.py"
|
8 |
+
fullWidth: true
|
9 |
+
pinned: true
|
10 |
+
license: "mit"
|