luisotorres commited on
Commit
76ca3a0
1 Parent(s): b5ef13c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -13
app.py CHANGED
@@ -1,23 +1,25 @@
1
- import gradio as gr
2
  import os
 
3
  import tensorflow as tf
4
- from PIL import Image
5
  import numpy as np
6
- from tensorflow.keras.preprocessing.image import img_to_array, load_img
 
7
 
8
  # Loading saved model
9
  model = tf.keras.models.load_model('plant_disease_classifier.h5')
10
 
11
- # Defining function for predictions
12
  def predict(input_image):
13
  try:
 
14
  input_image = tf.convert_to_tensor(input_image)
15
  input_image = tf.image.resize(input_image, [256, 256])
16
  input_image = tf.expand_dims(input_image, 0) / 255.0
17
 
 
18
  predictions = model.predict(input_image)
19
  labels = ['Healthy', 'Powdery', 'Rust']
20
 
 
21
  class_idx = np.argmax(predictions)
22
  class_label = labels[class_idx]
23
  confidence = predictions[0][class_idx]
@@ -30,14 +32,14 @@ def predict(input_image):
30
  examples = ["Healthy.png", "Powdery.png", "Rust.png"]
31
 
32
  iface = gr.Interface(
33
- fn = predict,
34
- inputs = gr.inputs.Image(shape=(256,256)),
35
- outputs = "text",
36
- title = "🌿 Plant Disease Detection",
37
- description='<br> This is a specialized Image Classification model engineered to identify the health status of plants, specifically detecting conditions of Powdery Mildew or Rust. <br> \
38
- This model is based on a Convolutional Neural Network that I have trained, evaluated, and validated on my Kaggle Notebook: <a href="https://www.kaggle.com/code/lusfernandotorres/convolutional-neural-network-from-scratch">🧠 Convolutional Neural Network From Scratch</a>. <br> \
39
- <br> Upload a photo of a plant to see how the model classifies its status!',
40
- examples = examples
41
  )
42
 
43
- iface.launch
 
 
1
  import os
2
+ import gradio as gr
3
  import tensorflow as tf
 
4
  import numpy as np
5
+
6
+ os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
7
 
8
  # Loading saved model
9
  model = tf.keras.models.load_model('plant_disease_classifier.h5')
10
 
 
11
  def predict(input_image):
12
  try:
13
+ # Preprocessing
14
  input_image = tf.convert_to_tensor(input_image)
15
  input_image = tf.image.resize(input_image, [256, 256])
16
  input_image = tf.expand_dims(input_image, 0) / 255.0
17
 
18
+
19
  predictions = model.predict(input_image)
20
  labels = ['Healthy', 'Powdery', 'Rust']
21
 
22
+
23
  class_idx = np.argmax(predictions)
24
  class_label = labels[class_idx]
25
  confidence = predictions[0][class_idx]
 
32
  examples = ["Healthy.png", "Powdery.png", "Rust.png"]
33
 
34
  iface = gr.Interface(
35
+ fn=predict,
36
+ inputs=gr.Interface.Image(shape=(256, 256)),
37
+ outputs="text",
38
+ title="🌿 Plant Disease Detection",
39
+ description='<br> This specialized Image Classification model identifies the health status of plants, pinpointing conditions like Powdery Mildew or Rust. <br>\
40
+ The model is engineered on a Convolutional Neural Network and has been rigorously trained, evaluated, and validated. Kaggle Notebook: <a href="https://www.kaggle.com/code/lusfernandotorres/convolutional-neural-network-from-scratch">🧠 Convolutional Neural Network From Scratch</a>. <br> \
41
+ <br> Upload a photo of a plant for classification!',
42
+ examples=examples
43
  )
44
 
45
+ iface.launch()