HashamUllah commited on
Commit
6e4028f
·
verified ·
1 Parent(s): 0ccfea5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -5
app.py CHANGED
@@ -7,8 +7,8 @@ import json
7
 
8
  app = Flask(__name__)
9
 
10
- # Load the TensorFlow SavedModel
11
- model = tf.keras.models.load_model('./plant_disease_detection_saved_model')
12
 
13
  # Load categories
14
  with open('./categories.json') as f:
@@ -31,12 +31,11 @@ def predict():
31
  image_array = preprocess_image(image)
32
 
33
  # Make prediction
34
- predictions = model.predict(image_array)
35
  predicted_class = np.argmax(predictions, axis=1)[0]
36
 
37
  # Map to category names
38
- predicted_label = [key for key, value in categories.items() if value == predicted_class]
39
- predicted_label = predicted_label[0] if predicted_label else 'Unknown'
40
 
41
  return jsonify({'class': predicted_label, 'confidence': float(predictions[0][predicted_class])})
42
 
 
7
 
8
  app = Flask(__name__)
9
 
10
+ # Load the TensorFlow model
11
+ model = tf.keras.layers.TFSMLayer('./plant_disease_detection_saved_model', call_endpoint='serving_default')
12
 
13
  # Load categories
14
  with open('./categories.json') as f:
 
31
  image_array = preprocess_image(image)
32
 
33
  # Make prediction
34
+ predictions = model(image_array)
35
  predicted_class = np.argmax(predictions, axis=1)[0]
36
 
37
  # Map to category names
38
+ predicted_label = categories.get(str(predicted_class), 'Unknown')
 
39
 
40
  return jsonify({'class': predicted_label, 'confidence': float(predictions[0][predicted_class])})
41