Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import cv2
|
| 4 |
+
|
| 5 |
+
used_model = tf.keras.models.load_model('/model')
|
| 6 |
+
new_classes = ['blight', 'common_rust', 'gray_leaf_spot','healthy']
|
| 7 |
+
|
| 8 |
+
def classify_image(img_dt):
|
| 9 |
+
img_dt = cv2.resize(img_dt,(256,256))
|
| 10 |
+
img_dt = img_dt.reshape((-1,256,256,3))
|
| 11 |
+
prediction = used_model.predict(img_dt).flatten()
|
| 12 |
+
confidences = {new_classes[i]: float(prediction[i]) for i in range (4) }
|
| 13 |
+
return confidences
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
with gr.Blocks() as demo:
|
| 17 |
+
with gr.Row():
|
| 18 |
+
signal = gr.Markdown(''' #Welcome to Maize Classifier, This model can identify if a leaf is
|
| 19 |
+
**HEALTHY**, has **COMMON RUST**, **BLIGHT** or **GRAY LEAF SPOT**''')
|
| 20 |
+
inp = gr.image()
|
| 21 |
+
out = gr.Label()
|
| 22 |
+
inp.upload(fn= classify_image, inputs = inp, outputs = out, show_progrss = True)
|