Segizu commited on
Commit
55948dc
·
1 Parent(s): 97364cf
Files changed (2) hide show
  1. app.py +3 -4
  2. metadata.py +40 -0
app.py CHANGED
@@ -19,13 +19,12 @@ EMBEDDINGS_DIR.mkdir(exist_ok=True)
19
  EMBEDDINGS_FILE = EMBEDDINGS_DIR / "embeddings.pkl"
20
 
21
  # ✅ Cargar el dataset de Hugging Face con imágenes decodificadas
22
- download_config = DownloadConfig(force_download=True, token=HF_TOKEN)
23
- dataset = load_dataset("Segizu/facial-recognition", download_config=download_config)
24
  if "train" in dataset:
25
  dataset = dataset["train"]
26
 
27
- # Asegurar que la columna 'image' sea del tipo imagen
28
- dataset = dataset.cast_column("image", HfImage())
29
 
30
  # 🔄 Preprocesar imagen para Facenet
31
  def preprocess_image(img: Image.Image) -> np.ndarray:
 
19
  EMBEDDINGS_FILE = EMBEDDINGS_DIR / "embeddings.pkl"
20
 
21
  # ✅ Cargar el dataset de Hugging Face con imágenes decodificadas
22
+ dataset = load_dataset("Segizu/facial-recognition", data_files="metadata.csv", token=HF_TOKEN)
 
23
  if "train" in dataset:
24
  dataset = dataset["train"]
25
 
26
+
27
+ dataset = dataset["train"].cast_column("image", HfImage())
28
 
29
  # 🔄 Preprocesar imagen para Facenet
30
  def preprocess_image(img: Image.Image) -> np.ndarray:
metadata.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from huggingface_hub import HfApi
2
+ import csv
3
+ import os
4
+ from pathlib import Path
5
+
6
+ # 🔐 Configuración segura del token
7
+ HF_TOKEN = os.getenv("HF_TOKEN")
8
+ if not HF_TOKEN:
9
+ raise ValueError("⚠️ Por favor, configura la variable de entorno HF_TOKEN")
10
+
11
+ # 🗂️ Configurar repositorio
12
+ api = HfApi()
13
+ repo_id = "Segizu/facial-recognition"
14
+
15
+ try:
16
+ # ✅ Listar todos los archivos del dataset
17
+ files = api.list_repo_files(repo_id=repo_id, repo_type="dataset", token=HF_TOKEN)
18
+
19
+ # Filtrar imágenes .jpg
20
+ image_files = [f for f in files if f.lower().endswith(".jpg")]
21
+
22
+ # Guardar metadata.csv
23
+ metadata_path = Path("metadata.csv")
24
+ with open(metadata_path, "w", newline="") as f:
25
+ writer = csv.writer(f)
26
+ writer.writerow(["image"])
27
+ for img in image_files:
28
+ writer.writerow([img])
29
+
30
+ print(f"✅ metadata.csv generado con {len(image_files)} imágenes.")
31
+
32
+ except Exception as e:
33
+ print(f"❌ Error: {str(e)}")
34
+ if "401" in str(e):
35
+ print("⚠️ Error de autenticación. Verifica que tu token de Hugging Face sea válido.")
36
+ elif "404" in str(e):
37
+ print("⚠️ No se encontró el repositorio. Verifica que el nombre del repositorio sea correcto.")
38
+ else:
39
+ print("⚠️ Ocurrió un error inesperado.")
40
+