Spaces:
Runtime error
Runtime error
update
Browse files
app.py
CHANGED
@@ -12,20 +12,25 @@ dataset = load_dataset("Segizu/dataset_faces", download_config=download_config)
|
|
12 |
if "train" in dataset:
|
13 |
dataset = dataset["train"]
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
# 📦 Construir base de datos de embeddings
|
16 |
def build_database():
|
17 |
database = []
|
18 |
for i, item in enumerate(dataset):
|
19 |
try:
|
20 |
img = item["image"]
|
21 |
-
|
22 |
-
img_np = np.array(img_rgb)
|
23 |
embedding = DeepFace.represent(
|
24 |
-
img_path=
|
25 |
model_name="Facenet",
|
26 |
enforce_detection=False
|
27 |
)[0]["embedding"]
|
28 |
-
database.append((f"image_{i}",
|
29 |
except Exception as e:
|
30 |
print(f"❌ No se pudo procesar imagen {i}: {e}")
|
31 |
return database
|
@@ -33,9 +38,9 @@ def build_database():
|
|
33 |
# 🔍 Buscar rostros similares
|
34 |
def find_similar_faces(uploaded_image):
|
35 |
try:
|
36 |
-
|
37 |
query_embedding = DeepFace.represent(
|
38 |
-
img_path=
|
39 |
model_name="Facenet",
|
40 |
enforce_detection=False
|
41 |
)[0]["embedding"]
|
|
|
12 |
if "train" in dataset:
|
13 |
dataset = dataset["train"]
|
14 |
|
15 |
+
# 🔄 Preprocesar imagen para Facenet
|
16 |
+
def preprocess_image(img):
|
17 |
+
img_rgb = img.convert("RGB")
|
18 |
+
img_resized = img_rgb.resize((160, 160), Image.Resampling.LANCZOS)
|
19 |
+
return np.array(img_resized)
|
20 |
+
|
21 |
# 📦 Construir base de datos de embeddings
|
22 |
def build_database():
|
23 |
database = []
|
24 |
for i, item in enumerate(dataset):
|
25 |
try:
|
26 |
img = item["image"]
|
27 |
+
img_processed = preprocess_image(img)
|
|
|
28 |
embedding = DeepFace.represent(
|
29 |
+
img_path=img_processed,
|
30 |
model_name="Facenet",
|
31 |
enforce_detection=False
|
32 |
)[0]["embedding"]
|
33 |
+
database.append((f"image_{i}", img, embedding))
|
34 |
except Exception as e:
|
35 |
print(f"❌ No se pudo procesar imagen {i}: {e}")
|
36 |
return database
|
|
|
38 |
# 🔍 Buscar rostros similares
|
39 |
def find_similar_faces(uploaded_image):
|
40 |
try:
|
41 |
+
img_processed = preprocess_image(uploaded_image)
|
42 |
query_embedding = DeepFace.represent(
|
43 |
+
img_path=img_processed,
|
44 |
model_name="Facenet",
|
45 |
enforce_detection=False
|
46 |
)[0]["embedding"]
|