import streamlit as st from pathlib import Path import google.generativeai as genai import tempfile # Function to configure and use the google.generativeai model def analyze_plant_disease(image_bytes): genai.configure(api_key="AIzaSyAVpLXDazfH6mSlo-CfMzQ4nq5YOnqEA9A") generation_config = { "temperature": 0.4, "top_p": 1, "top_k": 32, "max_output_tokens": 4096, } safety_settings = [ {"category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"}, {"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_MEDIUM_AND_ABOVE"}, {"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"}, {"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"}, ] model = genai.GenerativeModel(model_name="gemini-1.0-pro-vision-latest", generation_config=generation_config, safety_settings=safety_settings) image_parts = [{"mime_type": "image/jpeg", "data": image_bytes}] prompt_parts = [ "You are a professional Plant disease detector. I'll provide an image of a leaf of a plant. Identify any disease in the plant and provide a structured response in the following format: Predicted Plant Disease: [Include name of disease, details about symptoms, affected parts etc.] Precautions: [In bullet points, List 2-3 precautionary measures to prevent this disease from occurring or spreading further] Remedies: [In bullet points, Provide 2-3 treatment methods, natural remedies or solutions that can help cure or manage this plant disease] Please ensure your response has these 3 clear sections with relevant details in each. Do not include any additional descriptive text outside the requested structure.", image_parts[0], ] response = model.generate_content(prompt_parts) return response.text # Streamlit application starts here st.title("Plant Disease Detection using Vision Techniques") st.write(""" Discover plant care made easy with Vision techniques! Our project uses new age technology to spot plant diseases through pictures. It's like having a plant doctor with large data in your pocket! Early detection, simple solutions. Keep your plants healthy! """) uploaded_image = st.file_uploader("Choose an image of a plant leaf", type=["jpeg", "jpg", "png"]) if uploaded_image is not None: with st.spinner('Analyzing the image...'): # Read the image and convert to bytes image_bytes = uploaded_image.getvalue() result = analyze_plant_disease(image_bytes) st.success("Analysis Complete") st.write(result)