chrisaldikaraharja commited on
Commit
6f6031c
·
verified ·
1 Parent(s): 4efee95

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -26,11 +26,8 @@ def download_model():
26
  # Function to load and save the model in the SavedModel format
27
  def convert_and_save_model(h5_path, save_dir):
28
  try:
29
- # Load the .h5 model without compile=False
30
  model = tf.keras.models.load_model(h5_path)
31
-
32
- # Save the model in .keras format
33
- model.save(save_dir) # No need to specify save_format
34
  st.success(f"Model saved in .keras format at '{save_dir}'.")
35
  return model
36
  except Exception as e:
@@ -47,14 +44,20 @@ def load_saved_model(saved_model_path):
47
  return None
48
 
49
  # Download the model if not already done
 
50
  download_model()
51
 
52
- # Convert and save the model to avoid deserialization issues
53
  if not os.path.exists(saved_model_dir):
54
  model = convert_and_save_model(local_h5_path, saved_model_dir)
55
  else:
56
  model = load_saved_model(saved_model_dir)
57
 
 
 
 
 
 
58
  # Define the class labels
59
  label_map = {0: 'Glioma', 1: 'Meningioma', 2: 'Normal', 3: 'Pituitary'}
60
 
 
26
  # Function to load and save the model in the SavedModel format
27
  def convert_and_save_model(h5_path, save_dir):
28
  try:
 
29
  model = tf.keras.models.load_model(h5_path)
30
+ model.save(save_dir) # Save in .keras format
 
 
31
  st.success(f"Model saved in .keras format at '{save_dir}'.")
32
  return model
33
  except Exception as e:
 
44
  return None
45
 
46
  # Download the model if not already done
47
+ # Check if the model is being downloaded and saved correctly
48
  download_model()
49
 
50
+ # Convert and save the model if it doesn't exist
51
  if not os.path.exists(saved_model_dir):
52
  model = convert_and_save_model(local_h5_path, saved_model_dir)
53
  else:
54
  model = load_saved_model(saved_model_dir)
55
 
56
+ # Check if the model was loaded successfully
57
+ if model is None:
58
+ st.error("Failed to load the model. Please check the model file.")
59
+ else:
60
+ st.success("Model loaded successfully.")
61
  # Define the class labels
62
  label_map = {0: 'Glioma', 1: 'Meningioma', 2: 'Normal', 3: 'Pituitary'}
63