Spaces:
Running
on
Zero
Running
on
Zero
primer commit con imagenes
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +1 -0
- app.py +81 -3
- dataset_faces/FR_mmlaceja2024_1_24126995-5b39-4547-b358-e5b7cf0fa0d2_558 (1).jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_24126995-5b39-4547-b358-e5b7cf0fa0d2_558.jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_24126995-5b39-4547-b358-e5b7cf0fa0d2_560.jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_26e8e190-8144-4aea-9296-0440eebb3a29_2880.jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_26e8e190-8144-4aea-9296-0440eebb3a29_2881.jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_26e8e190-8144-4aea-9296-0440eebb3a29_2882.jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_26e8e190-8144-4aea-9296-0440eebb3a29_2884.jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_29ffa06c-9b8d-4792-a394-b16077b5b79d_1685 (1).jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_29ffa06c-9b8d-4792-a394-b16077b5b79d_1685.jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_29ffa06c-9b8d-4792-a394-b16077b5b79d_1686.jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_29ffa06c-9b8d-4792-a394-b16077b5b79d_1688 (1).jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_29ffa06c-9b8d-4792-a394-b16077b5b79d_1688.jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_29ffa06c-9b8d-4792-a394-b16077b5b79d_765 (1).jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_29ffa06c-9b8d-4792-a394-b16077b5b79d_765.jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_58c03ce4-a06f-44c9-82d4-305bc8cc9058_2167.jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_58c03ce4-a06f-44c9-82d4-305bc8cc9058_2219.jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_58c03ce4-a06f-44c9-82d4-305bc8cc9058_2221.jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_58c03ce4-a06f-44c9-82d4-305bc8cc9058_2224 (1).jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_58c03ce4-a06f-44c9-82d4-305bc8cc9058_2224.jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_58c03ce4-a06f-44c9-82d4-305bc8cc9058_2226.jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_58c03ce4-a06f-44c9-82d4-305bc8cc9058_415 (1).jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_58c03ce4-a06f-44c9-82d4-305bc8cc9058_415.jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_91e3fecd-ca72-4331-b034-10b70dd3f6a8_1947 (1).jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_91e3fecd-ca72-4331-b034-10b70dd3f6a8_1947.jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_91e3fecd-ca72-4331-b034-10b70dd3f6a8_1948.jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_91e3fecd-ca72-4331-b034-10b70dd3f6a8_3964.jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_91e3fecd-ca72-4331-b034-10b70dd3f6a8_3965.jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_9696544d-e89d-4ea9-a2c4-9232436ef6b8_820.jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_bcccd5e9-926e-4720-b22d-9a6ba96efdcd_1800.jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_bcccd5e9-926e-4720-b22d-9a6ba96efdcd_1802 (1).jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_bcccd5e9-926e-4720-b22d-9a6ba96efdcd_1802.jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_bcccd5e9-926e-4720-b22d-9a6ba96efdcd_1957 (1).jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_bcccd5e9-926e-4720-b22d-9a6ba96efdcd_1957.jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_bcccd5e9-926e-4720-b22d-9a6ba96efdcd_3225 (1).jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_bcccd5e9-926e-4720-b22d-9a6ba96efdcd_3225.jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_bfb46f55-ec2d-40ca-a131-4161f1bb8f81_1492.jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_bfb46f55-ec2d-40ca-a131-4161f1bb8f81_320 (1).jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_bfb46f55-ec2d-40ca-a131-4161f1bb8f81_320.jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_bfb46f55-ec2d-40ca-a131-4161f1bb8f81_322.jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_e44f9374-6c5c-4493-8bfd-1141d175b401_1615.jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_e44f9374-6c5c-4493-8bfd-1141d175b401_1616 (1).jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_e44f9374-6c5c-4493-8bfd-1141d175b401_1616.jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_e44f9374-6c5c-4493-8bfd-1141d175b401_1794 (1).jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_e44f9374-6c5c-4493-8bfd-1141d175b401_1794 (2).jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_e44f9374-6c5c-4493-8bfd-1141d175b401_1794.jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_e466d074-71e7-4229-b4d1-e1d04d0a3ac8_55.jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_eb74f9d8-5282-48fd-bfbd-d49b0d0101ed_1016.jpg +3 -0
- dataset_faces/FR_mmlaceja2024_1_eb74f9d8-5282-48fd-bfbd-d49b0d0101ed_1020.jpg +3 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ 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 |
+
*.jpg filter=lfs diff=lfs merge=lfs -text
|
app.py
CHANGED
@@ -1,7 +1,85 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
7 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import face_recognition
|
3 |
+
import numpy as np
|
4 |
+
import os
|
5 |
+
from PIL import Image
|
6 |
+
import dlib
|
7 |
|
8 |
+
# Verificar si CUDA está disponible y seleccionar el modelo adecuado
|
9 |
+
if dlib.DLIB_USE_CUDA:
|
10 |
+
print("✅ CUDA está disponible. Se usará GPU para reconocimiento facial.")
|
11 |
+
model_used = "cnn" # Modelo optimizado para GPU
|
12 |
+
else:
|
13 |
+
print("⚠ CUDA no está disponible. Se usará CPU para reconocimiento facial.")
|
14 |
+
model_used = "hog" # Modelo más adecuado para CPU
|
15 |
+
|
16 |
+
# 📂 Directorio donde se encuentran las imágenes
|
17 |
+
IMAGE_DIRECTORY = "dataset_faces/"
|
18 |
+
|
19 |
+
def load_images_and_encodings(directory):
|
20 |
+
"""
|
21 |
+
Carga las imágenes y extrae sus embeddings.
|
22 |
+
"""
|
23 |
+
known_encodings = []
|
24 |
+
known_images = []
|
25 |
+
known_names = []
|
26 |
+
|
27 |
+
for filename in os.listdir(directory):
|
28 |
+
if filename.lower().endswith((".jpg", ".png", ".jpeg")):
|
29 |
+
path = os.path.join(directory, filename)
|
30 |
+
image = face_recognition.load_image_file(path)
|
31 |
+
encodings = face_recognition.face_encodings(image, model=model_used)
|
32 |
+
if encodings: # Si se detecta al menos una cara
|
33 |
+
known_encodings.append(encodings[0])
|
34 |
+
known_images.append(path)
|
35 |
+
known_names.append(filename)
|
36 |
+
return known_encodings, known_images, known_names
|
37 |
+
|
38 |
+
# Cargar los datos de la carpeta de imágenes
|
39 |
+
known_encodings, known_images, known_names = load_images_and_encodings(IMAGE_DIRECTORY)
|
40 |
+
|
41 |
+
def find_similar_faces_gradio(uploaded_image):
|
42 |
+
"""
|
43 |
+
Dada una imagen subida, busca las imágenes similares del dataset.
|
44 |
+
Devuelve una lista de diccionarios para la galería y un texto con detalles.
|
45 |
+
"""
|
46 |
+
if uploaded_image is None:
|
47 |
+
return [], "No se subió ninguna imagen."
|
48 |
+
|
49 |
+
# Convertir la imagen subida a array de NumPy
|
50 |
+
image_np = np.array(uploaded_image)
|
51 |
+
face_encodings = face_recognition.face_encodings(image_np, model=model_used)
|
52 |
+
if not face_encodings:
|
53 |
+
return [], "⚠ No se detectó ningún rostro en la imagen subida."
|
54 |
+
|
55 |
+
query_encoding = face_encodings[0]
|
56 |
+
distances = face_recognition.face_distance(known_encodings, query_encoding)
|
57 |
+
sorted_indices = np.argsort(distances) # Ordenar por similitud (menor distancia = mayor similitud)
|
58 |
+
|
59 |
+
# Mostrar las 5 imágenes más similares
|
60 |
+
top_n = 5
|
61 |
+
gallery_items = []
|
62 |
+
details = ""
|
63 |
+
for idx in sorted_indices[:top_n]:
|
64 |
+
# Abrir la imagen del dataset
|
65 |
+
img = Image.open(known_images[idx])
|
66 |
+
similarity = 1 - distances[idx] # Definir similitud (valor entre 0 y 1)
|
67 |
+
caption = f"{os.path.basename(known_images[idx])}: Similitud: {similarity:.2f}"
|
68 |
+
gallery_items.append({"image": img, "caption": caption})
|
69 |
+
details += caption + "\n"
|
70 |
+
|
71 |
+
return gallery_items, details
|
72 |
+
|
73 |
+
# Definir la interfaz con Gradio
|
74 |
+
demo = gr.Interface(
|
75 |
+
fn=find_similar_faces_gradio,
|
76 |
+
inputs=gr.Image(label="Sube una imagen", type="pil"),
|
77 |
+
outputs=[
|
78 |
+
gr.Gallery(label="Imágenes similares").style(grid=[2], height="auto"),
|
79 |
+
gr.Textbox(label="Detalles de similitud", lines=5)
|
80 |
+
],
|
81 |
+
title="🔍 Buscador de Rostros en un Directorio",
|
82 |
+
description="Sube una imagen y se mostrarán las fotos más similares del directorio."
|
83 |
+
)
|
84 |
|
|
|
85 |
demo.launch()
|
dataset_faces/FR_mmlaceja2024_1_24126995-5b39-4547-b358-e5b7cf0fa0d2_558 (1).jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_24126995-5b39-4547-b358-e5b7cf0fa0d2_558.jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_24126995-5b39-4547-b358-e5b7cf0fa0d2_560.jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_26e8e190-8144-4aea-9296-0440eebb3a29_2880.jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_26e8e190-8144-4aea-9296-0440eebb3a29_2881.jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_26e8e190-8144-4aea-9296-0440eebb3a29_2882.jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_26e8e190-8144-4aea-9296-0440eebb3a29_2884.jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_29ffa06c-9b8d-4792-a394-b16077b5b79d_1685 (1).jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_29ffa06c-9b8d-4792-a394-b16077b5b79d_1685.jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_29ffa06c-9b8d-4792-a394-b16077b5b79d_1686.jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_29ffa06c-9b8d-4792-a394-b16077b5b79d_1688 (1).jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_29ffa06c-9b8d-4792-a394-b16077b5b79d_1688.jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_29ffa06c-9b8d-4792-a394-b16077b5b79d_765 (1).jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_29ffa06c-9b8d-4792-a394-b16077b5b79d_765.jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_58c03ce4-a06f-44c9-82d4-305bc8cc9058_2167.jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_58c03ce4-a06f-44c9-82d4-305bc8cc9058_2219.jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_58c03ce4-a06f-44c9-82d4-305bc8cc9058_2221.jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_58c03ce4-a06f-44c9-82d4-305bc8cc9058_2224 (1).jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_58c03ce4-a06f-44c9-82d4-305bc8cc9058_2224.jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_58c03ce4-a06f-44c9-82d4-305bc8cc9058_2226.jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_58c03ce4-a06f-44c9-82d4-305bc8cc9058_415 (1).jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_58c03ce4-a06f-44c9-82d4-305bc8cc9058_415.jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_91e3fecd-ca72-4331-b034-10b70dd3f6a8_1947 (1).jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_91e3fecd-ca72-4331-b034-10b70dd3f6a8_1947.jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_91e3fecd-ca72-4331-b034-10b70dd3f6a8_1948.jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_91e3fecd-ca72-4331-b034-10b70dd3f6a8_3964.jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_91e3fecd-ca72-4331-b034-10b70dd3f6a8_3965.jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_9696544d-e89d-4ea9-a2c4-9232436ef6b8_820.jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_bcccd5e9-926e-4720-b22d-9a6ba96efdcd_1800.jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_bcccd5e9-926e-4720-b22d-9a6ba96efdcd_1802 (1).jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_bcccd5e9-926e-4720-b22d-9a6ba96efdcd_1802.jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_bcccd5e9-926e-4720-b22d-9a6ba96efdcd_1957 (1).jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_bcccd5e9-926e-4720-b22d-9a6ba96efdcd_1957.jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_bcccd5e9-926e-4720-b22d-9a6ba96efdcd_3225 (1).jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_bcccd5e9-926e-4720-b22d-9a6ba96efdcd_3225.jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_bfb46f55-ec2d-40ca-a131-4161f1bb8f81_1492.jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_bfb46f55-ec2d-40ca-a131-4161f1bb8f81_320 (1).jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_bfb46f55-ec2d-40ca-a131-4161f1bb8f81_320.jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_bfb46f55-ec2d-40ca-a131-4161f1bb8f81_322.jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_e44f9374-6c5c-4493-8bfd-1141d175b401_1615.jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_e44f9374-6c5c-4493-8bfd-1141d175b401_1616 (1).jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_e44f9374-6c5c-4493-8bfd-1141d175b401_1616.jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_e44f9374-6c5c-4493-8bfd-1141d175b401_1794 (1).jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_e44f9374-6c5c-4493-8bfd-1141d175b401_1794 (2).jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_e44f9374-6c5c-4493-8bfd-1141d175b401_1794.jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_e466d074-71e7-4229-b4d1-e1d04d0a3ac8_55.jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_eb74f9d8-5282-48fd-bfbd-d49b0d0101ed_1016.jpg
ADDED
![]() |
Git LFS Details
|
dataset_faces/FR_mmlaceja2024_1_eb74f9d8-5282-48fd-bfbd-d49b0d0101ed_1020.jpg
ADDED
![]() |
Git LFS Details
|