Spaces:
Sleeping
Sleeping
A newer version of the Gradio SDK is available: 6.22.0
metadata
title: Face Recognition System
emoji: π§
colorFrom: blue
colorTo: purple
sdk: gradio
sdk_version: 6.16.0
python_version: '3.10'
app_file: app.py
pinned: false
Face Recognition & Photo Capture Web App
This repository provides a face recognition backend (Flask) and a small Gradio UI to register users and run recognition from images.
This README focuses on deploying to Hugging Face Spaces (either using the Gradio SDK or the Docker option).
Quick notes
- Python 3.10 recommended (native deps installed via Conda in the Dockerfile).
- Heavy native deps:
dlib,face-recognitionβ builds can be large and slow on Spaces.
Deploy options
Gradio SDK (recommended for simple Spaces):
- Use the Gradio SDK entrypoint. This repo includes
gradio_app.pywhich launches the Gradio interface. - If you prefer the SDK frontmatter approach, set
app_filetogradio_app.pyin your Space settings or renamegradio_app.pytoapp.py. - In the Space settings select
SDK: Gradio, Python3.10, and the appropriateapp_file.
- Use the Gradio SDK entrypoint. This repo includes
Docker (recommended if you need full control over system dependencies):
- This repo includes a
Dockerfilethat installs native deps via Conda and launches the Gradio app by default. - Choose Docker when creating a Space and push this repo; set Secrets before building.
- This repo includes a
Required Secrets (add these in your Space Settings β Secrets)
SUPABASE_URLβ your Supabase project URLSUPABASE_SERVICE_ROLE_KEYβ Supabase service role key (server-side) for uploads/deletesSTORAGEβ set tosupabaseto store images in Supabase StorageADMIN_USERNAMEβ admin username (optional; defaultadmin)ADMIN_PASSWORDβ admin password (required to access admin endpoints)APP_SECRETβ secret used for JWT signing- Optional:
DATABASE_URL(external Postgres),AWS_S3_BUCKET,AWS_REGION,CLOUDINARY_*
Supabase setup
- Create a Storage bucket named
captures(the app usessupabase.storage.from_('captures')). - Decide whether objects should be public. The code uses
get_public_url(); if you prefer private objects, update the app to use signed URLs.
Local testing (recommended before pushing to Spaces)
# build locally (requires Docker)
docker build -t face-recog-app .
# run using local filesystem storage to avoid external services
docker run --rm -e STORAGE=local -e ADMIN_PASSWORD=adminpass -p 7860:7860 face-recog-app
# open http://localhost:7860
Deploying to Hugging Face Spaces (high level)
- Create a new Space and choose
GradioSDK (orDockerif you prefer). If using Gradio SDK, setapp_filetogradio_app.py. - Push this repository to the Space (add remote and git push).
- In the Space Settings β Secrets, add the required
SUPABASE_*keys,ADMIN_PASSWORD, andAPP_SECRET. - Trigger a build and monitor logs for native dependency installation (may take several minutes).
Persistence and storage notes
- The container filesystem and local SQLite (
app.db) are ephemeral on Spaces. To persist images and DB across rebuilds use Supabase Storage and an external Postgres (DATABASE_URL). - The app's
STORAGEsetting controls where images are saved. UseSTORAGE=supabasein Space Secrets to send images to Supabase Storage.
Security
- Keep
SUPABASE_SERVICE_ROLE_KEYonly in Secrets β never expose it to the client/browser. - Use strong
APP_SECRETand secureADMIN_PASSWORDin production.
Troubleshooting
- Build fails or times out: heavy native deps (
dlib) are the likely cause. Consider pre-building an image elsewhere and using Docker, or replacingface-recognitionwith a lighter alternative for initial testing. - Supabase upload errors: verify the
capturesbucket exists and the service role key has storage permissions.
Files of interest
app.pyβ Flask backend and REST APIgradio_app.pyβ Gradio UI that integrates with the backend (used by Spaces Gradio SDK or Docker)Dockerfileβ Docker image that installs native deps via Conda and runsgradio_app.py.env.exampleβ example environment variables to copy into.envfor local testing
If you want, I can:
- Update the Space frontmatter to set
app_file: gradio_app.pyfor a Gradio SDK deployment. - Help push this repo to a new Hugging Face Space and add the exact Secrets via the UI.