RezinWiz commited on
Commit
8489fe2
·
verified ·
1 Parent(s): a6e4bae

Update api.py

Browse files
Files changed (1) hide show
  1. api.py +31 -4
api.py CHANGED
@@ -134,14 +134,41 @@ class DermFoundationNeuralNetwork:
134
  self.confidence_scaler = model_data['confidence_scaler']
135
  self.weighted_scaler = model_data['weighted_scaler']
136
 
 
137
  keras_model_path = model_data['keras_model_path']
138
- if os.path.exists(keras_model_path):
139
- self.model = tf.keras.models.load_model(keras_model_path)
140
- return True
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  else:
142
- return False
 
 
 
 
 
 
143
  except Exception as e:
144
  print(f"Error loading model: {e}")
 
 
145
  return False
146
 
147
  def predict(self, embedding):
 
134
  self.confidence_scaler = model_data['confidence_scaler']
135
  self.weighted_scaler = model_data['weighted_scaler']
136
 
137
+ # Get the original keras model path from pickle
138
  keras_model_path = model_data['keras_model_path']
139
+
140
+ # If the path doesn't exist, try looking in the same directory as the pickle file
141
+ if not os.path.exists(keras_model_path):
142
+ print(f"Original keras path not found: {keras_model_path}")
143
+
144
+ # Get the directory where the pickle file is located
145
+ pickle_dir = os.path.dirname(os.path.abspath(filepath))
146
+
147
+ # Extract just the filename from the original path
148
+ keras_filename = os.path.basename(keras_model_path)
149
+
150
+ # Try looking for it in the same directory as the pickle
151
+ alternative_path = os.path.join(pickle_dir, keras_filename)
152
+ print(f"Trying alternative path: {alternative_path}")
153
+
154
+ if os.path.exists(alternative_path):
155
+ keras_model_path = alternative_path
156
+ print(f"✓ Found keras model at: {keras_model_path}")
157
+ else:
158
+ print(f"✗ Keras model not found at alternative path either")
159
+ return False
160
  else:
161
+ print(f"✓ Found keras model at original path: {keras_model_path}")
162
+
163
+ # Load the keras model
164
+ self.model = tf.keras.models.load_model(keras_model_path)
165
+ print(f"✓ Keras model loaded successfully")
166
+ return True
167
+
168
  except Exception as e:
169
  print(f"Error loading model: {e}")
170
+ import traceback
171
+ traceback.print_exc()
172
  return False
173
 
174
  def predict(self, embedding):