Spaces:
Runtime error
Runtime error
Delete README.md
Browse files
README.md
DELETED
|
@@ -1,64 +0,0 @@
|
|
| 1 |
-
---
|
| 2 |
-
title: Face Recognition API
|
| 3 |
-
emoji: 🧠
|
| 4 |
-
colorFrom: yellow
|
| 5 |
-
colorTo: blue
|
| 6 |
-
sdk: gradio
|
| 7 |
-
sdk_version: 4.44.1
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
-
---
|
| 11 |
-
# Face Recognition API
|
| 12 |
-
|
| 13 |
-
InsightFace `buffalo_l` face recognition service for SchoolMaster attendance.
|
| 14 |
-
Stateless — it only extracts/compares face embeddings. All student data
|
| 15 |
-
(including embeddings) lives in your MySQL database, not on this Space.
|
| 16 |
-
|
| 17 |
-
Visiting the Space shows a small status page (Gradio) — that's just a
|
| 18 |
-
health-check UI. Your PHP backend talks directly to the `/api/*` endpoints
|
| 19 |
-
below, not to that page.
|
| 20 |
-
|
| 21 |
-
## Required setup: add your API key as a Secret
|
| 22 |
-
|
| 23 |
-
**Do not put your API key in this README or in any committed file.**
|
| 24 |
-
|
| 25 |
-
1. On this Space, go to **Settings → Repository secrets** (or **Variables
|
| 26 |
-
and secrets**, depending on your account).
|
| 27 |
-
2. Add a secret named `API_KEY` with your real key as the value — the same
|
| 28 |
-
value your PHP `.env` uses to call this service.
|
| 29 |
-
3. Restart the Space.
|
| 30 |
-
|
| 31 |
-
`config.py` reads it via `os.environ` — it is never written into the repo.
|
| 32 |
-
|
| 33 |
-
## Endpoints (same contract as your local version — no PHP changes needed)
|
| 34 |
-
|
| 35 |
-
| Endpoint | Method | Description |
|
| 36 |
-
|----------|--------|-------------|
|
| 37 |
-
| `/api/health` | GET | Health check |
|
| 38 |
-
| `/api/extract` | POST | Extract embedding from 1+ photos (multipart `files`) |
|
| 39 |
-
| `/api/enroll` | POST | Extract + average embedding from 3-10 photos (multipart `files`) |
|
| 40 |
-
| `/api/recognize` | POST | Match one photo against embeddings you pass in |
|
| 41 |
-
|
| 42 |
-
All POST endpoints require an `X-API-Key` header matching your `API_KEY`
|
| 43 |
-
secret, and accept `multipart/form-data` file uploads — identical to your
|
| 44 |
-
local FastAPI service, so your existing PHP integration works unchanged
|
| 45 |
-
(just point it at this Space's URL instead of `127.0.0.1:8000`).
|
| 46 |
-
|
| 47 |
-
## What was actually wrong before
|
| 48 |
-
|
| 49 |
-
The previous version tried to run a second `uvicorn` server in a background
|
| 50 |
-
thread on the same port Gradio also wanted to use, and never blocked the
|
| 51 |
-
main thread — so the process exited right after a successful model load,
|
| 52 |
-
crash-looping the Space. This version runs everything (the API routes and
|
| 53 |
-
a small Gradio status page) as **one process on one port**, which is what
|
| 54 |
-
Spaces actually needs.
|
| 55 |
-
|
| 56 |
-
## A tradeoff to know about before relying on this for production
|
| 57 |
-
|
| 58 |
-
Free-tier Spaces:
|
| 59 |
-
- **Sleep after inactivity.** The first request after a sleep can take
|
| 60 |
-
1-2 minutes while the container restarts and re-downloads the model.
|
| 61 |
-
- **CPU-only**, similar to or slower than a typical laptop — this may not
|
| 62 |
-
fix the "too slow" complaint that prompted looking at this in the first
|
| 63 |
-
place. Worth timing actual `/api/recognize` calls here vs. your local
|
| 64 |
-
setup before switching your kiosk over to it.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|