Skip to content

Commit 18c0428

Browse files
committed
logging
1 parent f8643b4 commit 18c0428

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

app.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import time
77
import requests
88
import os
9+
import logging
910

1011
app = Flask(__name__)
1112

@@ -15,16 +16,14 @@ def load_model():
1516
try:
1617
MODEL = keras.models.load_model('/model/keras_model.h5', compile=False)
1718
CLASS_NAMES = open("/model/labels.txt", "r").read().splitlines()
18-
print("Modello caricato con successo")
19+
logging.info("Modello caricato con successo")
1920
except Exception as e:
20-
print(f"Errore nel caricamento del modello: {e}")
21+
logging.error(f"Errore nel caricamento del modello: {e}")
2122
MODEL = None
2223
CLASS_NAMES = []
2324

24-
load_model()
25-
2625
def download_image(url: str, token: str = None, dest_dir: str = './tmp'):
27-
print("scarico l'immagine da:", url)
26+
logging.info("Scarico l'immagine da: %s", url)
2827
os.makedirs(dest_dir, exist_ok=True)
2928
if token:
3029
sep = '&' if '?' in url else '?'
@@ -82,19 +81,27 @@ def predict():
8281
"confidenza": confidence,
8382
"probabilita_complete": scores
8483
}
84+
logging.info("Predizione completata con successo")
8585
return jsonify(response)
8686
except requests.RequestException as e:
87+
logging.error("Errore download immagine: %s", e)
8788
return jsonify({"error": f"Errore download immagine: {e}"}), 400
8889
except Exception as e:
90+
logging.error("Errore durante la predizione: %s", e)
8991
return jsonify({"error": f"Errore durante la predizione: {e}"}), 500
9092
finally:
9193
if tmp_file and os.path.isfile(tmp_file):
9294
try:
9395
os.remove(tmp_file)
9496
except Exception:
97+
logging.error("Errore durante la rimozione del file temporaneo: %s", tmp_file)
9598
pass
9699

100+
101+
load_model()
102+
97103
if __name__ == '__main__':
98104
# Usare un server WSGI come Gunicorn per la produzione
99105
# Qui usiamo la modalità debug di Flask per semplicità
106+
logging.info("Avvio dell'app Flask")
100107
app.run(debug=True, host='0.0.0.0', port=5000)

0 commit comments

Comments
 (0)