Yash goyal commited on
Commit
a96caf4
·
verified ·
1 Parent(s): 514b92b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -2
app.py CHANGED
@@ -157,7 +157,11 @@ model = None
157
  try:
158
  if os.path.exists(MODEL_PATH):
159
  logger.info("Loading model from %s", MODEL_PATH)
160
- model = tf.keras.models.load_model(MODEL_PATH)
 
 
 
 
161
  else:
162
  logger.error("Model file %s not found", MODEL_PATH)
163
  raise FileNotFoundError(f"Model file {MODEL_PATH} not found")
@@ -337,7 +341,7 @@ def home():
337
  return render_template("form.html", history_plot=None, result={
338
  "prediction": "Error",
339
  "confidence": "N/A",
340
- "message": "Failed to load page. Please try again.",
341
  "email_status": "N/A"
342
  })
343
 
@@ -438,6 +442,8 @@ def email_report(scan_id):
438
  @app.route("/predict", methods=["POST"])
439
  def predict():
440
  try:
 
 
441
  if "image" not in request.files:
442
  raise ValueError("No image uploaded.")
443
  image = request.files["image"]
 
157
  try:
158
  if os.path.exists(MODEL_PATH):
159
  logger.info("Loading model from %s", MODEL_PATH)
160
+ try:
161
+ model = tf.keras.models.load_model(MODEL_PATH, compile=False)
162
+ except Exception as e:
163
+ logger.error("Failed to deserialize model: %s", str(e))
164
+ raise ValueError(f"Model deserialization error: {str(e)}. Please ensure the model is compatible with TensorFlow 2.15.0 or re-save it.")
165
  else:
166
  logger.error("Model file %s not found", MODEL_PATH)
167
  raise FileNotFoundError(f"Model file {MODEL_PATH} not found")
 
341
  return render_template("form.html", history_plot=None, result={
342
  "prediction": "Error",
343
  "confidence": "N/A",
344
+ "message": f"Failed to load page: {str(e)}",
345
  "email_status": "N/A"
346
  })
347
 
 
442
  @app.route("/predict", methods=["POST"])
443
  def predict():
444
  try:
445
+ if not model:
446
+ raise ValueError("Model not loaded, cannot make predictions")
447
  if "image" not in request.files:
448
  raise ValueError("No image uploaded.")
449
  image = request.files["image"]