koesan commited on
Commit
1e1e4e2
·
verified ·
1 Parent(s): 7d2dfc0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -2
app.py CHANGED
@@ -13,9 +13,21 @@ app.config['UPLOAD_FOLDER'] = 'uploads'
13
  # Create uploads folder if it doesn't exist
14
  os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
15
 
16
- # Load the model
17
  print("Loading model...")
18
- model = load_model('cancer_model.h5', compile=False)
 
 
 
 
 
 
 
 
 
 
 
 
19
  print("Model loaded successfully!")
20
 
21
  def resize_with_padding(img, target_size):
 
13
  # Create uploads folder if it doesn't exist
14
  os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
15
 
16
+ # Load the model with custom objects to handle compatibility
17
  print("Loading model...")
18
+ import warnings
19
+ warnings.filterwarnings('ignore')
20
+
21
+ # Custom loader for compatibility with different TensorFlow versions
22
+ try:
23
+ model = load_model('cancer_model.h5', compile=False)
24
+ except Exception as e:
25
+ print(f"First attempt failed: {e}")
26
+ print("Trying with safe mode...")
27
+ # Try loading with safe mode
28
+ from tensorflow import keras
29
+ model = keras.models.load_model('cancer_model.h5', compile=False, safe_mode=False)
30
+
31
  print("Model loaded successfully!")
32
 
33
  def resize_with_padding(img, target_size):