Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
from tensorflow.keras.models import load_model
|
| 4 |
+
from tensorflow.keras.preprocessing.image import load_img, img_to_array
|
| 5 |
+
import numpy as np
|
| 6 |
+
from PIL import Image
|
| 7 |
+
|
| 8 |
+
model = load_model('/content/drive/MyDrive/Colab Notebooks/model_extended.h5')
|
| 9 |
+
|
| 10 |
+
def predict_image(image):
|
| 11 |
+
img_array = img_to_array(image)
|
| 12 |
+
img_array = img_array.reshape((1, 256, 256, 3))
|
| 13 |
+
img_array = img_array / 255.0
|
| 14 |
+
predictions = model.predict(img_array)
|
| 15 |
+
predicted_class_index = predictions.argmax()
|
| 16 |
+
class_labels = ['bacterial_leaf_blight', 'bacterial_leaf_streak', 'bacterial_panicle_blight','blast','brown_spot','dead_heart','downy_mildew','hispa','normal','tungro' ] # Replace with your actual class labels
|
| 17 |
+
predicted_class_label = class_labels[predicted_class_index]
|
| 18 |
+
return predicted_class_label
|
| 19 |
+
|
| 20 |
+
my_app = gr.Blocks()
|
| 21 |
+
with my_app:
|
| 22 |
+
gr.Markdown("<center><h1>Paddy Pest Disease Classification Application UI with Gradio</h1></center>")
|
| 23 |
+
with gr.Row():
|
| 24 |
+
with gr.Column():
|
| 25 |
+
img_source = gr.Image(label="Please select source Image", shape=(256, 256))
|
| 26 |
+
source_image_loader = gr.Button("Load Image")
|
| 27 |
+
with gr.Column():
|
| 28 |
+
output = gr.Textbox(label="Image Info")
|
| 29 |
+
source_image_loader.click(predict_image,img_source,output)
|
| 30 |
+
|
| 31 |
+
my_app.launch(debug=True)
|