ombhojane commited on
Commit
9172b88
1 Parent(s): 185516d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from pathlib import Path
3
+ import google.generativeai as genai
4
+ import tempfile
5
+
6
+ # Function to configure and use the google.generativeai model
7
+ def analyze_plant_disease(image_bytes):
8
+ genai.configure(api_key="AIzaSyAVpLXDazfH6mSlo-CfMzQ4nq5YOnqEA9A")
9
+
10
+ generation_config = {
11
+ "temperature": 0.4,
12
+ "top_p": 1,
13
+ "top_k": 32,
14
+ "max_output_tokens": 4096,
15
+ }
16
+
17
+ safety_settings = [
18
+ {"category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"},
19
+ {"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_MEDIUM_AND_ABOVE"},
20
+ {"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"},
21
+ {"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"},
22
+ ]
23
+
24
+ model = genai.GenerativeModel(model_name="gemini-1.0-pro-vision-latest",
25
+ generation_config=generation_config,
26
+ safety_settings=safety_settings)
27
+
28
+ image_parts = [{"mime_type": "image/jpeg", "data": image_bytes}]
29
+
30
+ prompt_parts = [
31
+ "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.",
32
+ image_parts[0],
33
+ ]
34
+
35
+ response = model.generate_content(prompt_parts)
36
+ return response.text
37
+
38
+ # Streamlit application starts here
39
+ st.title("Plant Disease Detection using Vision Techniques")
40
+
41
+ st.write("""
42
+ 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!
43
+ """)
44
+
45
+ uploaded_image = st.file_uploader("Choose an image of a plant leaf", type=["jpeg", "jpg", "png"])
46
+ if uploaded_image is not None:
47
+ with st.spinner('Analyzing the image...'):
48
+ # Read the image and convert to bytes
49
+ image_bytes = uploaded_image.getvalue()
50
+ result = analyze_plant_disease(image_bytes)
51
+ st.success("Analysis Complete")
52
+ st.write(result)