Vinit710 commited on
Commit
84c7c12
·
verified ·
1 Parent(s): 06966b9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -46,15 +46,15 @@ class_names = [
46
  'Tomato___healthy'
47
  ]
48
 
49
- # Load the pre-trained model (adjust the path if necessary)
50
- model_path = "my_keras_model.keras" # Ensure this file is in the repository or adjust the path accordingly
51
  model = keras.models.load_model(model_path)
52
 
53
  def predict_plant_disease(image):
54
  """
55
- Process the uploaded image and return the predicted class along with the probability.
56
  """
57
- # Resize image to match model input
58
  img = tf.image.resize(image, (224, 224))
59
  # Convert to array and scale pixel values
60
  img_array = img_to_array(img) / 255.0
@@ -65,7 +65,7 @@ def predict_plant_disease(image):
65
  predicted_class_index = np.argmax(predictions, axis=1)[0]
66
  predicted_label = class_names[predicted_class_index]
67
 
68
- # Optionally, get top 5 predictions
69
  top5_indices = np.argsort(predictions[0])[-5:][::-1]
70
  top5_info = [(class_names[i], float(predictions[0][i])) for i in top5_indices]
71
 
@@ -85,7 +85,7 @@ description = (
85
 
86
  iface = gr.Interface(
87
  fn=predict_plant_disease,
88
- inputs=gr.inputs.Image(type="numpy", label="Upload Plant Image"),
89
  outputs="text",
90
  title=title,
91
  description=description,
 
46
  'Tomato___healthy'
47
  ]
48
 
49
+ # Load the pre-trained model (make sure the model file is in your repo)
50
+ model_path = "my_keras_model.keras" # Adjust the path if necessary
51
  model = keras.models.load_model(model_path)
52
 
53
  def predict_plant_disease(image):
54
  """
55
+ Process the uploaded image and return the predicted class along with the top 5 probabilities.
56
  """
57
+ # Resize the image to match model input
58
  img = tf.image.resize(image, (224, 224))
59
  # Convert to array and scale pixel values
60
  img_array = img_to_array(img) / 255.0
 
65
  predicted_class_index = np.argmax(predictions, axis=1)[0]
66
  predicted_label = class_names[predicted_class_index]
67
 
68
+ # Get top 5 predictions
69
  top5_indices = np.argsort(predictions[0])[-5:][::-1]
70
  top5_info = [(class_names[i], float(predictions[0][i])) for i in top5_indices]
71
 
 
85
 
86
  iface = gr.Interface(
87
  fn=predict_plant_disease,
88
+ inputs=gr.Image(type="numpy", label="Upload Plant Image"),
89
  outputs="text",
90
  title=title,
91
  description=description,