| import gradio as gr | |
| import tensorflow as tf | |
| import numpy as np | |
| import json | |
| from PIL import Image | |
| model = tf.keras.models.load_model("model") | |
| with open("class_names.json") as f: | |
| class_names = json.load(f) | |
| def predict(img): | |
| img = img.resize((224,224)) | |
| img = np.array(img) / 255.0 | |
| img = np.expand_dims(img, axis=0) | |
| pred = model.predict(img) | |
| return class_names[np.argmax(pred)] | |
| gr.Interface( | |
| fn=predict, | |
| inputs=gr.Image(type="pil"), | |
| outputs="label", | |
| title="Plant Disease Classifier" | |
| ).launch() | |