cristopher.salyrosas commited on
Commit
28afd5d
·
1 Parent(s): bb93518
Files changed (1) hide show
  1. app.py +16 -13
app.py CHANGED
@@ -24,27 +24,30 @@ else:
24
  # En local (Windows): Permitir el uso de la GPU (RTX 3060) y prevenir crash silencioso de OpenMP
25
  os.environ["KMP_DUPLICATE_LIB_OK"] = "True"
26
 
 
 
 
 
 
 
27
  import streamlit as st
28
  import cv2
29
  import numpy as np
30
  import time
31
  import tempfile
32
 
33
- import tensorflow as tf
34
- import torch
35
-
36
  if sys.platform.startswith("linux"):
37
- torch.set_num_threads(1)
38
  cv2.setNumThreads(1)
39
-
40
- # Configurar TensorFlow para compartir la GPU de forma amigable con PyTorch (solo útil en local)
41
- gpus = tf.config.list_physical_devices('GPU')
42
- if gpus:
43
- try:
44
- for gpu in gpus:
45
- tf.config.experimental.set_memory_growth(gpu, True)
46
- except RuntimeError as e:
47
- print(e)
 
48
 
49
  from pathlib import Path
50
  from datetime import datetime
 
24
  # En local (Windows): Permitir el uso de la GPU (RTX 3060) y prevenir crash silencioso de OpenMP
25
  os.environ["KMP_DUPLICATE_LIB_OK"] = "True"
26
 
27
+ # CRÍTICO: Importar torch ANTES que streamlit, cv2 o tensorflow para evitar Segmentation Fault en Linux
28
+ import torch
29
+
30
+ if sys.platform.startswith("linux"):
31
+ torch.set_num_threads(1)
32
+
33
  import streamlit as st
34
  import cv2
35
  import numpy as np
36
  import time
37
  import tempfile
38
 
 
 
 
39
  if sys.platform.startswith("linux"):
 
40
  cv2.setNumThreads(1)
41
+ else:
42
+ # Configurar TensorFlow para compartir la GPU de forma amigable con PyTorch (solo útil en local)
43
+ import tensorflow as tf
44
+ gpus = tf.config.list_physical_devices('GPU')
45
+ if gpus:
46
+ try:
47
+ for gpu in gpus:
48
+ tf.config.experimental.set_memory_growth(gpu, True)
49
+ except RuntimeError as e:
50
+ print(e)
51
 
52
  from pathlib import Path
53
  from datetime import datetime