Edvards commited on
Commit
eb8e92c
1 Parent(s): 0a40172

initial commit

Browse files
Files changed (7) hide show
  1. .gitattributes +2 -0
  2. .gitignore +3 -0
  3. Dockerfile +22 -0
  4. app.py +37 -0
  5. pixi.lock +0 -0
  6. pixi.toml +17 -0
  7. requirements.txt +4 -0
.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ # GitHub syntax highlighting
37
+ pixi.lock linguist-language=YAML linguist-generated=true
.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ # pixi environments
2
+ .pixi
3
+ *.egg-info
Dockerfile ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 for opencv
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
17
+
18
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
19
+
20
+ COPY --chown=user . /app
21
+
22
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ADDED
The diff for this file is too large to render. See raw diff
 
pixi.toml ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [project]
2
+ name = "PhotoPrepSpace"
3
+ version = "0.1.0"
4
+ description = "Add a short description here"
5
+ authors = ["EdvardsZ <edvards1999@gmail.com>"]
6
+ channels = ["conda-forge"]
7
+ platforms = ["linux-64"]
8
+
9
+ [tasks]
10
+
11
+ [dependencies]
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"
17
+
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ fastapi
2
+ uvicorn[standard]
3
+ retina-face
4
+ tf-keras