Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,8 +3,13 @@ import cv2
|
|
| 3 |
import numpy as np
|
| 4 |
from flask import Flask, request, render_template, jsonify
|
| 5 |
from werkzeug.utils import secure_filename
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
import tensorflow as tf
|
| 7 |
-
|
|
|
|
| 8 |
|
| 9 |
app = Flask(__name__)
|
| 10 |
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16MB max file size
|
|
@@ -13,26 +18,17 @@ 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 with
|
| 17 |
print("Loading model...")
|
| 18 |
import warnings
|
| 19 |
warnings.filterwarnings('ignore')
|
| 20 |
|
| 21 |
-
# Set TensorFlow to use less memory
|
| 22 |
-
os.environ['TF_FORCE_GPU_ALLOW_GROWTH'] = 'true'
|
| 23 |
-
|
| 24 |
-
# Try loading with h5py directly for better compatibility
|
| 25 |
-
import h5py
|
| 26 |
-
|
| 27 |
-
# Load model - TensorFlow 2.15 should handle it
|
| 28 |
try:
|
| 29 |
-
#
|
| 30 |
-
model =
|
| 31 |
-
print("✓ Model loaded successfully with
|
| 32 |
except Exception as e:
|
| 33 |
-
print(f"Error loading model: {e}")
|
| 34 |
-
print("\n⚠️ If loading fails, the model needs to be re-saved.")
|
| 35 |
-
print("Please run the convert_model.py script provided.")
|
| 36 |
raise
|
| 37 |
|
| 38 |
def resize_with_padding(img, target_size):
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
from flask import Flask, request, render_template, jsonify
|
| 5 |
from werkzeug.utils import secure_filename
|
| 6 |
+
|
| 7 |
+
# Suppress TensorFlow warnings
|
| 8 |
+
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
|
| 9 |
+
|
| 10 |
import tensorflow as tf
|
| 11 |
+
# Use standalone Keras (compatible with old models)
|
| 12 |
+
from keras.models import load_model
|
| 13 |
|
| 14 |
app = Flask(__name__)
|
| 15 |
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16MB max file size
|
|
|
|
| 18 |
# Create uploads folder if it doesn't exist
|
| 19 |
os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
|
| 20 |
|
| 21 |
+
# Load the model with old Keras 2.4.3
|
| 22 |
print("Loading model...")
|
| 23 |
import warnings
|
| 24 |
warnings.filterwarnings('ignore')
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
try:
|
| 27 |
+
# Use standalone Keras which supports old batch_shape parameter
|
| 28 |
+
model = load_model('cancer_model.h5', compile=False)
|
| 29 |
+
print("✓ Model loaded successfully with Keras 2.4.3!")
|
| 30 |
except Exception as e:
|
| 31 |
+
print(f"❌ Error loading model: {e}")
|
|
|
|
|
|
|
| 32 |
raise
|
| 33 |
|
| 34 |
def resize_with_padding(img, target_size):
|