luisotorres
commited on
Commit
•
76ca3a0
1
Parent(s):
b5ef13c
Update app.py
Browse files
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 |
-
|
|
|
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
|
34 |
-
inputs
|
35 |
-
outputs
|
36 |
-
title
|
37 |
-
description='<br> This
|
38 |
-
|
39 |
-
<br> Upload a photo of a plant
|
40 |
-
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()
|