Edvards commited on
Commit
ee7103e
1 Parent(s): 6567450

detect faces

Browse files
Files changed (6) hide show
  1. .gitignore +2 -0
  2. Dockerfile +7 -1
  3. app.py +31 -1
  4. pixi.lock +0 -0
  5. pixi.toml +2 -0
  6. requirements.txt +3 -1
.gitignore CHANGED
@@ -1,3 +1,5 @@
1
  # pixi environments
2
  .pixi
3
  *.egg-info
 
 
 
1
  # pixi environments
2
  .pixi
3
  *.egg-info
4
+ *.pyc
5
+ __pycache__
Dockerfile CHANGED
@@ -1,10 +1,16 @@
1
  # read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
  # you will also find guides on how best to write your Dockerfile
3
 
4
- FROM python:3.11
5
 
6
  RUN useradd -m -u 1000 user
7
 
 
 
 
 
 
 
8
  WORKDIR /app
9
 
10
  COPY --chown=user ./requirements.txt requirements.txt
 
1
  # read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
  # you will also find guides on how best to write your Dockerfile
3
 
4
+ FROM python:3.11-slim
5
 
6
  RUN useradd -m -u 1000 user
7
 
8
+ # Install system dependencies
9
+ RUN apt-get update && apt-get install -y \
10
+ libgl1-mesa-glx \
11
+ libglib2.0-0 \
12
+ && rm -rf /var/lib/apt/lists/*
13
+
14
  WORKDIR /app
15
 
16
  COPY --chown=user ./requirements.txt requirements.txt
app.py CHANGED
@@ -1,7 +1,37 @@
1
- from fastapi import FastAPI
 
 
 
 
2
 
3
  app = FastAPI()
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  @app.get("/")
6
  def greet_json():
7
  return {"Hello": "World!"}
 
1
+ from fastapi import FastAPI, File, UploadFile
2
+ from retinaface import RetinaFace
3
+ import cv2
4
+ import numpy as np
5
+ from typing import Any, Dict
6
 
7
  app = FastAPI()
8
 
9
+ def convert_to_python_types(obj: Any) -> Any:
10
+ if isinstance(obj, np.integer):
11
+ return int(obj)
12
+ elif isinstance(obj, np.floating):
13
+ return float(obj)
14
+ elif isinstance(obj, np.ndarray):
15
+ return obj.tolist()
16
+ elif isinstance(obj, dict):
17
+ return {key: convert_to_python_types(value) for key, value in obj.items()}
18
+ elif isinstance(obj, list):
19
+ return [convert_to_python_types(item) for item in obj]
20
+ else:
21
+ return obj
22
+
23
+ @app.post("/detect_faces")
24
+ async def detect_faces(file: UploadFile = File(...)):
25
+ contents = await file.read()
26
+ nparr = np.frombuffer(contents, np.uint8)
27
+ image = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
28
+
29
+ # Detect faces
30
+ faces = RetinaFace.detect_faces(image)
31
+
32
+ return convert_to_python_types(faces)
33
+
34
+
35
  @app.get("/")
36
  def greet_json():
37
  return {"Hello": "World!"}
pixi.lock CHANGED
The diff for this file is too large to render. See raw diff
 
pixi.toml CHANGED
@@ -12,3 +12,5 @@ platforms = ["linux-64"]
12
  python = "3.11.*"
13
  fastapi = ">=0.111.0,<0.112"
14
  uvicorn = ">=0.30.1,<0.31"
 
 
 
12
  python = "3.11.*"
13
  fastapi = ">=0.111.0,<0.112"
14
  uvicorn = ">=0.30.1,<0.31"
15
+ retina-face = ">=0.0.17,<0.1"
16
+ tf-keras = ">=2.16.0,<2.17"
requirements.txt CHANGED
@@ -1,2 +1,4 @@
1
  fastapi
2
- uvicorn[standard]
 
 
 
1
  fastapi
2
+ uvicorn[standard]
3
+ retina-face
4
+ tf-keras