import gradio as gr from tensorflow.keras.models import load_model from tensorflow.keras.preprocessing import image import numpy as np # ✅ Load model once model = load_model("model.keras") labels = ["Healthy", "Early Blight", "Late Blight"] # ✅ Prediction function def predict(img): img = img.resize((128, 128)) img_array = image.img_to_array(img) img_array = np.expand_dims(img_array, axis=0) / 255.0 preds = model.predict(img_array) idx = np.argmax(preds[0]) conf = np.max(preds[0]) * 100 return { "label": labels[idx], "confidence": f"{conf:.2f}%" } # ✅ UI Text title = "🌿 DeepCrop: AI Potato Disease Detector" description = """ Upload a **potato leaf** image below, and DeepCrop’s AI will identify whether it’s **Healthy**, **Early Blight**, or **Late Blight**. --- ### 🧠 About DeepCrop is an AI-powered crop disease detection tool that helps farmers identify and manage plant health faster. --- """ # ✅ Gradio Interface (no examples) demo = gr.Interface( fn=predict, inputs=gr.Image(type="pil", label="Upload Potato Leaf"), outputs=gr.JSON(label="Prediction Result"), title=title, description=description, theme=gr.themes.Soft(primary_hue="green", secondary_hue="lime"), ) if __name__ == "__main__": demo.launch(share=True)