psinha823 commited on
Commit
b3ddd7a
·
verified ·
1 Parent(s): 6b0fbd1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -8
app.py CHANGED
@@ -108,6 +108,7 @@ from tensorflow.keras.preprocessing import image as keras_image
108
  from PIL import Image
109
  import numpy as np
110
  import logging
 
111
 
112
  # Set up logging
113
  logging.basicConfig(level=logging.DEBUG)
@@ -115,14 +116,24 @@ logging.basicConfig(level=logging.DEBUG)
115
  # Initialize the model variable
116
  model = None
117
 
118
- # Load the trained model
119
- try:
120
- model_path = './model1_kera.h5' # Replace with the actual path to your model file
121
- logging.info(f"Loading model from: {model_path}")
122
- model = tf.keras.models.load_model(model_path)
123
- logging.info("Model loaded successfully.")
124
- except Exception as e:
125
- logging.error(f"Error loading model: {e}")
 
 
 
 
 
 
 
 
 
 
126
 
127
  # Define the class names
128
  classes = ['Colon Adenocarcinoma', 'Colon Benign Tissue', 'Lung Adenocarcinoma', 'Lung Benign Tissue', 'Lung Squamous Cell Carcinoma']
 
108
  from PIL import Image
109
  import numpy as np
110
  import logging
111
+ import os
112
 
113
  # Set up logging
114
  logging.basicConfig(level=logging.DEBUG)
 
116
  # Initialize the model variable
117
  model = None
118
 
119
+ # Function to load the model
120
+ def load_model():
121
+ global model
122
+ model_path = 'path/to/your/model.h5' # Replace with the actual path to your model file
123
+ if not os.path.exists(model_path):
124
+ logging.error(f"Model file does not exist at path: {model_path}")
125
+ return False
126
+ try:
127
+ logging.info(f"Loading model from: {model_path}")
128
+ model = tf.keras.models.load_model(model_path)
129
+ logging.info("Model loaded successfully.")
130
+ return True
131
+ except Exception as e:
132
+ logging.error(f"Error loading model: {e}")
133
+ return False
134
+
135
+ # Load the model when the script starts
136
+ model_loaded = load_model()
137
 
138
  # Define the class names
139
  classes = ['Colon Adenocarcinoma', 'Colon Benign Tissue', 'Lung Adenocarcinoma', 'Lung Benign Tissue', 'Lung Squamous Cell Carcinoma']