msi commited on
Commit
ef21e68
·
1 Parent(s): 5a057e0
Files changed (5) hide show
  1. app.py +30 -0
  2. logo.png +0 -0
  3. pages/LeafDiseaseDetection .py +61 -0
  4. pages/Weather.py +11 -0
  5. pages/yolo.pt +3 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from streamlit_option_menu import option_menu
3
+
4
+ # Inclure le logo
5
+ st.image('logo', width=700) # Adjust the width as needed
6
+
7
+ # Description de l'application
8
+ st.markdown("""
9
+ <div style="color: #000000; font-size: 20px; font-weight: bold; text-align: center; margin-bottom: 20px;">
10
+ This application helps farmers detect plant leaf diseases and generate reports with recommended solutions. Additionally, it offers a weather dashboard to help you plan your agricultural activities.
11
+ </div>
12
+ """, unsafe_allow_html=True)
13
+
14
+
15
+
16
+
17
+ selected = option_menu(
18
+ menu_title=None,
19
+ options=["home","Today's weather", "Leaf disease detection"],
20
+ icons=['weather', 'image'],
21
+ menu_icon="cast", default_index=0, orientation="horizontal",
22
+
23
+ )
24
+ if selected == "Today's weather":
25
+ st.switch_page('pages/Weather.py')
26
+ elif selected == "Leaf disease detection":
27
+ st.switch_page('pages/LeafDiseaseDetection.py')
28
+
29
+
30
+
logo.png ADDED
pages/LeafDiseaseDetection .py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from ultralytics import YOLO
3
+ from PIL import Image
4
+ import numpy as np
5
+ from groq import Groq
6
+
7
+ client = Groq(
8
+ api_key="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"
9
+ )
10
+
11
+ def process_diseases(diseases):
12
+ unique_elements = sorted(set(diseases))
13
+ diseases_str = ", ".join(unique_elements)
14
+ user_input = f"How can {diseases_str} leaf diseases be treated?"
15
+ return user_input
16
+
17
+
18
+ # Function to detect diseases in an image
19
+ def detect_image(image):
20
+ detected_classes = []
21
+ img_array = np.array(image)
22
+
23
+ model = YOLO("yolo.pt")
24
+ results = model(img_array)
25
+
26
+ for result in results:
27
+ img_with_boxes = result.plot()
28
+ for box in result.boxes:
29
+ class_id = int(box.cls)
30
+ class_name = model.names[class_id]
31
+ detected_classes.append(class_name)
32
+
33
+ return img_with_boxes, list(dict.fromkeys(detected_classes))
34
+
35
+ def get_chat_completion(prompt):
36
+
37
+ chat_completion = client.chat.completions.create(
38
+ messages=[{ "role": "user", "content": prompt, } ],
39
+ model="llama3-8b-8192",)
40
+ response=chat_completion.choices[0].message.content
41
+ return response
42
+
43
+ st.title("Disease Detection and Solution Finder")
44
+
45
+ uploaded_file = st.file_uploader("Upload image", type=["png", "jpg", "jpeg","webp"])
46
+
47
+ if uploaded_file is not None:
48
+ image = Image.open(uploaded_file)
49
+ detected_image, diseases = detect_image(image)
50
+ detected_pil_image = Image.fromarray(detected_image)
51
+ st.image(detected_pil_image, caption='Detected Image', width=500)
52
+ user_input = process_diseases(diseases)
53
+
54
+ if st.button("Get Solution"):
55
+ if user_input:
56
+ st.write(user_input)
57
+ with st.spinner("Generating response..."):
58
+ response = get_chat_completion(user_input)
59
+ st.write(response) # Change st.write_stream to st.write
60
+ else:
61
+ st.write("No diseases detected to generate a solution.")
pages/Weather.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ # Exemple d'utilisation de st.components.v1.iframe
3
+ iframe_src ="https://app.powerbi.com/view?r=eyJrIjoiNzg4M2E3YzQtYmUyZS00MWE1LTlhYTMtYWZhYjAxMzcyNGM0IiwidCI6ImRiZDY2NjRkLTRlYjktNDZlYi05OWQ4LTVjNDNiYTE1M2M2MSIsImMiOjl9"
4
+
5
+ st.components.v1.iframe(
6
+ src=iframe_src,
7
+ width=1000,
8
+ height=1200,
9
+ scrolling=True # Permet le défilement si nécessaire
10
+ )
11
+
pages/yolo.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b2142cdc3e0211e115813b924500e4af755889b153e5df40602ca5a8cef2032a
3
+ size 6250275