omunaman commited on
Commit
2d339dc
Β·
verified Β·
1 Parent(s): 227bafd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -12
app.py CHANGED
@@ -49,25 +49,30 @@ def predict_disease(image):
49
  Preprocesses the image, performs prediction, and returns the predicted class with confidence score.
50
  """
51
  # Resize and preprocess image
52
- img = tf.image.resize(image, [256, 256])
 
53
  img = tf.expand_dims(img, axis=0) # Add batch dimension
54
 
55
  # Predict probabilities
56
- prediction = model.predict(img)
57
  labels = ['Early Blight', 'Late Blight', 'Healthy']
58
-
59
- # Get predicted class and confidence
60
- predicted_class = labels[prediction.argmax()]
61
- confidence = prediction.max()
62
- return f"Prediction: {predicted_class}, Confidence: {confidence:.2%}"
63
 
64
  # ... (Rest of your code) ...
65
 
66
  iface = gr.Interface(
67
  fn=predict_disease,
68
- inputs=gr.Image(), # Remove shape argument
69
- outputs="text",
70
- title="Potato Disease Classification",
71
- description="Upload an image of a potato leaf to classify its disease.",
 
 
 
 
 
 
72
  )
73
- iface.launch(share=True)
 
49
  Preprocesses the image, performs prediction, and returns the predicted class with confidence score.
50
  """
51
  # Resize and preprocess image
52
+ # Resize and preprocess the image
53
+ img = tf.image.resize(image, [256, 256])
54
  img = tf.expand_dims(img, axis=0) # Add batch dimension
55
 
56
  # Predict probabilities
57
+ prediction = model.predict(img)[0] # Extract first element (batch of size 1)
58
  labels = ['Early Blight', 'Late Blight', 'Healthy']
59
+
60
+ # Create a dictionary of class probabilities
61
+ class_probs = {label: float(prob) for label, prob in zip(labels, prediction)}
 
 
62
 
63
  # ... (Rest of your code) ...
64
 
65
  iface = gr.Interface(
66
  fn=predict_disease,
67
+ inputs=gr.Image(type="numpy", tool="editor"), # Allow image editing
68
+ outputs=gr.Label(num_top_classes=3), # Display all three probabilities
69
+ title="Potato Disease Classifier 🍟πŸ₯”",
70
+ description=(
71
+ "Upload an image of a potato leaf, and I'll classify it as one of the following:\n"
72
+ "- **Early Blight** 🌱\n"
73
+ "- **Late Blight** 🌧️\n"
74
+ "- **Healthy** πŸ’š\n\n"
75
+ "Check out the probability bars for more details!"
76
+ ),
77
  )
78
+ iface.launch(share=True)