luisotorres commited on
Commit
b836ce7
1 Parent(s): 20eefb9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import tensorflow_hub as hub
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 = img_to_array(input_image) # Converting picture to array
15
+
16
+ # Preprocessing
17
+ input_image = np.resize(input_image, (256,256,3))
18
+ input_image = np.array(input_image).astype(np.float32) / 255.0
19
+ input_image = np.expand_dims(input_image, axis = 0)
20
+
21
+ prediction = model.predict(input_image)
22
+
23
+ labels = ['Healthy', 'Powdery', 'Rust']
24
+
25
+ preds_class = np.argmax(preds)
26
+ preds_label = labels[preds_class]
27
+
28
+ output = f"Predicted Class: {preds_label} <br><br> Confidence Score: {preds[0][preds_class]}"
29
+
30
+ return output
31
+ except Exception as e:
32
+ return str(e)
33
+
34
+ examples = ["Healthy.png",
35
+ "Powdery.png",
36
+ "Rust.png"]
37
+
38
+ iface = gr.Interface(
39
+ fn = predict,
40
+ inputs = gr.inputs.Image(shape=(256,256)),
41
+ outputs = "text",
42
+ title = "🌿 Plant Disease Detection",
43
+ 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>
44
+ 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>
45
+ <br> Upload a photo of a plant to see how the model classify its status!"""",
46
+ examples = examples
47
+ )
48
+
49
+ iface.launch