wissemkarous commited on
Commit
524689b
1 Parent(s): 8400d07
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -40,20 +40,21 @@ model = models.Sequential([
40
  # Load pre-trained weights
41
  model.load_weights('model911.h5')
42
 
43
- # Function to make predictions
44
  def classify_image(image):
45
- # Preprocess image if necessary
 
 
 
46
  # Make prediction
47
- prediction = model.predict(image)
48
  classes = ['Potato___Early_blight', 'Potato___Late_blight', 'Potato___healthy']
49
  return {classes[i]: float(prediction[0][i]) for i in range(len(classes))}
50
 
51
-
52
- # Input component
53
- inputs = gr.Image(shape=(image_size, image_size,channels))
54
 
55
  # Output component
56
  outputs = gr.outputs.Label(num_top_classes=3)
57
 
58
  # Create Gradio interface
59
- gr.Interface(fn=classify_image, inputs=inputs, outputs=outputs, title='Potato Plant Diseases Classifier').launch()
 
40
  # Load pre-trained weights
41
  model.load_weights('model911.h5')
42
 
 
43
  def classify_image(image):
44
+ # Preprocess image (if needed)
45
+ image = tf.image.resize(image, (image_size, image_size)) # Resize to expected shape
46
+ image = tf.cast(image, dtype=tf.float32) / 255.0 # Rescale
47
+
48
  # Make prediction
49
+ prediction = model.predict(tf.expand_dims(image, axis=0))
50
  classes = ['Potato___Early_blight', 'Potato___Late_blight', 'Potato___healthy']
51
  return {classes[i]: float(prediction[0][i]) for i in range(len(classes))}
52
 
53
+ # Input component (No need for `shape` here)
54
+ inputs = gr.Image()
 
55
 
56
  # Output component
57
  outputs = gr.outputs.Label(num_top_classes=3)
58
 
59
  # Create Gradio interface
60
+ gr.Interface(fn=classify_image, inputs=inputs, outputs=outputs, title='Potato Plant Diseases Classifier').launch()