santhuvenky commited on
Commit
2425c82
·
verified ·
1 Parent(s): 630de6d

Upload 3 files

Browse files
Files changed (3) hide show
  1. best.pt +3 -0
  2. garden.py +121 -0
  3. requirements.txt +7 -0
best.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:920cea4150ca7a0ece69cf5baeafbd4ab3f8621fd2c863b2026f94ee33eecc78
3
+ size 11057851
garden.py ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from PIL import Image
3
+ from groq import Groq
4
+ from streamlit_chat import message
5
+ from ultralytics import YOLO
6
+
7
+
8
+ def load_model():
9
+ model = YOLO('best.pt')
10
+ return model
11
+
12
+ # Set up API key
13
+ GROQ_API = "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"
14
+ client = Groq(api_key=GROQ_API)
15
+
16
+ def chatbot_response(user_input):
17
+ chat_completion = client.chat.completions.create(
18
+ messages=[
19
+ {"role": "system", "content": "You are a helpful assistant who assists with gardening queries accurately."},
20
+ {"role": "user", "content": user_input}
21
+ ],
22
+ model="llama-3.3-70b-versatile",
23
+ )
24
+ return chat_completion.choices[0].message.content
25
+
26
+ def classify_plant_disease(image, model):
27
+ results = model(image)
28
+ probs = results[0].probs # Get the probability object
29
+ predicted_class_index = probs.top1 # Get index of the highest probability class
30
+ predicted_class_name = results[0].names[predicted_class_index]
31
+ labels = predicted_class_name
32
+ confs = probs.top1conf.item()
33
+ return [labels, confs]
34
+
35
+ # Custom CSS for enhanced UI
36
+ def add_custom_css():
37
+ st.markdown(
38
+ """
39
+ <style>
40
+ .main {background-color: #f0fff0;}
41
+ .stButton>button {border-radius: 12px; padding: 10px 20px;}
42
+ .nav-bar {background: #2e8b57; padding: 15px; border-radius: 10px; text-align: center;}
43
+ .nav-bar a {margin: 0 15px; color: white; font-size: 18px; text-decoration: none; font-weight: bold;}
44
+ .chat-container {background: #fff; padding: 20px; border-radius: 12px; box-shadow: 0px 0px 10px rgba(0,0,0,0.2);}
45
+ .chat-bubble {margin-bottom: 10px; padding: 10px 15px; border-radius: 12px;}
46
+ .user {background: #cce5ff; align-self: flex-end;}
47
+ .bot {background: #d4edda;}
48
+ </style>
49
+ """,
50
+ unsafe_allow_html=True,
51
+ )
52
+
53
+ # UI Layout
54
+ st.set_page_config(page_title="Smart Gardener AI", page_icon="🌿", layout="wide")
55
+ add_custom_css()
56
+
57
+ # Navigation Bar
58
+ st.markdown(
59
+ """
60
+ <div class='nav-bar'>
61
+ <a href='/?Home'>🏡 Home</a>
62
+ <a href='/?Plant Disease Classifier'>🌱 Classifier</a>
63
+ <a href='/?Chatbot'>🤖 Chatbot</a>
64
+ </div>
65
+ """,
66
+ unsafe_allow_html=True,
67
+ )
68
+
69
+ # Sidebar Navigation
70
+ st.sidebar.title("Navigation")
71
+ page = st.sidebar.radio("Go to", ["Home", "Plant Disease Classifier", "Chatbot"])
72
+
73
+ if page == "Home":
74
+ st.title("🌿 Welcome to Green Doctor")
75
+ st.markdown("### Your AI-powered Gardening Assistant")
76
+ st.image("https://source.unsplash.com/800x400/?garden,plants")
77
+ st.write("Green Doctor helps you identify plant diseases and offers expert gardening advice using AI-powered image classification and a smart chatbot.")
78
+ st.markdown("- **Identify plant diseases** with high accuracy.")
79
+ st.markdown("- **Get expert gardening tips** for healthy plant care.")
80
+ st.markdown("- **Chat with our AI bot** for real-time assistance.")
81
+ st.markdown("[Explore Classifier](/?Plant Disease Classifier)", unsafe_allow_html=True)
82
+
83
+ elif page == "Plant Disease Classifier":
84
+ st.title("🌱 Plant Disease Classifier")
85
+ uploaded_file = st.file_uploader("Upload an image", type=["jpg", "png", "jpeg"], key="classifier")
86
+ if uploaded_file:
87
+ image = Image.open(uploaded_file)
88
+ st.image(image, caption="Uploaded Image", width=500)
89
+ model = load_model()
90
+ label, confs = classify_plant_disease(image, model)
91
+
92
+ if label:
93
+ st.subheader("Results")
94
+
95
+ st.write(f"**Disease:** {label} \n\n **Confidence:** {confs*100:.2f}%")
96
+ response = chatbot_response(f"What are the prevention, cure, and symptoms for the {label} disease in plants with two points in each?")
97
+ st.write("### Suggested Actions:")
98
+ st.write(response)
99
+
100
+
101
+ elif page == "Chatbot":
102
+ st.title("🤖 Gardening Assistant Chatbot")
103
+ st.markdown("### Ask anything about gardening!")
104
+ chat_history = st.session_state.get("chat_history", [])
105
+ user_input = st.chat_input("Ask something")
106
+
107
+ if user_input:
108
+ bot_response = chatbot_response(user_input)
109
+ chat_history.append(("You", user_input))
110
+ chat_history.append(("Bot", bot_response))
111
+ st.session_state["chat_history"] = chat_history
112
+
113
+ # st.markdown("<div class='chat-container'>", unsafe_allow_html=True)
114
+ for sender, messages in chat_history:
115
+ if sender == "You":
116
+ message(messages,is_user=True)
117
+ else:
118
+ message(messages)
119
+ # st.markdown("</div>", unsafe_allow_html=True)
120
+
121
+ st.markdown("[Back to Home](/?Home)")
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ flask
3
+ requests
4
+ groq
5
+ pillow
6
+ ultralytics
7
+ streamlit-chat