Spaces:
Sleeping
Sleeping
- app.py +130 -0
- best.pt +3 -0
- requirements.txt +5 -0
app.py
ADDED
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from ultralytics import YOLO
|
2 |
+
import streamlit as st
|
3 |
+
import plotly.graph_objs as go
|
4 |
+
from PIL import Image,ImageDraw
|
5 |
+
import numpy as np
|
6 |
+
from io import BytesIO
|
7 |
+
|
8 |
+
colors = {
|
9 |
+
'Apple Scab Leaf': ['rgb(165, 42, 42)', (165, 42, 42)], # Brown
|
10 |
+
'Apple leaf': ['rgb(128, 0, 128)', (128, 0, 128)], # Purple
|
11 |
+
'Apple rust leaf': ['rgb(0, 255, 0)', (0, 255, 0)], # Green
|
12 |
+
'Bell_pepper leaf spot': ['rgb(255, 215, 0)', (255, 215, 0)], # Gold
|
13 |
+
'Bell_pepper leaf': ['rgb(139, 69, 19)', (139, 69, 19)], # Brown
|
14 |
+
'Blueberry leaf': ['rgb(128, 128, 128)', (128, 128, 128)], # Gray
|
15 |
+
'Cherry leaf': ['rgb(0, 128, 0)', (0, 128, 0)], # Dark green
|
16 |
+
'Corn Gray leaf spot': ['rgb(255, 0, 0)', (255, 0, 0)], # Red
|
17 |
+
'Corn leaf blight': ['rgb(255, 165, 0)', (255, 165, 0)], # Orange
|
18 |
+
'Peach leaf': ['rgb(255, 20, 147)', (255, 20, 147)], # Pink
|
19 |
+
'Potato leaf early blight': ['rgb(255, 105, 180)', (255, 105, 180)], # Hot pink
|
20 |
+
'Potato leaf late blight': ['rgb(0, 0, 139)', (0, 0, 139)], # Dark blue
|
21 |
+
'Potato leaf': ['rgb(218, 112, 214)', (218, 112, 214)], # Orchid
|
22 |
+
'Raspberry leaf': ['rgb(255, 0, 255)', (255, 0, 255)], # Magenta
|
23 |
+
'Soyabean leaf': ['rgb(255, 69, 0)', (255, 69, 0)], # Red-orange
|
24 |
+
'Squash Powdery mildew leaf': ['rgb(0, 255, 255)', (0, 255, 255)], # Cyan
|
25 |
+
'Strawberry leaf': ['rgb(255, 255, 0)', (255, 255, 0)], # Yellow
|
26 |
+
'Tomato Early blight leaf': ['rgb(154, 205, 50)', (154, 205, 50)], # Yellow-green
|
27 |
+
'Tomato Septoria leaf spot': ['rgb(0, 0, 255)', (0, 0, 255)], # Blue
|
28 |
+
'Tomato leaf bacterial spot': ['rgb(255, 99, 71)', (255, 99, 71)], # Tomato
|
29 |
+
'Tomato leaf late blight': ['rgb(46, 139, 87)', (46, 139, 87)], # Sea green
|
30 |
+
'Tomato leaf mosaic virus': ['rgb(255, 192, 203)', (255, 192, 203)], # Pink
|
31 |
+
'Tomato leaf yellow virus': ['rgb(173, 255, 47)', (173, 255, 47)], # Green-yellow
|
32 |
+
'Tomato leaf': ['rgb(0, 128, 128)', (0, 128, 128)], # Teal
|
33 |
+
'Tomato mold leaf': ['rgb(128, 0, 0)', (128, 0, 0)], # Maroon
|
34 |
+
'Tomato two spotted spider mites leaf': ['rgb(70, 130, 180)', (70, 130, 180)], # Steel blue
|
35 |
+
'grape leaf black rot': ['rgb(0, 255, 127)', (0, 255, 127)] # Spring green
|
36 |
+
}
|
37 |
+
|
38 |
+
frequencies = {
|
39 |
+
'Apple Scab Leaf': 0,
|
40 |
+
'Apple leaf': 0,
|
41 |
+
'Apple rust leaf': 0,
|
42 |
+
'Bell_pepper leaf spot': 0,
|
43 |
+
'Bell_pepper leaf': 0,
|
44 |
+
'Blueberry leaf': 0,
|
45 |
+
'Cherry leaf': 0,
|
46 |
+
'Corn Gray leaf spot': 0,
|
47 |
+
'Corn leaf blight': 0,
|
48 |
+
'Peach leaf': 0,
|
49 |
+
'Potato leaf early blight': 0,
|
50 |
+
'Potato leaf late blight': 0,
|
51 |
+
'Potato leaf': 0,
|
52 |
+
'Raspberry leaf': 0,
|
53 |
+
'Soyabean leaf': 0,
|
54 |
+
'Squash Powdery mildew leaf': 0,
|
55 |
+
'Strawberry leaf': 0,
|
56 |
+
'Tomato Early blight leaf': 0,
|
57 |
+
'Tomato Septoria leaf spot': 0,
|
58 |
+
'Tomato leaf bacterial spot': 0,
|
59 |
+
'Tomato leaf late blight': 0,
|
60 |
+
'Tomato leaf mosaic virus': 0,
|
61 |
+
'Tomato leaf yellow virus': 0,
|
62 |
+
'Tomato leaf': 0,
|
63 |
+
'Tomato mold leaf': 0,
|
64 |
+
'Tomato two spotted spider mites leaf': 0,
|
65 |
+
'grape leaf black rot': 0
|
66 |
+
}
|
67 |
+
|
68 |
+
model = YOLO("best.pt","v8")
|
69 |
+
|
70 |
+
def draw_bboxes(image, bboxes ):
|
71 |
+
draw = ImageDraw.Draw(image)
|
72 |
+
for bbox in bboxes:
|
73 |
+
x1, y1, x2, y2 = bbox[0:4]
|
74 |
+
class_name = names[bbox[5]]
|
75 |
+
color = colors[class_name][1]
|
76 |
+
|
77 |
+
if class_name in frequencies :
|
78 |
+
frequencies[class_name] +=1
|
79 |
+
else :
|
80 |
+
frequencies[class_name] =1
|
81 |
+
x1,y1,x2,y2 = int(x1),int(y1),int(x2),int(y2)
|
82 |
+
draw.rectangle([(x1, y1), (x2, y2)], outline=color, width=2)
|
83 |
+
|
84 |
+
|
85 |
+
|
86 |
+
|
87 |
+
|
88 |
+
st.title('Plant(Apple,tomato,corn,..) disease detector using yolov8 ')
|
89 |
+
image = st.file_uploader("**put your image for examintion :** ")
|
90 |
+
|
91 |
+
|
92 |
+
if image is not None :
|
93 |
+
image = Image.open(image)
|
94 |
+
#image = image.filter(ImageFilter.MedianFilter(5))
|
95 |
+
image_np = np.array(image)
|
96 |
+
|
97 |
+
result = model.predict(source=image_np,conf=0.25,save=False)
|
98 |
+
names =result[0].names
|
99 |
+
data = result[0].boxes.data.numpy()
|
100 |
+
xyxy = data[:,:]
|
101 |
+
button = st.button("start analyzing .." , type="primary")
|
102 |
+
|
103 |
+
if button :
|
104 |
+
|
105 |
+
draw_bboxes(image, xyxy)
|
106 |
+
image.save("output.png")
|
107 |
+
|
108 |
+
|
109 |
+
|
110 |
+
|
111 |
+
x = list(frequencies.values())
|
112 |
+
y = list(frequencies.keys())
|
113 |
+
colors_list = [colors[key][0] for key in y]
|
114 |
+
# Create a bar plot
|
115 |
+
fig = go.Figure(data=[go.Bar(x=y, y=x, marker_color=colors_list)])
|
116 |
+
|
117 |
+
# Display image in the first column
|
118 |
+
|
119 |
+
st.image("output.png", caption='Annotated Image', use_column_width=True)
|
120 |
+
st.download_button(
|
121 |
+
label="Download image",
|
122 |
+
data=BytesIO(image.tobytes()),
|
123 |
+
file_name="result_image.jpg",
|
124 |
+
key="download_button",
|
125 |
+
help="Click to download t image.",
|
126 |
+
)
|
127 |
+
|
128 |
+
# Display frequencies in the second column
|
129 |
+
|
130 |
+
st.plotly_chart(fig, use_container_width=True)
|
best.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ea545d0d356576c155897287f014db9447dd85f31b8bca5819d97f41ced9bbf1
|
3 |
+
size 52064321
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
numpy==1.24.3
|
2 |
+
Pillow==10.1.0
|
3 |
+
streamlit==1.29.0
|
4 |
+
ultralytics==8.1.10
|
5 |
+
plotly==5.18.0
|