Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import tensorflow as tf | |
| import numpy as np | |
| from PIL import Image | |
| # trained model load | |
| # Purana code: model = tf.keras.models.load_model("model.h5") | |
| # Naya code (Sahi naam ke saath): | |
| model = tf.keras.models.load_model("plant_disease_model.keras") | |
| # prediction function | |
| def predict_plant(img): | |
| # resize same as training | |
| img = img.resize((150,150)) | |
| img_array = np.array(img)/255.0 | |
| # batch dimension add | |
| img_array = np.expand_dims(img_array, axis=0) | |
| prediction = model.predict(img_array)[0][0] | |
| if prediction > 0.5: | |
| return "Diseased Plant" | |
| else: | |
| return "Healthy Plant" | |
| # interface | |
| demo = gr.Interface( | |
| fn=predict_plant, | |
| inputs=gr.Image(type="pil"), | |
| outputs="text", | |
| title="Plant Disease Classifier" | |
| ) | |
| demo.launch() | |