shubham5027 commited on
Commit
b792099
·
verified ·
1 Parent(s): 25033f4

Upload 6 files

Browse files
Files changed (6) hide show
  1. .env +1 -0
  2. app.py +114 -0
  3. farmi.jpg +0 -0
  4. image.jpg +0 -0
  5. phto.jpg +0 -0
  6. requirements.txt +0 -0
.env ADDED
@@ -0,0 +1 @@
 
 
1
+ GOOGLE_API_KEY ="AIzaSyASX72XnwUqqM7XZOPY0pxoxqPNRC9thWA"
app.py ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ from io import BytesIO
4
+ from PIL import Image
5
+ import tensorflow as tf
6
+ import base64
7
+ import cv2
8
+ import os
9
+ from dotenv import load_dotenv
10
+ import google.generativeai as genai
11
+ load_dotenv()
12
+ genai.configure(api_key=os.getenv('GOOGLE_API_KEY'))
13
+
14
+ header_image_path = 'farmi.jpg'
15
+ st.image(header_image_path, use_column_width='auto')
16
+
17
+
18
+ def get_gemini_repsonse(input,prompt):
19
+ model=genai.GenerativeModel('gemini-pro')
20
+ response=model.generate_content([input,prompt])
21
+ return response.text
22
+
23
+ input_prompt= """You are an farming expert and i want some remedial and preventive information about given tomato plant disease. give me remedial informaion for appropriate environmental condition , soil condition and what pesticides and fertilizers to use. give the information in such away that it is easy for a farmer to understand if possible in hindi"""
24
+
25
+ MODEL = tf.keras.models.load_model('./potato_trained_models/1/')
26
+ TOMATO_MODEL = tf.keras.models.load_model('./tomato_trained_models/1')
27
+ PEEPER_MODEL = tf.keras.models.load_model('./pepper_trained_models/1')
28
+
29
+ class_names = ['Potato___Early_blight', 'Potato___Late_blight', 'Potato___healthy']
30
+
31
+ Tomato_classes = ['Tomato_healthy', 'Tomato_Spider_mites_Two_spotted_spider_mite', 'Tomato__Target_Spot', 'Tomato_Septoria_leaf_spot',
32
+ 'Tomato__Tomato_mosaic_virus', 'Tomato_Leaf_Mold', 'Tomato_Bacterial_spot', 'Tomato_Late_blight',
33
+ 'Tomato_Early_blight', 'Tomato__Tomato_YellowLeaf__Curl_Virus']
34
+
35
+ pepper_classes = ['pepper_bell_bacterial_spot','pepper_healthy']
36
+
37
+
38
+ st.title("Plant Disease Detection")
39
+ st.write("This application is detecting disease in three plants photato, tomato and pepper")
40
+ options = ["Select One Plant","Tomato", "Potato", "Pepper"]
41
+
42
+
43
+ selected_option = st.selectbox("Select Plant:", options)
44
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
45
+
46
+ def read_file_as_image(data)->np.array:
47
+ image = np.array(data)
48
+ image = cv2.resize(image, (256,256))
49
+ return image
50
+
51
+ async def potato():
52
+ if uploaded_file is not None:
53
+ image = Image.open(uploaded_file)
54
+ st.image(image, caption="Uploaded Image", width=250)
55
+ image = read_file_as_image(image)
56
+ image_batch = np.expand_dims(image, axis=0)
57
+ predictions = MODEL.predict(image_batch)
58
+ predicted_class = class_names[np.argmax(predictions[0])]
59
+ confidence = np.max(predictions[0])
60
+ print("prediction", class_names[np.argmax(predictions)])
61
+ st.write("Predicted Class : ", predicted_class, " Confidence Level : ", confidence)
62
+ input=st.text_input(predicted_class,key="input")
63
+ response=get_gemini_repsonse(input_prompt,input)
64
+ st.subheader("The Response is")
65
+ st.write(response)
66
+
67
+ async def tomato():
68
+ if uploaded_file is not None:
69
+ image = Image.open(uploaded_file)
70
+ st.image(image, caption="Uploaded Image", width=250)
71
+ image = read_file_as_image(image)
72
+ image_batch = np.expand_dims(image, axis=0)
73
+ predictions = TOMATO_MODEL.predict(image_batch)
74
+ predicted_class = Tomato_classes[np.argmax(predictions[0])]
75
+ confidence = np.max(predictions[0])
76
+ print("prediction", Tomato_classes[np.argmax(predictions)])
77
+ st.write("Predicted Class : ", predicted_class, " Confidence Level : ", confidence)
78
+ input=st.text_input(predicted_class,key="input")
79
+ response=get_gemini_repsonse(input_prompt,input)
80
+ st.subheader("The Response is")
81
+ st.write(response)
82
+
83
+
84
+ async def pepper():
85
+ if uploaded_file is not None:
86
+ image = Image.open(uploaded_file)
87
+ st.image(image, caption="Uploaded Image", width=250)
88
+ image = read_file_as_image(image)
89
+ image_batch = np.expand_dims(image, axis=0)
90
+ predictions = PEEPER_MODEL.predict(image_batch)
91
+ predicted_class = pepper_classes[np.argmax(predictions[0])]
92
+ confidence = np.max(predictions[0])
93
+ print("prediction", pepper_classes[np.argmax(predictions)])
94
+ st.write("Predicted Class : ", predicted_class, "Confidence Level : ", confidence)
95
+ input=st.text_input(predicted_class,key="input")
96
+ response=get_gemini_repsonse(input_prompt,input)
97
+ st.subheader("The Response is")
98
+ st.write(response)
99
+
100
+
101
+
102
+ import asyncio
103
+
104
+ if __name__ == "__main__":
105
+ if st.button('Predict'):
106
+
107
+ if selected_option == 'Potato':
108
+ asyncio.run(potato())
109
+ elif selected_option == 'Tomato':
110
+ asyncio.run(tomato())
111
+ else :
112
+ asyncio.run(pepper())
113
+ # else:
114
+ # st.write("not avalible")
farmi.jpg ADDED
image.jpg ADDED
phto.jpg ADDED
requirements.txt ADDED
Binary file (286 Bytes). View file