Spaces:
Runtime error
Runtime error
Upload 10 files
Browse files- .gitattributes +1 -0
- app.py +43 -0
- categories.json +40 -0
- plant_disease_detection.h5 +3 -0
- plant_disease_detection_saved_model/fingerprint.pb +3 -0
- plant_disease_detection_saved_model/keras_metadata.pb +3 -0
- plant_disease_detection_saved_model/saved_model.pb +3 -0
- plant_disease_detection_saved_model/variables/variables.data-00000-of-00001 +3 -0
- plant_disease_detection_saved_model/variables/variables.index +0 -0
- plant_disease_detection_v2_17.h5 +3 -0
- temp_image.jpg +0 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
plant_disease_detection_saved_model/variables/variables.data-00000-of-00001 filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
import json
|
7 |
+
|
8 |
+
app = Flask(__name__)
|
9 |
+
|
10 |
+
# Load the TensorFlow model
|
11 |
+
model = tf.keras.models.load_model('./plant_disease_detection_saved_model')
|
12 |
+
|
13 |
+
# Load categories
|
14 |
+
with open('./categories.json') as f:
|
15 |
+
categories = json.load(f)
|
16 |
+
|
17 |
+
def preprocess_image(image):
|
18 |
+
# Convert the image to a NumPy array
|
19 |
+
image = Image.open(io.BytesIO(image))
|
20 |
+
image = image.resize((224, 224)) # Adjust size as needed
|
21 |
+
image_array = np.array(image) / 255.0 # Normalize to [0, 1]
|
22 |
+
image_array = np.expand_dims(image_array, axis=0) # Add batch dimension
|
23 |
+
return image_array
|
24 |
+
|
25 |
+
@app.route('/predict', methods=['POST'])
|
26 |
+
def predict():
|
27 |
+
if 'image' not in request.files:
|
28 |
+
return jsonify({'error': 'No image provided'}), 400
|
29 |
+
|
30 |
+
image = request.files['image'].read()
|
31 |
+
image_array = preprocess_image(image)
|
32 |
+
|
33 |
+
# Make prediction
|
34 |
+
predictions = model.predict(image_array)
|
35 |
+
predicted_class = np.argmax(predictions, axis=1)[0]
|
36 |
+
|
37 |
+
# Map to category names
|
38 |
+
predicted_label = categories.get(str(predicted_class), 'Unknown')
|
39 |
+
|
40 |
+
return jsonify({'class': predicted_label, 'confidence': float(predictions[0][predicted_class])})
|
41 |
+
|
42 |
+
if __name__ == '__main__':
|
43 |
+
app.run(host='0.0.0.0', port=8080, debug=True)
|
categories.json
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"0": "Apple___Apple_scab",
|
3 |
+
"1": "Apple___Black_rot",
|
4 |
+
"2": "Apple___Cedar_apple_rust",
|
5 |
+
"3": "Apple___healthy",
|
6 |
+
"4": "Blueberry___healthy",
|
7 |
+
"5": "Cherry_(including_sour)___Powdery_mildew",
|
8 |
+
"6": "Cherry_(including_sour)___healthy",
|
9 |
+
"7": "Corn_(maize)___Cercospora_leaf_spot Gray_leaf_spot",
|
10 |
+
"8": "Corn_(maize)___Common_rust_",
|
11 |
+
"9": "Corn_(maize)___Northern_Leaf_Blight",
|
12 |
+
"10": "Corn_(maize)___healthy",
|
13 |
+
"11": "Grape___Black_rot",
|
14 |
+
"12": "Grape___Esca_(Black_Measles)",
|
15 |
+
"13": "Grape___Leaf_blight_(Isariopsis_Leaf_Spot)",
|
16 |
+
"14": "Grape___healthy",
|
17 |
+
"15": "Orange___Haunglongbing_(Citrus_greening)",
|
18 |
+
"16": "Peach___Bacterial_spot",
|
19 |
+
"17": "Peach___healthy",
|
20 |
+
"18": "Pepper,_bell___Bacterial_spot",
|
21 |
+
"19": "Pepper,_bell___healthy",
|
22 |
+
"20": "Potato___Early_blight",
|
23 |
+
"21": "Potato___Late_blight",
|
24 |
+
"22": "Potato___healthy",
|
25 |
+
"23": "Raspberry___healthy",
|
26 |
+
"24": "Soybean___healthy",
|
27 |
+
"25": "Squash___Powdery_mildew",
|
28 |
+
"26": "Strawberry___Leaf_scorch",
|
29 |
+
"27": "Strawberry___healthy",
|
30 |
+
"28": "Tomato___Bacterial_spot",
|
31 |
+
"29": "Tomato___Early_blight",
|
32 |
+
"30": "Tomato___Late_blight",
|
33 |
+
"31": "Tomato___Leaf_Mold",
|
34 |
+
"32": "Tomato___Septoria_leaf_spot",
|
35 |
+
"33": "Tomato___Spider_mites Two-spotted_spider_mite",
|
36 |
+
"34": "Tomato___Target_Spot",
|
37 |
+
"35": "Tomato___Tomato_Yellow_Leaf_Curl_Virus",
|
38 |
+
"36": "Tomato___Tomato_mosaic_virus",
|
39 |
+
"37": "Tomato___healthy"
|
40 |
+
}
|
plant_disease_detection.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d762c7af973c2e146345f7e7a891b371f48b5ea8c5f16dffbb939eb832d3d21d
|
3 |
+
size 9947768
|
plant_disease_detection_saved_model/fingerprint.pb
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:343b96b61ce427f0b3950b8ecfbc2f8c4e0c728b4aa54ca8513acbe7e90fa6bd
|
3 |
+
size 58
|
plant_disease_detection_saved_model/keras_metadata.pb
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a3b5ec5afcd9cb199e0231c71c3175c83189476513f8fdb71e7e752d033a79db
|
3 |
+
size 541826
|
plant_disease_detection_saved_model/saved_model.pb
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:82b1f9c611884ca35aefe1cfc99d242a51d44287df3578668f6b9aa7ff8adc20
|
3 |
+
size 2613437
|
plant_disease_detection_saved_model/variables/variables.data-00000-of-00001
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:792510776cb478e85ed86d59c5c7e78caeeb19452f2c1851f6fee8f5633f6750
|
3 |
+
size 9754360
|
plant_disease_detection_saved_model/variables/variables.index
ADDED
Binary file (15.3 kB). View file
|
|
plant_disease_detection_v2_17.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:24047ea1e4923747ada751e33f737fb213a2fcdbd32ca129f7747d7a6c0f2fa6
|
3 |
+
size 9946728
|
temp_image.jpg
ADDED
![]() |