mahesh002 commited on
Commit
c9f1cda
โ€ข
1 Parent(s): 00593c6

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +155 -0
  2. bg.webp +0 -0
  3. style.css +23 -0
app.py ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ import streamlit as st
3
+ from streamlit_option_menu import option_menu
4
+ from roboflow import Roboflow
5
+ import supervision as sv
6
+ import numpy as np
7
+ import base64
8
+
9
+ # Initialize Roboflow client
10
+ rf = Roboflow(api_key="ywbRFI4K4ArkHodSLcw8")
11
+
12
+ # Load project and model
13
+ project = rf.workspace().project("agriweed")
14
+ model = project.version(1).model
15
+
16
+ # Initialize annotators
17
+ label_annotator = sv.LabelAnnotator()
18
+ box_annotator = sv.BoxAnnotator()
19
+
20
+ def annotate_image(input_image):
21
+ # Make predictions
22
+ result = model.predict(input_image, confidence=40, overlap=30).json()
23
+
24
+ # Extract labels from predictions
25
+ labels = [item["class"] for item in result["predictions"]]
26
+
27
+ # Create Detections object from Roboflow result
28
+ detections = sv.Detections.from_roboflow(result)
29
+
30
+ # Convert input image to numpy array
31
+ image_np = np.array(input_image)
32
+
33
+ # Annotate image with bounding boxes
34
+ annotated_image = box_annotator.annotate(scene=image_np, detections=detections)
35
+
36
+ # Annotate image with labels
37
+ annotated_image = label_annotator.annotate(scene=annotated_image, detections=detections, labels=labels)
38
+
39
+ return annotated_image
40
+
41
+ def main():
42
+
43
+ with open("bg.webp", "rb") as f:
44
+ img = f.read()
45
+ bg_img = base64.b64encode(img).decode()
46
+
47
+ page_bg_img = f"""
48
+ <style>
49
+ [data-testid="stAppViewContainer"] > .main {{
50
+ background-image: url("https://images.unsplash.com/photo-1533737979086-fdf9fdaed352?q");
51
+ background-position: 20% 50%;
52
+ background-repeat: no-repeat;
53
+ background-attachment: local;
54
+ background-color: rgba(0, 0, 0, 0.5); /* 50% opacity */
55
+ }}
56
+
57
+ [data-testid="stSidebar"] > div:first-child {{
58
+ background-image: url("data:image/png;base64,{img}");
59
+ background-position: center;
60
+ background-repeat: no-repeat;
61
+ background-attachment: fixed;
62
+ }}
63
+
64
+ [data-testid="stHeader"] {{
65
+ background: rgba(0,0,0,0);
66
+ }}
67
+
68
+ [data-testid="stToolbar"] {{
69
+ right: 2rem;
70
+ }}
71
+ </style>
72
+ """
73
+ st.markdown(page_bg_img, unsafe_allow_html=True)
74
+
75
+
76
+ with st.sidebar:
77
+ page = option_menu("Main Menu", ["Home", "About", "Contact"],
78
+ icons=['house', 'people', 'book', 'envelope'], menu_icon="cast", default_index=0)
79
+
80
+ if page == "Home":
81
+ st.title("Object Detection App")
82
+ uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
83
+
84
+ if uploaded_file is not None:
85
+ # Read the image file
86
+ input_image = cv2.imdecode(np.fromstring(uploaded_file.read(), np.uint8), cv2.IMREAD_COLOR)
87
+
88
+ # Call the annotate_image function
89
+ output_image = annotate_image(input_image)
90
+
91
+ # Display the annotated image
92
+ st.image(output_image, channels="BGR")
93
+
94
+ elif page == "About":
95
+
96
+ st.title("Crop Weed Detection")
97
+
98
+ st.markdown(
99
+ """
100
+ ## ๐ŸŒพ About Project
101
+
102
+ In the enchanting world of agriculture, where crops sway in the breeze and weeds lurk in the shadows, our valiant project, Crop Weed Detection, emerges as a beacon of hope! Armed with pixels and patterns, we embark on a noble quest to unveil the secrets of the soil and shield the crops from their leafy adversaries.
103
+
104
+ ## ๐Ÿš€ Impact
105
+
106
+ Picture a utopia where crops thrive without fear of weed invasions, where farmers can sleep soundly knowing their fields are safeguarded. Our project aspires to transform this dream into reality, one algorithmic innovation at a time.
107
+
108
+ ## ๐Ÿ‘จโ€๐Ÿ‘จโ€๐Ÿ‘ฆโ€๐Ÿ‘ฆ Team Members
109
+
110
+ - Ravi ๐Ÿง™โ€โ™‚๏ธ: The grandmaster of algorithms, Ravi weaves code like a wizard, conjuring solutions from the digital ether.
111
+ - Mahesh ๐Ÿ“Š: The data whisperer, Mahesh can coax insights from the most obstinate datasets, turning raw numbers into gold.
112
+ - Ganesh ๐Ÿค–: The neural network ninja, Ganesh trains models with the precision of a samurai, effortlessly slicing through complexity.
113
+ - Arvind ๐Ÿ”ฎ: The visionary, Arvind gazes beyond the pixels, envisioning a future where technology and agriculture harmonize for the greater good.
114
+
115
+ ## ๐Ÿ”ฎ Future Horizons
116
+
117
+ Our journey doesn't end here! We're constantly refining our algorithms, exploring new datasets, and collaborating with experts to push the boundaries of Crop Weed Detection. The future holds exciting possibilities, and we're eager to continue this adventure to revolutionize agriculture.
118
+
119
+ ## ๐ŸŒฑ Join Our Quest
120
+
121
+ Are you passionate about technology, agriculture, or making a positive impact on the world? Join us on our quest to revolutionize agriculture with Crop Weed Detection. Together, we can cultivate a brighter future for farmers and crops alike!
122
+ """
123
+ )
124
+
125
+
126
+
127
+ elif page == "Contact":
128
+
129
+ st.title("Contact Us")
130
+ st.write(":mailbox: Get In Touch With Me!")
131
+
132
+ contact_form = """
133
+ <form action="https://formsubmit.co/YOUREMAIL@EMAIL.COM" method="POST">
134
+ <input type="hidden" name="_captcha" value="false">
135
+ <input type="text" name="name" placeholder="Your name" required>
136
+ <input type="email" name="email" placeholder="Your email" required>
137
+ <textarea name="message" placeholder="Your message here"></textarea>
138
+ <button type="submit">Send</button>
139
+ </form>
140
+ """
141
+
142
+ st.markdown(contact_form, unsafe_allow_html=True)
143
+
144
+ # Use Local CSS File
145
+ def local_css(file_name):
146
+ with open(file_name) as f:
147
+ st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
148
+
149
+ local_css("style.css")
150
+
151
+
152
+
153
+
154
+ if __name__ == "__main__":
155
+ main()
bg.webp ADDED
style.css ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Style inputs with type="text", type="email"and textareas */
2
+ input[type=text], input[type=email], textarea {
3
+ width: 100%; /* Full width */
4
+ padding: 12px; /* Some padding */
5
+ border: 1px solid #ccc; /* Gray border */
6
+ border-radius: 4px; /* Rounded borders */
7
+ box-sizing: border-box; /* Make sure that padding and width stays in place */
8
+ margin-top: 6px; /* Add a top margin */
9
+ margin-bottom: 16px; /* Bottom margin */
10
+ resize: vertical /* Allow the user to vertically resize the textarea (not horizontally) */
11
+ }
12
+
13
+ /* Style the submit button with a specific background color etc */
14
+ button[type=submit] {
15
+ background-color: #04AA6D;
16
+ color: white;
17
+ padding: 12px 20px;
18
+ border: none;
19
+ border-radius: 4px;
20
+ cursor: pointer;
21
+ }
22
+
23
+