Spaces:
Sleeping
Sleeping
Sync from GitHub via hub-sync
Browse files- Dockerfile +8 -1
- README.md +28 -11
- docker-compose.yml +6 -2
Dockerfile
CHANGED
|
@@ -6,6 +6,9 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
|
|
| 6 |
PYTHONPATH=/app/src \
|
| 7 |
FACEVERIFICATION_DEVICE=cpu
|
| 8 |
|
|
|
|
|
|
|
|
|
|
| 9 |
WORKDIR /app
|
| 10 |
|
| 11 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
@@ -28,4 +31,8 @@ USER appuser
|
|
| 28 |
|
| 29 |
EXPOSE 8000 7860
|
| 30 |
|
| 31 |
-
CMD [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
PYTHONPATH=/app/src \
|
| 7 |
FACEVERIFICATION_DEVICE=cpu
|
| 8 |
|
| 9 |
+
ARG APP_VARIANT=gradio
|
| 10 |
+
ENV APP_VARIANT=${APP_VARIANT}
|
| 11 |
+
|
| 12 |
WORKDIR /app
|
| 13 |
|
| 14 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
|
|
| 31 |
|
| 32 |
EXPOSE 8000 7860
|
| 33 |
|
| 34 |
+
CMD if [ "$APP_VARIANT" = "fastapi" ]; then \
|
| 35 |
+
exec uvicorn faceverification.interfaces.fastapi_app:app --host 0.0.0.0 --port 8000; \
|
| 36 |
+
else \
|
| 37 |
+
exec python -m faceverification.interfaces.gradio_app; \
|
| 38 |
+
fi
|
README.md
CHANGED
|
@@ -3,10 +3,8 @@ title: Face Verification
|
|
| 3 |
emoji: 🧠
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: green
|
| 6 |
-
sdk:
|
| 7 |
-
|
| 8 |
-
python_version: '3.11'
|
| 9 |
-
app_file: app.py
|
| 10 |
short_description: "Face verification demo with FaceNet and VectorDB"
|
| 11 |
tags: ["face-verification", "computer-vision", "facenet", "vector-database"]
|
| 12 |
pinned: false
|
|
@@ -30,7 +28,8 @@ The app lets users add known people to a local embeddings database and verify wh
|
|
| 30 |
- FaceNet embedding extraction with PyTorch
|
| 31 |
- Similarity search with ChromaDB
|
| 32 |
- Interactive Gradio UI with add-person and verify-identity flows
|
| 33 |
-
-
|
|
|
|
| 34 |
|
| 35 |
## Tech Stack
|
| 36 |
|
|
@@ -38,8 +37,10 @@ The app lets users add known people to a local embeddings database and verify wh
|
|
| 38 |
- PyTorch
|
| 39 |
- FaceNet / facenet-pytorch
|
| 40 |
- ChromaDB
|
|
|
|
| 41 |
- Gradio
|
| 42 |
-
-
|
|
|
|
| 43 |
|
| 44 |
## Run Locally
|
| 45 |
|
|
@@ -59,7 +60,7 @@ python app.py
|
|
| 59 |
|
| 60 |
## FastAPI Interface
|
| 61 |
|
| 62 |
-
The project
|
| 63 |
Run it locally with:
|
| 64 |
|
| 65 |
```bash
|
|
@@ -98,8 +99,8 @@ Authorization: Bearer <access_token>
|
|
| 98 |
|
| 99 |
## Deployment Notes
|
| 100 |
|
| 101 |
-
For
|
| 102 |
-
|
| 103 |
|
| 104 |
```bash
|
| 105 |
uvicorn faceverification.interfaces.fastapi_app:app --host 0.0.0.0 --port 8000
|
|
@@ -143,7 +144,21 @@ docker compose --profile gradio up --build
|
|
| 143 |
|
| 144 |
The Gradio UI will be available at http://localhost:7860.
|
| 145 |
|
| 146 |
-
Both services
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
enrolled faces are ephemeral and disappear when the container restarts. This is
|
| 148 |
intentional for the demo baseline.
|
| 149 |
|
|
@@ -199,11 +214,13 @@ curl -X POST http://localhost:8000/verify \
|
|
| 199 |
|
| 200 |
```text
|
| 201 |
src/faceverification/
|
| 202 |
-
app.py
|
| 203 |
config.py
|
| 204 |
core/
|
| 205 |
image_processor.py
|
| 206 |
vectordb.py
|
|
|
|
|
|
|
|
|
|
| 207 |
services/
|
| 208 |
face_verification.py
|
| 209 |
```
|
|
|
|
| 3 |
emoji: 🧠
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: green
|
| 6 |
+
sdk: docker
|
| 7 |
+
app_port: 7860
|
|
|
|
|
|
|
| 8 |
short_description: "Face verification demo with FaceNet and VectorDB"
|
| 9 |
tags: ["face-verification", "computer-vision", "facenet", "vector-database"]
|
| 10 |
pinned: false
|
|
|
|
| 28 |
- FaceNet embedding extraction with PyTorch
|
| 29 |
- Similarity search with ChromaDB
|
| 30 |
- Interactive Gradio UI with add-person and verify-identity flows
|
| 31 |
+
- FastAPI interface for containerized API deployments
|
| 32 |
+
- Docker-based Hugging Face Space deployment
|
| 33 |
|
| 34 |
## Tech Stack
|
| 35 |
|
|
|
|
| 37 |
- PyTorch
|
| 38 |
- FaceNet / facenet-pytorch
|
| 39 |
- ChromaDB
|
| 40 |
+
- FastAPI
|
| 41 |
- Gradio
|
| 42 |
+
- Docker / GHCR
|
| 43 |
+
- Hugging Face Spaces Docker SDK
|
| 44 |
|
| 45 |
## Run Locally
|
| 46 |
|
|
|
|
| 60 |
|
| 61 |
## FastAPI Interface
|
| 62 |
|
| 63 |
+
The project includes an HTTP API for the same enroll-and-verify workflow.
|
| 64 |
Run it locally with:
|
| 65 |
|
| 66 |
```bash
|
|
|
|
| 99 |
|
| 100 |
## Deployment Notes
|
| 101 |
|
| 102 |
+
For API deployments, the recommended baseline is the FastAPI container running
|
| 103 |
+
Uvicorn:
|
| 104 |
|
| 105 |
```bash
|
| 106 |
uvicorn faceverification.interfaces.fastapi_app:app --host 0.0.0.0 --port 8000
|
|
|
|
| 144 |
|
| 145 |
The Gradio UI will be available at http://localhost:7860.
|
| 146 |
|
| 147 |
+
Both services are built from the same `Dockerfile` with different variants:
|
| 148 |
+
|
| 149 |
+
- `fastapi`: published to GHCR by the container workflow.
|
| 150 |
+
- `gradio`: used by the Hugging Face Docker Space.
|
| 151 |
+
|
| 152 |
+
The published FastAPI image is tagged as:
|
| 153 |
+
|
| 154 |
+
```text
|
| 155 |
+
ghcr.io/leandrodevai/faceverification:fastapi
|
| 156 |
+
```
|
| 157 |
+
|
| 158 |
+
Each successful container workflow also publishes an immutable SHA tag with the
|
| 159 |
+
`fastapi-sha-*` prefix.
|
| 160 |
+
|
| 161 |
+
By default, ChromaDB runs in memory, so
|
| 162 |
enrolled faces are ephemeral and disappear when the container restarts. This is
|
| 163 |
intentional for the demo baseline.
|
| 164 |
|
|
|
|
| 214 |
|
| 215 |
```text
|
| 216 |
src/faceverification/
|
|
|
|
| 217 |
config.py
|
| 218 |
core/
|
| 219 |
image_processor.py
|
| 220 |
vectordb.py
|
| 221 |
+
interfaces/
|
| 222 |
+
fastapi_app.py
|
| 223 |
+
gradio_app.py
|
| 224 |
services/
|
| 225 |
face_verification.py
|
| 226 |
```
|
docker-compose.yml
CHANGED
|
@@ -2,7 +2,9 @@ services:
|
|
| 2 |
api:
|
| 3 |
build:
|
| 4 |
context: .
|
| 5 |
-
|
|
|
|
|
|
|
| 6 |
command: uvicorn faceverification.interfaces.fastapi_app:app --host 0.0.0.0 --port 8000
|
| 7 |
ports:
|
| 8 |
- "8000:8000"
|
|
@@ -21,7 +23,9 @@ services:
|
|
| 21 |
gradio:
|
| 22 |
build:
|
| 23 |
context: .
|
| 24 |
-
|
|
|
|
|
|
|
| 25 |
command: python -m faceverification.interfaces.gradio_app
|
| 26 |
profiles:
|
| 27 |
- gradio
|
|
|
|
| 2 |
api:
|
| 3 |
build:
|
| 4 |
context: .
|
| 5 |
+
args:
|
| 6 |
+
APP_VARIANT: fastapi
|
| 7 |
+
image: faceverification:fastapi
|
| 8 |
command: uvicorn faceverification.interfaces.fastapi_app:app --host 0.0.0.0 --port 8000
|
| 9 |
ports:
|
| 10 |
- "8000:8000"
|
|
|
|
| 23 |
gradio:
|
| 24 |
build:
|
| 25 |
context: .
|
| 26 |
+
args:
|
| 27 |
+
APP_VARIANT: gradio
|
| 28 |
+
image: faceverification:gradio
|
| 29 |
command: python -m faceverification.interfaces.gradio_app
|
| 30 |
profiles:
|
| 31 |
- gradio
|