Spaces:
Running
Running
fix: Correctly load the Keras model from a zip file
Browse files- frontend/app.py +12 -5
frontend/app.py
CHANGED
@@ -56,13 +56,16 @@ st.title("Medi Scape Dashboard")
|
|
56 |
# --- Session State Initialization ---
|
57 |
if 'disease_model' not in st.session_state:
|
58 |
try:
|
59 |
-
model_path = 'FINAL_MODEL.
|
60 |
print(f"Attempting to load disease model from: {model_path}")
|
61 |
print(f"Model file exists: {os.path.exists(model_path)}")
|
62 |
-
|
|
|
|
|
|
|
63 |
print("Disease model loaded successfully!")
|
64 |
except FileNotFoundError:
|
65 |
-
st.error("Disease classification model not found. Please ensure 'FINAL_MODEL.
|
66 |
st.session_state.disease_model = None
|
67 |
except PermissionError:
|
68 |
st.error("Permission error accessing 'model.weights.h5'. Please ensure the file is not being used by another process.")
|
@@ -101,9 +104,13 @@ if 'model_llm' not in st.session_state:
|
|
101 |
|
102 |
# Load the disease classification model
|
103 |
try:
|
104 |
-
|
|
|
|
|
|
|
|
|
105 |
except FileNotFoundError:
|
106 |
-
st.error("Disease classification model not found. Please ensure 'FINAL_MODEL.
|
107 |
disease_model = None
|
108 |
except PermissionError:
|
109 |
st.error("Permission error accessing 'model.weights.h5'. Please ensure the file is not being used by another process.")
|
|
|
56 |
# --- Session State Initialization ---
|
57 |
if 'disease_model' not in st.session_state:
|
58 |
try:
|
59 |
+
model_path = 'FINAL_MODEL.zip' # Updated path to zip file
|
60 |
print(f"Attempting to load disease model from: {model_path}")
|
61 |
print(f"Model file exists: {os.path.exists(model_path)}")
|
62 |
+
with tf.keras.utils.get_file('FINAL_MODEL.keras', model_path, extract=True) as extracted_model_path:
|
63 |
+
model_dir = os.path.dirname(extracted_model_path)
|
64 |
+
model_path = os.path.join(model_dir, 'FINAL_MODEL.keras')
|
65 |
+
st.session_state.disease_model = tf.keras.models.load_model(model_path)
|
66 |
print("Disease model loaded successfully!")
|
67 |
except FileNotFoundError:
|
68 |
+
st.error("Disease classification model not found. Please ensure 'FINAL_MODEL.zip' is in the same directory as this app.")
|
69 |
st.session_state.disease_model = None
|
70 |
except PermissionError:
|
71 |
st.error("Permission error accessing 'model.weights.h5'. Please ensure the file is not being used by another process.")
|
|
|
104 |
|
105 |
# Load the disease classification model
|
106 |
try:
|
107 |
+
model_path = 'FINAL_MODEL.zip' # Updated path to zip file
|
108 |
+
with tf.keras.utils.get_file('FINAL_MODEL.keras', model_path, extract=True) as extracted_model_path:
|
109 |
+
model_dir = os.path.dirname(extracted_model_path)
|
110 |
+
model_path = os.path.join(model_dir, 'FINAL_MODEL.keras')
|
111 |
+
disease_model = tf.keras.models.load_model(model_path)
|
112 |
except FileNotFoundError:
|
113 |
+
st.error("Disease classification model not found. Please ensure 'FINAL_MODEL.zip' is in the same directory as this app.")
|
114 |
disease_model = None
|
115 |
except PermissionError:
|
116 |
st.error("Permission error accessing 'model.weights.h5'. Please ensure the file is not being used by another process.")
|