ViannyCruz commited on
Commit
0c8c5a5
·
verified ·
1 Parent(s): d3f142b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -23
app.py CHANGED
@@ -721,9 +721,8 @@ def debug():
721
  'db_exists': os.path.exists(db.db_path),
722
  'users': [dict(u) for u in users],
723
  'model_loaded': model is not None,
724
- 'model_error': _model_error,
725
- 'model_thread_alive': _model_thread.is_alive(),
726
- 'h5_files': [f for f in os.listdir('/app') if f.endswith('.h5')]
727
  })
728
  except Exception as e:
729
  return jsonify({'error': str(e), 'db_path': db.db_path})
@@ -732,28 +731,12 @@ def debug():
732
  # ------------------------------------------------------------------ #
733
  # ARRANQUE
734
  # ------------------------------------------------------------------ #
735
- # Cargar modelo en background al arrancar
736
- import threading
737
 
738
- _model_error = None
739
 
740
- def _load_model_background():
741
- global _model_error
742
- print("Iniciando carga de modelo en background...")
743
- try:
744
- result = load_model()
745
- if result:
746
- print("Modelo cargado exitosamente en background")
747
- else:
748
- _model_error = "load_model() retornó False — ver logs del servidor"
749
- print(_model_error)
750
- except Exception as e:
751
- import traceback
752
- _model_error = traceback.format_exc()
753
- print(f"Error cargando modelo en background: {_model_error}")
754
-
755
- _model_thread = threading.Thread(target=_load_model_background, daemon=True)
756
- _model_thread.start()
757
 
758
  if __name__ == '__main__':
759
  port = int(os.environ.get('PORT', 7860))
 
721
  'db_exists': os.path.exists(db.db_path),
722
  'users': [dict(u) for u in users],
723
  'model_loaded': model is not None,
724
+ 'h5_files': [f for f in os.listdir(os.path.dirname(os.path.abspath(__file__))) if f.endswith('.h5')],
725
+ 'app_dir': os.path.dirname(os.path.abspath(__file__))
 
726
  })
727
  except Exception as e:
728
  return jsonify({'error': str(e), 'db_path': db.db_path})
 
731
  # ------------------------------------------------------------------ #
732
  # ARRANQUE
733
  # ------------------------------------------------------------------ #
 
 
734
 
 
735
 
736
+ # Cargar modelo al importar el módulo (funciona con gunicorn)
737
+ print("=== Cargando modelo TensorFlow ===")
738
+ load_model()
739
+ print(f"=== Modelo {'CARGADO' if model is not None else 'NO CARGADO'} ===")
 
 
 
 
 
 
 
 
 
 
 
 
 
740
 
741
  if __name__ == '__main__':
742
  port = int(os.environ.get('PORT', 7860))