Skip to content

jubayeris/AI-based-Crop-Disease-Detection-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

AI-based-Crop-Disease-Detection-System

from flask import Flask, request, render_template_string import tensorflow as tf import numpy as np from PIL import Image import io

app = Flask(name)

Load the pre-trained model (make sure the model is available)

model = tf.keras.models.load_model('crop_disease_model.h5')

Class labels (update these with your actual class names)

class_labels = ['Healthy', 'Disease A', 'Disease B', 'Disease C', 'Disease D']

Simple HTML form for file upload

html_form = '''

<title>Crop Disease Detection</title>

Upload a Plant Image for Disease Prediction

Predict '''

Home route that displays the upload form

@app.route('/') def home(): return render_template_string(html_form)

Prediction route

@app.route('/predict', methods=['POST']) def predict(): if 'file' not in request.files: return 'No file part'

file = request.files['file']
if file.filename == '':
    return 'No selected file'

image = Image.open(file)
image = image.resize((150, 150))  # Resize the image to match the model input size
image = np.array(image) / 255.0   # Normalize the image
image = np.expand_dims(image, axis=0)  # Add batch dimension

prediction = model.predict(image)
predicted_class = class_labels[np.argmax(prediction)]  # Get the predicted class

return f"Predicted Disease: {predicted_class}"

if name == 'main': app.run(debug=True)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published