Spaces:
Running
Running
Alief Gilang Permana Putra commited on
Commit ·
3e534ec
1
Parent(s): 60c0cc3
fix: check tflite model and download if doesn't exist
Browse files
services/__pycache__/face_extractor.cpython-314.pyc
ADDED
|
Binary file (4.9 kB). View file
|
|
|
services/face_extractor.py
CHANGED
|
@@ -5,6 +5,7 @@ import mediapipe as mp
|
|
| 5 |
from mediapipe.tasks import python
|
| 6 |
from mediapipe.tasks.python import vision
|
| 7 |
import os
|
|
|
|
| 8 |
|
| 9 |
class FaceExtractor:
|
| 10 |
def __init__(self, model_path: str = None):
|
|
@@ -15,6 +16,14 @@ class FaceExtractor:
|
|
| 15 |
else:
|
| 16 |
self.model_path = model_path
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
base_options = python.BaseOptions(model_asset_path=self.model_path)
|
| 19 |
options = vision.FaceDetectorOptions(
|
| 20 |
base_options=base_options,
|
|
|
|
| 5 |
from mediapipe.tasks import python
|
| 6 |
from mediapipe.tasks.python import vision
|
| 7 |
import os
|
| 8 |
+
import urllib.request
|
| 9 |
|
| 10 |
class FaceExtractor:
|
| 11 |
def __init__(self, model_path: str = None):
|
|
|
|
| 16 |
else:
|
| 17 |
self.model_path = model_path
|
| 18 |
|
| 19 |
+
# Bulletproof check: Ensure the file exists and is a valid binary (not a Git LFS pointer)
|
| 20 |
+
if not os.path.exists(self.model_path) or os.path.getsize(self.model_path) < 2000:
|
| 21 |
+
print(f"Valid model not found at {self.model_path}. Auto-downloading...")
|
| 22 |
+
os.makedirs(os.path.dirname(self.model_path), exist_ok=True)
|
| 23 |
+
url = "https://storage.googleapis.com/mediapipe-models/face_detector/blaze_face_short_range/float16/latest/blaze_face_short_range.tflite"
|
| 24 |
+
urllib.request.urlretrieve(url, self.model_path)
|
| 25 |
+
print("Download complete.")
|
| 26 |
+
|
| 27 |
base_options = python.BaseOptions(model_asset_path=self.model_path)
|
| 28 |
options = vision.FaceDetectorOptions(
|
| 29 |
base_options=base_options,
|