cristopher.salyrosas commited on
Commit
d2ff8ac
·
1 Parent(s): 7177408

AppIAIntegrationFix

Browse files
Files changed (2) hide show
  1. app.py +28 -5
  2. facial_auth.py +1 -1
app.py CHANGED
@@ -14,10 +14,22 @@ import numpy as np
14
  import time
15
  import tempfile
16
  import os
17
- import torch
18
- os.environ["CUDA_VISIBLE_DEVICES"] = "-1" # Previene Segmentation Fault por choque entre TF y PyTorch en la nube
 
19
  os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
20
 
 
 
 
 
 
 
 
 
 
 
 
21
  from pathlib import Path
22
  from datetime import datetime
23
 
@@ -977,12 +989,12 @@ if st.session_state.running:
977
  if detector.model:
978
  pass # la confianza se pasa en detect()
979
 
980
- # Detección de personas
981
- detections = detector.detect(frame)
982
 
983
  # Evaluación de reglas
984
  alerts, events = rules_engine.evaluate(detections)
985
- has_alert = any(alerts)
986
  st.session_state.alert_active = has_alert
987
 
988
  # Dibujar anotaciones
@@ -990,6 +1002,7 @@ if st.session_state.running:
990
  frame, detections, alerts,
991
  zone=zone_px, zone_active=True,
992
  draw_skeleton=show_skeleton,
 
993
  )
994
 
995
  # Mostrar frame
@@ -1020,6 +1033,16 @@ if st.session_state.running:
1020
  captura =cap_path,
1021
  detalle =event.get("detalle", ""),
1022
  )
 
 
 
 
 
 
 
 
 
 
1023
 
1024
  # ── Panel derecho: estado en vivo ─────────────────────────────
1025
  with live_status.container():
 
14
  import time
15
  import tempfile
16
  import os
17
+
18
+ # Prevenir crash silencioso de OpenMP al mezclar PyTorch y TensorFlow en Windows
19
+ os.environ["KMP_DUPLICATE_LIB_OK"] = "True"
20
  os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
21
 
22
+ # Configurar TensorFlow para compartir la GPU de forma amigable con PyTorch
23
+ import tensorflow as tf
24
+ import torch
25
+ gpus = tf.config.list_physical_devices('GPU')
26
+ if gpus:
27
+ try:
28
+ for gpu in gpus:
29
+ tf.config.experimental.set_memory_growth(gpu, True)
30
+ except RuntimeError as e:
31
+ print(e)
32
+
33
  from pathlib import Path
34
  from datetime import datetime
35
 
 
989
  if detector.model:
990
  pass # la confianza se pasa en detect()
991
 
992
+ # Detección de personas y anomalías
993
+ detections, anomaly_info = detector.detect(frame)
994
 
995
  # Evaluación de reglas
996
  alerts, events = rules_engine.evaluate(detections)
997
+ has_alert = any(alerts) or anomaly_info is not None
998
  st.session_state.alert_active = has_alert
999
 
1000
  # Dibujar anotaciones
 
1002
  frame, detections, alerts,
1003
  zone=zone_px, zone_active=True,
1004
  draw_skeleton=show_skeleton,
1005
+ anomaly_info=anomaly_info
1006
  )
1007
 
1008
  # Mostrar frame
 
1033
  captura =cap_path,
1034
  detalle =event.get("detalle", ""),
1035
  )
1036
+
1037
+ # Registrar evento de anomalía si se detecta
1038
+ if anomaly_info is not None:
1039
+ insert_event(
1040
+ tipo_evento="ANOMALIA_DETECTADA",
1041
+ estado="Alerta Global",
1042
+ duracion=0,
1043
+ captura=cap_path,
1044
+ detalle=f"Se detectó posible crimen: {anomaly_info['class']} (Conf: {anomaly_info['conf']:.0%})",
1045
+ )
1046
 
1047
  # ── Panel derecho: estado en vivo ─────────────────────────────
1048
  with live_status.container():
facial_auth.py CHANGED
@@ -69,7 +69,7 @@ class FacialAuthenticator:
69
  img_path=frame_crop,
70
  db_path=self.db_path,
71
  model_name=self.model_name,
72
- detector_backend="retinaface",
73
  enforce_detection=False,
74
  silent=True
75
  )
 
69
  img_path=frame_crop,
70
  db_path=self.db_path,
71
  model_name=self.model_name,
72
+ detector_backend="opencv",
73
  enforce_detection=False,
74
  silent=True
75
  )