Upload pdd1.py
Browse files
pdd1.py
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import tensorflow as tf
|
3 |
+
from PIL import Image
|
4 |
+
import numpy as np
|
5 |
+
import os
|
6 |
+
|
7 |
+
import io
|
8 |
+
|
9 |
+
|
10 |
+
import google.generativeai as genai
|
11 |
+
|
12 |
+
def app():
|
13 |
+
def import_and_predict(image_data, model, class_labels):
|
14 |
+
size = (256, 256)
|
15 |
+
|
16 |
+
if image_data is not None:
|
17 |
+
image = Image.open(io.BytesIO(image_data.read()))
|
18 |
+
image = image.resize(size)
|
19 |
+
image = np.array(image)
|
20 |
+
img_reshape = image / 255.0
|
21 |
+
img_reshape = np.expand_dims(img_reshape, axis=0)
|
22 |
+
|
23 |
+
prediction = model.predict(img_reshape)
|
24 |
+
st.image(image, width=300)
|
25 |
+
predictions_label = class_labels[np.argmax(prediction[0])]
|
26 |
+
return predictions_label
|
27 |
+
else:
|
28 |
+
st.warning("Please upload an image.")
|
29 |
+
return None
|
30 |
+
|
31 |
+
|
32 |
+
def get_info_from_gemini(prompt):
|
33 |
+
genai.configure(api_key=os.environ.get('gemini_api'))
|
34 |
+
model = genai.GenerativeModel('gemini-pro')
|
35 |
+
response = model.generate_content(f"{prompt}")
|
36 |
+
return response
|
37 |
+
|
38 |
+
|
39 |
+
|
40 |
+
|
41 |
+
st.title("Plant Disease Detection")
|
42 |
+
|
43 |
+
uploaded_image = st.file_uploader(f"Upload an image", type=["jpg", "jpeg", "png"])
|
44 |
+
models_path = ['./best_model_100_subset.h5',]
|
45 |
+
|
46 |
+
|
47 |
+
|
48 |
+
CLASS_LABELS = ['Tomato Early blight', 'Tomato Leaf Mold', 'Tomato YellowLeaf Curl Virus',
|
49 |
+
'Tomato mosaic virus', 'Tomato healthy']
|
50 |
+
|
51 |
+
model = tf.keras.models.load_model(models_path[0])
|
52 |
+
|
53 |
+
|
54 |
+
|
55 |
+
|
56 |
+
prediction = import_and_predict(uploaded_image, model, CLASS_LABELS)
|
57 |
+
st.write("disease name: ", prediction)
|
58 |
+
|
59 |
+
|
60 |
+
if prediction != None:
|
61 |
+
new_title = '<p style="font-size: 38px">Measures you can take to control: </p>'
|
62 |
+
st.markdown(new_title, unsafe_allow_html=True)
|
63 |
+
if prediction == CLASS_LABELS[4]:
|
64 |
+
st.write("Plant is healthy take good care of it")
|
65 |
+
response = get_info_from_gemini(f"cure for the disease {prediction} tell in bulletpoints and estimated cost in inr at last give summary of each measures estimated cost")
|
66 |
+
st.write(response.text)
|
67 |
+
|