maryjscout commited on
Commit
cd13fff
·
verified ·
1 Parent(s): 599de0a

Delete face_service.py

Browse files
Files changed (1) hide show
  1. face_service.py +0 -58
face_service.py DELETED
@@ -1,58 +0,0 @@
1
- """
2
- face_service.py
3
- ===============
4
- InsightFace wrapper — lazy loading + guarded import.
5
-
6
- The analyser is created on first call to get_analyser(), not at module import.
7
- This means the server starts instantly even if the buffalo_l model pack
8
- hasn't been downloaded yet.
9
- """
10
- from __future__ import annotations
11
-
12
- _face_analyser = None
13
-
14
- # Guard: don't crash at import time if insightface isn't installed
15
- try:
16
- import insightface # noqa: F401 — availability check only
17
- _AVAILABLE = True
18
- except ImportError:
19
- _AVAILABLE = False
20
-
21
-
22
- def get_analyser():
23
- """
24
- Return the FaceAnalysis instance, initialising it on first call.
25
- Thread-safety note: fine for single-worker Railway deployments.
26
- """
27
- global _face_analyser
28
-
29
- if not _AVAILABLE:
30
- raise RuntimeError(
31
- "insightface is not installed. "
32
- "Add it to requirements.txt and redeploy."
33
- )
34
-
35
- if _face_analyser is None:
36
- from insightface.app import FaceAnalysis
37
- print("⏳ Initialising FaceAnalysis (buffalo_l)…", flush=True)
38
- _face_analyser = FaceAnalysis(
39
- name="buffalo_l",
40
- providers=["CPUExecutionProvider"],
41
- )
42
- _face_analyser.prepare(ctx_id=0, det_size=(640, 640))
43
- print("✅ FaceAnalysis ready", flush=True)
44
-
45
- return _face_analyser
46
-
47
-
48
- def process_face(data: dict) -> dict:
49
- """
50
- Face detection stub — replace the body with your real processing logic.
51
- Returns a safe error dict instead of raising, so /face never returns 500.
52
- """
53
- try:
54
- analyser = get_analyser()
55
- # TODO: decode image from data["image_b64"], run analyser.get(img), etc.
56
- return {"status": "ready", "faces_detected": "processing"}
57
- except Exception as exc:
58
- return {"error": str(exc)}