Skip to content

Commit ad8dcde

Browse files
done
1 parent fa0793e commit ad8dcde

File tree

5 files changed

+98
-6
lines changed

5 files changed

+98
-6
lines changed

combined-disease-detection-api/app.py

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
from flask import Flask, request, jsonify
2+
import tensorflow as tf
3+
import numpy as np
4+
from PIL import Image
5+
import io
6+
from flask_cors import CORS
7+
8+
app = Flask(__name__)
9+
CORS(app) # Enable CORS for all routes
10+
11+
# Load TFLite Model and allocate tensors
12+
interpreter = tf.lite.Interpreter(model_path="plant_disease_model.tflite")
13+
interpreter.allocate_tensors()
14+
15+
# Get input and output tensors
16+
input_details = interpreter.get_input_details()
17+
output_details = interpreter.get_output_details()
18+
19+
# Define class names
20+
CLASS_NAMES = [
21+
'Apple___Apple_scab', 'Apple___Black_rot', 'Apple___Cedar_apple_rust', 'Apple___healthy',
22+
'Blueberry___healthy', 'Cherry_(including_sour)___Powdery_mildew',
23+
'Cherry_(including_sour)___healthy', 'Corn_(maize)___Cercospora_leaf_spot Gray_leaf_spot',
24+
'Corn_(maize)___Common_rust_', 'Corn_(maize)___Northern_Leaf_Blight', 'Corn_(maize)___healthy',
25+
'Grape___Black_rot', 'Grape___Esca_(Black_Measles)', 'Grape___Leaf_blight_(Isariopsis_Leaf_Spot)',
26+
'Grape___healthy', 'Orange___Haunglongbing_(Citrus_greening)', 'Peach___Bacterial_spot',
27+
'Peach___healthy', 'Pepper,_bell___Bacterial_spot', 'Pepper,_bell___healthy',
28+
'Potato___Early_blight', 'Potato___Late_blight', 'Potato___healthy',
29+
'Raspberry___healthy', 'Soybean___healthy', 'Squash___Powdery_mildew',
30+
'Strawberry___Leaf_scorch', 'Strawberry___healthy', 'Tomato___Bacterial_spot',
31+
'Tomato___Early_blight', 'Tomato___Late_blight', 'Tomato___Leaf_Mold',
32+
'Tomato___Septoria_leaf_spot', 'Tomato___Spider_mites Two-spotted_spider_mite',
33+
'Tomato___Target_Spot', 'Tomato___Tomato_Yellow_Leaf_Curl_Virus', 'Tomato___Tomato_mosaic_virus',
34+
'Tomato___healthy'
35+
]
36+
37+
def model_prediction(image_bytes):
38+
try:
39+
# Load and preprocess the image
40+
image = Image.open(io.BytesIO(image_bytes)).convert('RGB')
41+
image = image.resize((224, 224))
42+
input_arr = np.array(image)
43+
input_arr = np.expand_dims(input_arr, axis=0).astype(np.float32) / 255.0
44+
45+
# Set the tensor for the input
46+
interpreter.set_tensor(input_details[0]['index'], input_arr)
47+
48+
# Run the model
49+
interpreter.invoke()
50+
51+
# Get the output tensor and return the index of the max element
52+
output_data = interpreter.get_tensor(output_details[0]['index'])
53+
return int(np.argmax(output_data))
54+
except Exception as e:
55+
print(f"Error in model_prediction: {e}")
56+
return None
57+
58+
@app.route('/predict', methods=['POST'])
59+
def predict():
60+
if 'image' not in request.files:
61+
return jsonify({"error": "No image part in the request"}), 400
62+
63+
file = request.files['image']
64+
65+
if file.filename == '':
66+
return jsonify({"error": "No image selected for uploading"}), 400
67+
68+
try:
69+
img_bytes = file.read()
70+
result_index = model_prediction(img_bytes)
71+
72+
if result_index is None:
73+
return jsonify({"error": "Prediction failed"}), 500
74+
75+
class_name = CLASS_NAMES[result_index]
76+
return jsonify({"prediction": class_name}), 200
77+
78+
except Exception as e:
79+
print(f"Error in /predict: {e}")
80+
return jsonify({"error": "An error occurred during prediction"}), 500
81+
82+
if __name__ == '__main__':
83+
app.run(debug=True)
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
flask
2+
tensorflow
3+
numpy
4+
Pillow
5+
flask-cors
6+
gunicorn

frontend/src/components/TestimonialSlider.jsx

+8-5
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,13 @@ const TestimonialSlider = () => {
102102
border: '1px solid rgba(207, 230, 207, 0.5)', // Light green border
103103
}}
104104
>
105-
<img
106-
src={testimonial.image}
107-
alt={`${testimonial.author}'s picture`}
108-
className="w-24 h-24 md:w-32 md:h-32 rounded-full mb-4 border-2 border-green-400 transition-all duration-300 transform hover:scale-105"
109-
/>
105+
<div className="flex justify-center">
106+
<img
107+
src={testimonial.image}
108+
alt={`${testimonial.author}'s picture`}
109+
className="w-24 h-24 md:w-32 md:h-32 rounded-full mb-4 border-2 border-green-400 transition-all duration-300 transform hover:scale-105"
110+
/>
111+
</div>
110112
<p className="text-lg md:text-xl italic mb-4 text-center text-green-800">{testimonial.quote}</p>
111113
<h4 className="text-base md:text-lg text-green-600 font-semibold text-center">- {testimonial.author}</h4>
112114
</div>
@@ -130,6 +132,7 @@ const TestimonialSlider = () => {
130132
</div>
131133
</div>
132134
</section>
135+
133136
);
134137
};
135138

frontend/src/pages/Disease/PaddyRecognition.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const PaddyRecognition = () => {
3333
setLoading(true);
3434
try {
3535
const response = await axios.post(
36-
"http://127.0.0.1:5000/submit_paddy",
36+
"https://agrp-tech-ai-paddy-api.onrender.com/submit_paddy",
3737
formData,
3838
{
3939
headers: {

0 commit comments

Comments
 (0)