| | import gradio as gr |
| | import tensorflow as tf |
| | from tensorflow.keras.preprocessing import image |
| | import numpy as np |
| | import pickle |
| |
|
| | |
| | model = tf.keras.models.load_model("rice_disease_detector.h5") |
| | with open("class_indices.pkl", "rb") as f: |
| | class_indices = pickle.load(f) |
| | class_names = list(class_indices.keys()) |
| |
|
| | def predict_rice_disease(img): |
| | img = img.resize((224, 224)) |
| | img_array = image.img_to_array(img) / 255.0 |
| | img_array = np.expand_dims(img_array, axis=0) |
| | predictions = model.predict(img_array)[0] |
| | |
| | |
| | confidence_scores = {class_names[i]: float(f"{predictions[i]:.4f}") for i in range(len(class_names))} |
| | |
| | return confidence_scores |
| |
|
| | iface = gr.Interface( |
| | fn=predict_rice_disease, |
| | inputs=gr.Image(type="pil"), |
| | outputs=gr.Label(num_top_classes=len(class_names)), |
| | title="Rice Disease Classifier" |
| | ) |
| |
|
| | iface.launch() |
| |
|