luisotorres
commited on
Commit
•
0af5b29
1
Parent(s):
2abbe16
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
import tensorflow as tf
|
3 |
from PIL import Image
|
4 |
import numpy as np
|
@@ -10,33 +11,27 @@ model = tf.keras.models.load_model('plant_disease_classifier.h5')
|
|
10 |
# Defining function for predictions
|
11 |
def predict(input_image):
|
12 |
try:
|
13 |
-
input_image =
|
14 |
-
|
15 |
-
|
16 |
-
input_image = np.resize(input_image, (256,256,3))
|
17 |
-
input_image = np.array(input_image).astype(np.float32) / 255.0
|
18 |
-
input_image = np.expand_dims(input_image, axis = 0)
|
19 |
-
|
20 |
-
prediction = model.predict(input_image)
|
21 |
|
|
|
22 |
labels = ['Healthy', 'Powdery', 'Rust']
|
23 |
|
24 |
-
|
25 |
-
|
|
|
26 |
|
27 |
-
|
28 |
|
29 |
-
return output
|
30 |
except Exception as e:
|
31 |
-
return
|
32 |
|
33 |
-
examples = ["Healthy.png",
|
34 |
-
"Powdery.png",
|
35 |
-
"Rust.png"]
|
36 |
|
37 |
iface = gr.Interface(
|
38 |
fn = predict,
|
39 |
-
inputs = gr.
|
40 |
outputs = "text",
|
41 |
title = "🌿 Plant Disease Detection",
|
42 |
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> \
|
|
|
1 |
import gradio as gr
|
2 |
+
import os
|
3 |
import tensorflow as tf
|
4 |
from PIL import Image
|
5 |
import numpy as np
|
|
|
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]
|
24 |
|
25 |
+
return f"Predicted Class: {class_label} <br><br> Confidence Score: {confidence}"
|
26 |
|
|
|
27 |
except Exception as e:
|
28 |
+
return f"An error occurred: {e}"
|
29 |
|
30 |
+
examples = ["Healthy.png", "Powdery.png", "Rust.png"]
|
|
|
|
|
31 |
|
32 |
iface = gr.Interface(
|
33 |
fn = predict,
|
34 |
+
inputs = gr.Interface.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> \
|