Spaces:
Paused
Paused
Alessandro Piana
commited on
Commit
·
714ed23
1
Parent(s):
65e200e
dockerfile con logging 53
Browse files
app.py
CHANGED
|
@@ -10,7 +10,7 @@ from datetime import datetime
|
|
| 10 |
from flask import Flask, render_template, redirect, url_for, flash, request # AGGIUNTO 'request'
|
| 11 |
from flask_login import LoginManager, current_user
|
| 12 |
import logging
|
| 13 |
-
|
| 14 |
from werkzeug.middleware.proxy_fix import ProxyFix # NUOVA RIGA
|
| 15 |
from flask_cors import CORS
|
| 16 |
|
|
@@ -221,14 +221,14 @@ app.register_blueprint(chat_bp, url_prefix='/chat')
|
|
| 221 |
# ------------------------------------------------------------------
|
| 222 |
# --- NUOVA SEZIONE: PRE-CARICAMENTO MODELLO ASINCRONO (FIX 1) ---
|
| 223 |
# ------------------------------------------------------------------
|
|
|
|
| 224 |
def load_model_on_startup():
|
| 225 |
"""Carica il modello in un thread separato per evitare il blocco del server."""
|
| 226 |
try:
|
| 227 |
# L'app_context è necessario per garantire la sicurezza del DB/Logging
|
| 228 |
-
# in un thread avviato al di fuori del contesto di richiesta.
|
| 229 |
with app.app_context():
|
| 230 |
logger.info("--- PRE-LOAD: Avvio caricamento modello in background...")
|
| 231 |
-
get_life_coach_model() #
|
| 232 |
logger.info("--- PRE-LOAD: Caricamento modello completato.")
|
| 233 |
except Exception as e:
|
| 234 |
logger.error(f"--- PRE-LOAD ERROR: Errore nel caricamento: {e}", exc_info=True)
|
|
|
|
| 10 |
from flask import Flask, render_template, redirect, url_for, flash, request # AGGIUNTO 'request'
|
| 11 |
from flask_login import LoginManager, current_user
|
| 12 |
import logging
|
| 13 |
+
|
| 14 |
from werkzeug.middleware.proxy_fix import ProxyFix # NUOVA RIGA
|
| 15 |
from flask_cors import CORS
|
| 16 |
|
|
|
|
| 221 |
# ------------------------------------------------------------------
|
| 222 |
# --- NUOVA SEZIONE: PRE-CARICAMENTO MODELLO ASINCRONO (FIX 1) ---
|
| 223 |
# ------------------------------------------------------------------
|
| 224 |
+
# Nota: La funzione get_life_coach_model() è già definita in questo file.
|
| 225 |
def load_model_on_startup():
|
| 226 |
"""Carica il modello in un thread separato per evitare il blocco del server."""
|
| 227 |
try:
|
| 228 |
# L'app_context è necessario per garantire la sicurezza del DB/Logging
|
|
|
|
| 229 |
with app.app_context():
|
| 230 |
logger.info("--- PRE-LOAD: Avvio caricamento modello in background...")
|
| 231 |
+
get_life_coach_model() # La funzione che attiva il caricamento lento
|
| 232 |
logger.info("--- PRE-LOAD: Caricamento modello completato.")
|
| 233 |
except Exception as e:
|
| 234 |
logger.error(f"--- PRE-LOAD ERROR: Errore nel caricamento: {e}", exc_info=True)
|