Spaces:
Runtime error
Runtime error
no cache embeddings
Browse files
app.py
CHANGED
@@ -12,10 +12,10 @@ HF_TOKEN = os.getenv("HF_TOKEN")
|
|
12 |
if not HF_TOKEN:
|
13 |
raise ValueError("⚠️ Por favor, configura la variable de entorno HF_TOKEN para acceder al dataset privado")
|
14 |
|
15 |
-
# 📁 Configurar directorio de
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
|
20 |
os.system("rm -rf ~/.cache/huggingface/hub/datasets--Segizu--dataset_faces")
|
21 |
|
@@ -36,10 +36,10 @@ def preprocess_image(img):
|
|
36 |
|
37 |
# 📦 Construir base de datos de embeddings
|
38 |
def build_database():
|
39 |
-
# Intentar cargar embeddings desde
|
40 |
-
if
|
41 |
-
print("📂 Cargando embeddings desde
|
42 |
-
with open(
|
43 |
return pickle.load(f)
|
44 |
|
45 |
print("🔄 Calculando embeddings (esto puede tomar unos minutos)...")
|
@@ -58,9 +58,9 @@ def build_database():
|
|
58 |
except Exception as e:
|
59 |
print(f"❌ No se pudo procesar imagen {i}: {e}")
|
60 |
|
61 |
-
# Guardar embeddings en
|
62 |
-
print("💾 Guardando embeddings en
|
63 |
-
with open(
|
64 |
pickle.dump(database, f)
|
65 |
|
66 |
return database
|
|
|
12 |
if not HF_TOKEN:
|
13 |
raise ValueError("⚠️ Por favor, configura la variable de entorno HF_TOKEN para acceder al dataset privado")
|
14 |
|
15 |
+
# 📁 Configurar directorio de embeddings
|
16 |
+
EMBEDDINGS_DIR = Path("embeddings")
|
17 |
+
EMBEDDINGS_DIR.mkdir(exist_ok=True)
|
18 |
+
EMBEDDINGS_FILE = EMBEDDINGS_DIR / "embeddings.pkl"
|
19 |
|
20 |
os.system("rm -rf ~/.cache/huggingface/hub/datasets--Segizu--dataset_faces")
|
21 |
|
|
|
36 |
|
37 |
# 📦 Construir base de datos de embeddings
|
38 |
def build_database():
|
39 |
+
# Intentar cargar embeddings desde el archivo
|
40 |
+
if EMBEDDINGS_FILE.exists():
|
41 |
+
print("📂 Cargando embeddings desde el archivo...")
|
42 |
+
with open(EMBEDDINGS_FILE, 'rb') as f:
|
43 |
return pickle.load(f)
|
44 |
|
45 |
print("🔄 Calculando embeddings (esto puede tomar unos minutos)...")
|
|
|
58 |
except Exception as e:
|
59 |
print(f"❌ No se pudo procesar imagen {i}: {e}")
|
60 |
|
61 |
+
# Guardar embeddings en el archivo
|
62 |
+
print("💾 Guardando embeddings en el archivo...")
|
63 |
+
with open(EMBEDDINGS_FILE, 'wb') as f:
|
64 |
pickle.dump(database, f)
|
65 |
|
66 |
return database
|