|
import streamlit as st |
|
import tensorflow as tf |
|
from PIL import Image |
|
import numpy as np |
|
import os |
|
|
|
import io |
|
|
|
|
|
import google.generativeai as genai |
|
|
|
|
|
def import_and_predict(image_data, model, class_labels): |
|
size = (256, 256) |
|
|
|
if image_data is not None: |
|
image = Image.open(io.BytesIO(image_data.read())) |
|
image = image.resize(size) |
|
image = np.array(image) |
|
img_reshape = image / 255.0 |
|
img_reshape = np.expand_dims(img_reshape, axis=0) |
|
|
|
prediction = model.predict(img_reshape) |
|
st.image(image, width=300) |
|
predictions_label = class_labels[np.argmax(prediction[0])] |
|
return predictions_label |
|
else: |
|
st.warning("Please upload an image.") |
|
return None |
|
|
|
|
|
def get_info_from_gemini(prompt): |
|
genai.configure(api_key=os.environ.get('gemini_api')) |
|
model = genai.GenerativeModel('gemini-pro') |
|
response = model.generate_content(f"{prompt}") |
|
return response |
|
|
|
|
|
|
|
|
|
st.title("Plant Disease Detection") |
|
|
|
uploaded_image = st.file_uploader(f"Upload an image", type=["jpg", "jpeg", "png"]) |
|
models_path = ['./best_model_100_subset.h5',] |
|
|
|
|
|
|
|
CLASS_LABELS = ['Tomato Early blight', 'Tomato Leaf Mold', 'Tomato YellowLeaf Curl Virus', |
|
'Tomato mosaic virus', 'Tomato healthy'] |
|
|
|
model = tf.keras.models.load_model(models_path[0]) |
|
|
|
|
|
|
|
|
|
prediction = import_and_predict(uploaded_image, model, CLASS_LABELS) |
|
st.write("disease name: ", prediction) |
|
|
|
|
|
if prediction != None: |
|
new_title = '<p style="font-size: 38px">Measures you can take to control: </p>' |
|
st.markdown(new_title, unsafe_allow_html=True) |
|
if prediction == CLASS_LABELS[4]: |
|
st.write("Plant is healthy take good care of it") |
|
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") |
|
st.write(response.text) |