Create app.py
Browse files12345678910111213141516171819202122232425262728293031import gradio as grimport tensorflow as tffrom tensorflow.keras.models import load_modelfrom tensorflow.keras.preprocessing.image import load_img, img_to_arrayimport numpy as npfrom PIL import Image
model = load_model('/content/drive/MyDrive/Colab Notebooks/model_extended.h5')
def predict_image(image): img_array = img_to_array(image) img_array = img_array.reshape((1, 256, 256, 3)) img_array = img_array / 255.0 predictions = model.predict(img_array) predicted_class_index = predictions.argmax() 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 predicted_class_label = class_labels[predicted_class_index] return predicted_class_label
my_app = gr.Blocks()with my_app: gr.Markdown("<center><h1>Paddy Pest Disease Classification Application UI with Gradio</h1></center>") with gr.Row(): with gr.Column(): img_source = gr.Image(label="Please select source Image", shape=(256, 256)) source_image_loader = gr.Button("Load Image") with gr.Column(): output = gr.Textbox(label="Image Info") source_image_loader.click(predict_image,img_source,output)
my_app.launch(debug=True)app.pyAdded+31