Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,169 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
-
import
|
3 |
-
import
|
4 |
-
import tensorflow as tf
|
5 |
-
from tensorflow.keras.models import load_model
|
6 |
-
from tensorflow.keras.preprocessing.image import img_to_array
|
7 |
from PIL import Image
|
8 |
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
'Tomate: Leaf mold',
|
23 |
-
'Tomate: Septoria leaf spot',
|
24 |
-
'Tomate: Spider mites',
|
25 |
-
'Tomate: Spot',
|
26 |
-
'Tomate: Yellow Leaf Curl',
|
27 |
-
'Tomate: Virus Mosaïque',
|
28 |
-
'Tomate: Healthy'
|
29 |
-
]
|
30 |
|
31 |
-
|
32 |
-
treatment_dict = {
|
33 |
-
'Piment: Bacterial_spot': {
|
34 |
-
'treatment': 'Apply Copper Fungicide',
|
35 |
-
'medicines': ['Fungicide A', 'Fungicide B']
|
36 |
-
},
|
37 |
-
'Piment: healthy': {
|
38 |
-
'treatment': 'No treatment required',
|
39 |
-
'medicines': []
|
40 |
-
},
|
41 |
-
'Pomme de terre: Early_blight': {
|
42 |
-
'treatment': 'Use Neem Oil',
|
43 |
-
'medicines': ['Neem Oil', 'Fungicide C']
|
44 |
-
},
|
45 |
-
'Pomme de terre: Late_blight': {
|
46 |
-
'treatment': 'Apply Systemic Fungicide',
|
47 |
-
'medicines': ['Fungicide D']
|
48 |
-
},
|
49 |
-
'Pomme de terre: Healthy': {
|
50 |
-
'treatment': 'No treatment required',
|
51 |
-
'medicines': []
|
52 |
-
},
|
53 |
-
'Tomate: Bacterial Spot': {
|
54 |
-
'treatment': 'Remove infected leaves and apply bactericide',
|
55 |
-
'medicines': ['Bactericide A']
|
56 |
-
},
|
57 |
-
'Tomate: Early Blight': {
|
58 |
-
'treatment': 'Apply preventative fungicides',
|
59 |
-
'medicines': ['Fungicide E']
|
60 |
-
},
|
61 |
-
'Tomate: Late Blight': {
|
62 |
-
'treatment': 'Use fungicides with metalaxyl',
|
63 |
-
'medicines': ['Fungicide F']
|
64 |
-
},
|
65 |
-
'Tomate: Leaf mold': {
|
66 |
-
'treatment': 'Improve air circulation',
|
67 |
-
'medicines': ['Fungicide G']
|
68 |
-
},
|
69 |
-
'Tomate: Septoria leaf spot': {
|
70 |
-
'treatment': 'Remove infected leaves and spray with fungicide',
|
71 |
-
'medicines': ['Fungicide H']
|
72 |
-
},
|
73 |
-
'Tomate: Spider mites': {
|
74 |
-
'treatment': 'Use miticides or insecticidal soap',
|
75 |
-
'medicines': ['Miticide A']
|
76 |
-
},
|
77 |
-
'Tomate: Spot': {
|
78 |
-
'treatment': 'Check for pest issues and apply appropriate treatment',
|
79 |
-
'medicines': []
|
80 |
-
},
|
81 |
-
'Tomate: Yellow Leaf Curl': {
|
82 |
-
'treatment': 'Remove infected plants',
|
83 |
-
'medicines': []
|
84 |
-
},
|
85 |
-
'Tomate: Virus Mosaïque': {
|
86 |
-
'treatment': 'Remove infected plants',
|
87 |
-
'medicines': []
|
88 |
-
},
|
89 |
-
'Tomate: Healthy': {
|
90 |
-
'treatment': 'No treatment required',
|
91 |
-
'medicines': []
|
92 |
-
}
|
93 |
-
}
|
94 |
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
"Sharp Eyespot", "Root Rot", "Take-all", "Yellow Rust", "Brown Rust",
|
101 |
-
"Black Point", "Stem Rust", "Glume Blotch", "Dwarf Wheat Rust", "Wheat Blast"
|
102 |
-
],
|
103 |
-
"Rice": [
|
104 |
-
"Brown Spot", "Leaf Blast", "Bacterial Blight", "Sheath Blight",
|
105 |
-
"Rice Tungro Virus", "False Smut", "Leaf Scald", "Stem Rot",
|
106 |
-
"Glume Discoloration", "Narrow Brown Leaf Spot", "Mosaic Virus",
|
107 |
-
"Ricelblast", "White Tip", "Bacterial Leaf Blight", "Fusarium Head Blight"
|
108 |
-
],
|
109 |
-
"Corn": [
|
110 |
-
"Corn Smut", "Northern Corn Leaf Blight", "Gray Leaf Spot", "Goss's Wilt",
|
111 |
-
"Southern Rust", "Common Rust", "Seedling Blight", "Ear Rot",
|
112 |
-
"Fusarium Ear Rot", "Anthracnose", "Bacterial Leaf Streak", "Diplodia Ear Rot",
|
113 |
-
"Eyespot", "Root Rot", "Crown Rot", "Stalk Rot", "Kernel Rot"
|
114 |
-
],
|
115 |
-
"Soybean": [
|
116 |
-
"Soybean Cyst Nematode", "Phytophthora Root Rot", "Bacterial Blight", "Downy Mildew",
|
117 |
-
"Brown Spot", "Sclerotinia Stem Rot", "Frogeye Leaf Spot", "Pod Blight",
|
118 |
-
"Root Rot", "Anthracnose", "Virus Diseases", "Septoria Leaf Spot",
|
119 |
-
"Rust", "White Mold", "Sudden Death Syndrome", "Charcoal Rot"
|
120 |
-
],
|
121 |
-
"Tomato": [
|
122 |
-
"Late Blight", "Early Blight", "Leaf Spot", "Fusarium Wilt",
|
123 |
-
"Bacterial Spot", "Blossom End Rot", "Powdery Mildew", "Septoria Leaf Spot",
|
124 |
-
"Tobacco Mosaic Virus", "Gray Mold", "Canker", "Phytophthora Root Rot",
|
125 |
-
"Verticillium Wilt", "Downy Mildew", "Black Mold", "Nematode Infestation"
|
126 |
-
],
|
127 |
-
"Potato": [
|
128 |
-
"Late Blight", "Early Blight", "Black Leg", "Scab",
|
129 |
-
"Powdery Scab", "Fusarium Wilt", "Tuber Blight", "Soft Rot",
|
130 |
-
"Verticillium Wilt", "Phytophthora Blight", "Golden Nematode",
|
131 |
-
"Bacterial Ring Rot", "Leaf Roll Virus", "Potato Virus X", "Cyst Nematodes"
|
132 |
-
],
|
133 |
-
"Cotton": [
|
134 |
-
"Cotton Wilt", "Boll Rot", "Alternaria Leaf Spot", "Bacterial Blight",
|
135 |
-
"Fusarium Wilt", "Pink Bollworm", "Cotton Leaf Curl Virus", "Root Knot Nematode",
|
136 |
-
"Seedling Disease", "Boll Weevil", "Leaf Spot", "Webworm",
|
137 |
-
"Southern Blight", "Target Spot", "Anthracnose", "Thrips Damage"
|
138 |
-
],
|
139 |
-
"Barley": [
|
140 |
-
"Barley Yellow Dwarf", "Powdery Mildew", "Net Blotch", "Fusarium Head Blight",
|
141 |
-
"Scald", "Hulled Barley Disease", "Root Rot", "Bacterial Leaf Blight",
|
142 |
-
"Corn Smut", "Kernel Blight", "Mosaic Virus", "Spot Blotch",
|
143 |
-
"Streak", "Barley Yellow Mosaic"
|
144 |
-
],
|
145 |
-
"Cabbage": [
|
146 |
-
"Black Rot", "Downy Mildew", "Cabbage Looper", "Alternaria Leaf Spot",
|
147 |
-
"Clubroot", "Bacterial Soft Rot", "Fusarium Wilt", "Cabbage Maggot",
|
148 |
-
"Diamondback Moth", "Bacterial Blight", "Mosaic Virus", "White Rust",
|
149 |
-
"Leaf Spot", "Sclerotinia Rot"
|
150 |
-
],
|
151 |
-
"Carrot": [
|
152 |
-
"Alternaria Leaf Blight", "Cavity Spot", "Fusarium Wilt", "Bacterial Soft Rot",
|
153 |
-
"Downy Mildew", "Carrot Rust Fly", "Crown Rot", "Powdery Mildew",
|
154 |
-
"Bacterial Blight", "Sclerotinia Rot", "Root Knot Nematode", "Mosaic Virus",
|
155 |
-
"Leaf Spot"
|
156 |
-
],
|
157 |
-
"Onion": [
|
158 |
-
"Downy Mildew", "Onion Fly", "White Rot", "Botrytis Leaf Blight",
|
159 |
-
"Fusarium Basal Rot", "Bacterial Soft Rot", "Pink Root", "Mosaic Virus",
|
160 |
-
"Leaf Blight", "Pythium Root Rot", "Black Mold", "Fusarium Wilt"
|
161 |
-
],
|
162 |
-
"Grapes": [
|
163 |
-
"Powdery Mildew", "Downy Mildew", "Botrytis Bunch Rot", "Black Rot",
|
164 |
-
"Phomopsis Cane and Leaf Spot", "Crown Gall", "Pierce's Disease",
|
165 |
-
"Bacterial Blight", "Eutypa Dieback", "Grapevine Leafroll",
|
166 |
-
"Sooty Mold", "Anthracnose", "Mealybug Infestation", "Fungal Leaf Spot"
|
167 |
-
],
|
168 |
-
"Peppers": [
|
169 |
-
"Bacterial Spot", "Powdery Mildew", "Ph
|
|
|
1 |
+
### Health Management APP
|
2 |
+
from dotenv import load_dotenv
|
3 |
+
|
4 |
+
load_dotenv() ## load all the environment variables
|
5 |
+
|
6 |
import streamlit as st
|
7 |
+
import os
|
8 |
+
import google.generativeai as genai
|
|
|
|
|
|
|
9 |
from PIL import Image
|
10 |
|
11 |
+
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
12 |
+
|
13 |
+
## Function to load Google Gemini Pro Vision API And get response
|
14 |
+
|
15 |
+
def get_gemini_repsonse(input,image,prompt):
|
16 |
+
model=genai.GenerativeModel('gemini-pro-vision')
|
17 |
+
response=model.generate_content([input,image[0],prompt])
|
18 |
+
return response.text
|
19 |
+
|
20 |
+
def input_image_setup(uploaded_file):
|
21 |
+
# Check if a file has been uploaded
|
22 |
+
if uploaded_file is not None:
|
23 |
+
# Read the file into bytes
|
24 |
+
bytes_data = uploaded_file.getvalue()
|
25 |
+
|
26 |
+
image_parts = [
|
27 |
+
{
|
28 |
+
"mime_type": uploaded_file.type, # Get the mime type of the uploaded file
|
29 |
+
"data": bytes_data
|
30 |
+
}
|
31 |
+
]
|
32 |
+
return image_parts
|
33 |
+
else:
|
34 |
+
raise FileNotFoundError("No file uploaded")
|
35 |
+
|
36 |
+
##initialize our streamlit app
|
37 |
+
|
38 |
+
st.set_page_config(page_title="Crop Disease Detection App")
|
39 |
+
|
40 |
+
st.header("Gemini Crop Disease App")
|
41 |
+
input=st.text_input("Input Prompt: ",key="input")
|
42 |
+
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
43 |
+
image=""
|
44 |
+
if uploaded_file is not None:
|
45 |
+
image = Image.open(uploaded_file)
|
46 |
+
st.image(image, caption="Uploaded Image.", use_column_width=True)
|
47 |
+
|
48 |
+
|
49 |
+
submit=st.button("Predict Crop/Plant Health")
|
50 |
|
51 |
+
input_prompt="""
|
52 |
+
"You are an expert in computer vision and agriculture who can easily predict the disease of the plant. "
|
53 |
+
"Analyze the following image and provide 6 outputs in a structured table format: "
|
54 |
+
"1. Crop in the image, "
|
55 |
+
"2. Whether it is infected or healthy, "
|
56 |
+
"3. Type of disease (if any), "
|
57 |
+
"4. How confident out of 100% whether image is healthy or infected "
|
58 |
+
"5. Reason for the disease such as whether it is happening due to fungus, bacteria, insect bite, poor nutrition, etc., "
|
59 |
+
"6. Precautions for it."
|
60 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
+
## If submit button is clicked
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
+
if submit:
|
65 |
+
image_data=input_image_setup(uploaded_file)
|
66 |
+
response=get_gemini_repsonse(input_prompt,image_data,input)
|
67 |
+
st.subheader("The Response is")
|
68 |
+
st.write(response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|