rajkhanke commited on
Commit
ee86969
·
verified ·
1 Parent(s): 460a073

Upload 6 files

Browse files
elephant_historic_data.csv ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ State,Elephants in 1993,Elephants in 1997,Elephants in 2002,Elephants in 2007,Elephants in 2012,Elephants in 2017
2
+ Arunachal Pradesh,2102,1800,1607,1690,890,1614
3
+ Assam,5524,5312,5246,5281,5620,5719
4
+ Meghalaya,2872,1840,1868,1811,1811,1754
5
+ Nagaland,178,158,145,152,212,446
6
+ Mizoram,15,22,33,12,12,7
7
+ Manipur,50,30,12,12,12,9
8
+ Tripura,100,70,40,59,59,102
9
+ West Bengal ,200,276,338,350,647,682
10
+ Jharkhand,550,618,772,624,688,679
11
+ Odisha,1750,1800,1841,1862,1930,1976
12
+ Chhattisgarh,82,89,102,122,247,247
13
+ Bihar ,0,0,0,10,10,25
14
+ Madhya Pradesh,0,0,0,7,7,7
15
+ Uttarakhand ,828,1130,1582,1346,1346,1839
16
+ Uttar Pradesh,47,70,85,380,291,232
17
+ Haryana,0,0,0,0,7,7
18
+ Himachal Pradesh,0,0,0,0,5,7
19
+ Tamil Nadu,2307,2971,3052,3867,4015,2761
20
+ Karnataka,5500,6088,5838,4035,5678,6049
21
+ Kerala,3500,3600,3850,6068,6133,5706
22
+ Andhra Pradesh,46,57,74,28,41,65
23
+ Maharashtra,2,4,3,7,4,6
24
+ Andaman & Nicobar Islands ,0,0,2,9,13,25
elephants.py ADDED
@@ -0,0 +1,254 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import folium
3
+ import plotly.express as px
4
+ from prophet import Prophet
5
+ import streamlit as st
6
+
7
+ def elephants_page():
8
+ st.markdown(
9
+ '<h1 style="text-align: center; color: lightgreen; font-weight: bold;">Elephant Monitoring in India</h1>',
10
+ unsafe_allow_html=True)
11
+
12
+ df = pd.read_csv('elephant_historic_data.csv')
13
+
14
+ # Update years list
15
+ years = ['1993', '1997', '2002', '2007', '2012', '2017']
16
+
17
+ # Add a select box for year selection
18
+ selected_year = st.selectbox('Select Year', years)
19
+
20
+ # Create a map centered around India
21
+ india_map = folium.Map(location=[17.5937, 82.9629], zoom_start=5, width=1300, height=800)
22
+
23
+ # Add bubble markers for each state based on the selected year
24
+ for i, row in df.iterrows():
25
+ state = row['State']
26
+ location = {
27
+ 'Andhra Pradesh': [15.9129, 79.7400],
28
+ 'Arunachal Pradesh': [27.1137, 93.6054],
29
+ 'Assam': [26.2006, 92.9376],
30
+ 'Bihar': [25.0961, 85.3131],
31
+ 'Chhattisgarh': [21.2787, 81.8661],
32
+ 'Goa': [15.2993, 74.1240],
33
+ 'Gujarat': [22.2587, 71.1924],
34
+ 'Jharkhand': [23.6102, 85.2799],
35
+ 'Karnataka': [15.3173, 75.7139],
36
+ 'Kerala': [10.8505, 76.2711],
37
+ 'Madhya Pradesh': [23.4734, 77.9479],
38
+ 'Maharashtra': [19.6633, 75.3202],
39
+ 'Meghalaya': [25.4670, 91.3662],
40
+ 'Mizoram': [23.1645, 92.9376],
41
+ 'Nagaland': [26.1584, 94.5624],
42
+ 'Odisha': [20.9517, 85.0985],
43
+ 'Rajasthan': [27.0238, 74.2176],
44
+ 'Tamil Nadu': [11.1271, 78.6569],
45
+ 'Telangana': [17.0220, 78.3555],
46
+ 'Tripura': [23.9408, 91.9882],
47
+ 'Uttar Pradesh': [27.2599, 79.4126],
48
+ 'Uttarakhand ': [30.0668, 79.0193],
49
+ 'West Bengal ': [22.9868, 87.8550],
50
+ 'Sikkim': [27.5330, 88.6139],
51
+ 'Jammu & Kashmir': [33.2778, 76.5765],
52
+ 'Punjab': [31.1471, 75.3412],
53
+ 'Haryana': [29.0588, 76.0856],
54
+ 'Himachal Pradesh': [31.1048, 77.1734],
55
+ 'Manipur': [24.6637, 93.9063],
56
+ 'Andaman & Nicobar Islands ': [11.7401, 92.6586]
57
+ }.get(state, [20.5937, 78.9629])
58
+
59
+ elephant_count = row[f'Elephants in {selected_year}']
60
+
61
+ if elephant_count <= 0:
62
+ continue
63
+
64
+ if elephant_count > 200:
65
+ color = 'pink'
66
+ elif elephant_count > 50:
67
+ color = 'orange'
68
+ else:
69
+ color = 'yellow'
70
+
71
+ bubble_size = 20
72
+
73
+ folium.CircleMarker(
74
+ location=location,
75
+ radius=bubble_size,
76
+ color=color,
77
+ fill=True,
78
+ fill_color=color,
79
+ fill_opacity=0.8
80
+ ).add_to(india_map)
81
+
82
+ folium.map.Marker(
83
+ location,
84
+ icon=folium.DivIcon(html=f'''
85
+ <div style="text-align: left; font-size: 8.5pt; font-weight: bold; width:{bubble_size * 0.2}px; color: black;">
86
+ {elephant_count:.0f}
87
+ </div>''')
88
+ ).add_to(india_map)
89
+
90
+ title_html = f'''
91
+ <h3 align="center" style="font-size:20px"><b>Elephant Count in India ({selected_year})</b></h3>
92
+ '''
93
+ india_map.get_root().html.add_child(folium.Element(title_html))
94
+
95
+ legend_html = '''
96
+ <div style="position: fixed;
97
+ bottom: 50px; left: 50px; width: 150px; height: 110px;
98
+ border:2px solid grey; z-index:9999; font-size:12px;
99
+ background-color:white; padding: 10px;">
100
+ <b>Elephant Frequency</b><br>
101
+ <i class="fa fa-circle" style="color:pink"></i> > 200 Elephants<br>
102
+ <i class="fa fa-circle" style="color:orange"></i> 50-200 Elephants<br>
103
+ <i class="fa fa-circle" style="color:yellow"></i> < 50 Elephants<br>
104
+ </div>
105
+ '''
106
+ india_map.get_root().html.add_child(folium.Element(legend_html))
107
+
108
+ st.components.v1.html(india_map._repr_html_(), height=700)
109
+
110
+ selected_state = st.selectbox('Select a State', df['State'].unique())
111
+
112
+ state_data = df[df['State'] == selected_state]
113
+
114
+ # Reshape the DataFrame
115
+ state_data = state_data.melt(id_vars=['State'], var_name='Year', value_name='Elephant Count')
116
+ state_data['Year'] = state_data['Year'].str.extract(r'(\d{4})').astype(int)
117
+
118
+ line_fig = px.line(state_data, x='Year', y='Elephant Count', title=f'Elephant Population Over Time in {selected_state}')
119
+ bar_fig = px.bar(state_data, x='Year', y='Elephant Count', title=f'Elephant Population Count in {selected_state}')
120
+
121
+ col1, col2 = st.columns(2)
122
+
123
+ with col1:
124
+ st.plotly_chart(line_fig)
125
+
126
+ with col2:
127
+ st.plotly_chart(bar_fig)
128
+
129
+ st.subheader('Predict Future Elephant Counts')
130
+ future_year = st.number_input('Enter Future Year (2025 and onwards)', min_value=2025, step=1)
131
+
132
+ # Add a button to start the prediction
133
+ if st.button('Start Prediction'):
134
+ if future_year >= 2025:
135
+ future_data = []
136
+ for state in df['State'].unique():
137
+ state_df = df[df['State'] == state]
138
+ state_df = state_df.melt(id_vars=['State'], var_name='Year', value_name='Elephant Count')
139
+ state_df['Year'] = state_df['Year'].str.extract(r'(\d{4})').astype(int)
140
+ state_df = state_df.rename(columns={'Year': 'ds', 'Elephant Count': 'y'})
141
+ state_df['ds'] = pd.to_datetime(state_df['ds'], format='%Y') # Ensure correct date format
142
+
143
+ # Use Prophet for forecasting
144
+ model = Prophet()
145
+ state_df = state_df[['ds', 'y']]
146
+ model.fit(state_df)
147
+
148
+ future = pd.DataFrame({'ds': pd.date_range(start='2023-01-01', periods=future_year - 2022, freq='Y')})
149
+ forecast = model.predict(future)
150
+
151
+ # Ensure forecast is not empty
152
+ if forecast['yhat'].size > 0:
153
+ future_elephant_count = abs(
154
+ forecast['yhat'].iloc[-1]) # Use absolute value to handle negative predictions
155
+ else:
156
+ future_elephant_count = 0 # Default value if forecast is empty
157
+
158
+ # Only append data if the elephant count is greater than zero
159
+ if future_elephant_count > 0:
160
+ future_data.append(
161
+ {'State': state, 'Year': future_year, 'Predicted Elephant Count': future_elephant_count})
162
+
163
+ future_df = pd.DataFrame(future_data)
164
+
165
+ # Map for predicted elephant counts
166
+ pred_map = folium.Map(location=[17.5937, 82.9629], zoom_start=5, width=1300, height=800)
167
+
168
+ for i, row in future_df.iterrows():
169
+ state = row['State']
170
+ location = {
171
+ 'Andhra Pradesh': [15.9129, 79.7400],
172
+ 'Arunachal Pradesh': [27.1137, 93.6054],
173
+ 'Assam': [26.2006, 92.9376],
174
+ 'Bihar': [25.0961, 85.3131],
175
+ 'Chhattisgarh': [21.2787, 81.8661],
176
+ 'Goa': [15.2993, 74.1240],
177
+ 'Gujarat': [22.2587, 71.1924],
178
+ 'Jharkhand': [23.6102, 85.2799],
179
+ 'Karnataka': [15.3173, 75.7139],
180
+ 'Kerala': [10.8505, 76.2711],
181
+ 'Madhya Pradesh': [23.4734, 77.9479],
182
+ 'Maharashtra': [19.6633, 75.3202],
183
+ 'Meghalaya': [25.4670, 91.3662],
184
+ 'Mizoram': [23.1645, 92.9376],
185
+ 'Nagaland': [26.1584, 94.5624],
186
+ 'Odisha': [20.9517, 85.0985],
187
+ 'Rajasthan': [27.0238, 74.2176],
188
+ 'Tamil Nadu': [11.1271, 78.6569],
189
+ 'Telangana': [17.0220, 78.3555],
190
+ 'Tripura': [23.9408, 91.9882],
191
+ 'Uttar Pradesh': [27.2599, 79.4126],
192
+ 'Uttarakhand ': [30.0668, 79.0193],
193
+ 'West Bengal ': [22.9868, 87.8550],
194
+ 'Sikkim': [27.5330, 88.6139],
195
+ 'Jammu & Kashmir': [33.2778, 76.5765],
196
+ 'Punjab': [31.1471, 75.3412],
197
+ 'Haryana': [29.0588, 76.0856],
198
+ 'Himachal Pradesh': [31.1048, 77.1734],
199
+ 'Manipur': [24.6637, 93.9063],
200
+ 'Andaman & Nicobar Islands ': [11.7401, 92.6586]
201
+ }.get(state, [20.5937, 78.9629])
202
+
203
+ predicted_count = row['Predicted Elephant Count']
204
+
205
+ if predicted_count > 200:
206
+ color = 'pink'
207
+ elif predicted_count > 50:
208
+ color = 'orange'
209
+ else:
210
+ color = 'yellow'
211
+
212
+ bubble_size = 20
213
+
214
+ folium.CircleMarker(
215
+ location=location,
216
+ radius=bubble_size,
217
+ color=color,
218
+ fill=True,
219
+ fill_color=color,
220
+ fill_opacity=0.8
221
+ ).add_to(pred_map)
222
+
223
+ folium.map.Marker(
224
+ location,
225
+ icon=folium.DivIcon(html=f'''
226
+ <div style="text-align: left; font-size: 8.5pt; font-weight: bold; width:{bubble_size * 0.2}px; color: black;">
227
+ {predicted_count:.0f}
228
+ </div>''')
229
+ ).add_to(pred_map)
230
+
231
+ pred_title_html = f'''
232
+ <h3 align="center" style="font-size:20px"><b>Predicted Elephant Count in {future_year}</b></h3>
233
+ '''
234
+ pred_map.get_root().html.add_child(folium.Element(pred_title_html))
235
+
236
+ pred_legend_html = '''
237
+ <div style="position: fixed;
238
+ bottom: 50px; left: 50px; width: 150px; height: 110px;
239
+ border:2px solid grey; z-index:9999; font-size:12px;
240
+ background-color:white; padding: 10px;">
241
+ <b>Predicted Elephant Frequency</b><br>
242
+ <i class="fa fa-circle" style="color:pink"></i> > 200 Elephants<br>
243
+ <i class="fa fa-circle" style="color:orange"></i> 50-200 Elephants<br>
244
+ <i class="fa fa-circle" style="color:yellow"></i> < 50 Elephants<br>
245
+ </div>
246
+ '''
247
+ pred_map.get_root().html.add_child(folium.Element(pred_legend_html))
248
+
249
+ st.components.v1.html(pred_map._repr_html_(), height=700)
250
+
251
+ # Add your Streamlit app configuration and page registration
252
+ if __name__ == '__main__':
253
+ st.set_page_config(page_title='Elephant Monitoring', layout='wide')
254
+ elephants_page()
leopard.py ADDED
@@ -0,0 +1,251 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import folium
3
+ import plotly.express as px
4
+ from prophet import Prophet
5
+ import streamlit as st
6
+
7
+ def leopard_page():
8
+ st.markdown(
9
+ '<h1 style="text-align: center; color: orange; font-weight: bold;">Leopard Monitoring in India</h1>',
10
+ unsafe_allow_html=True)
11
+
12
+ df = pd.read_csv('leopard_historic_data.csv')
13
+
14
+ # Add a select box for year selection
15
+ selected_year = st.selectbox('Select Year', ['2006', '2010', '2014', '2018', '2024'])
16
+
17
+ # Create a map centered around India
18
+ india_map = folium.Map(location=[17.5937, 82.9629], zoom_start=5, width=1300, height=800)
19
+
20
+ # Add bubble markers for each state based on the selected year
21
+ for i, row in df.iterrows():
22
+ state = row['State']
23
+ location = {
24
+ 'Andhra Pradesh': [15.9129, 79.7400],
25
+ 'Arunachal Pradesh': [27.1137, 93.6054],
26
+ 'Assam': [26.2006, 92.9376],
27
+ 'Bihar': [25.0961, 85.3131],
28
+ 'Chhattisgarh': [21.2787, 81.8661],
29
+ 'Goa': [15.2993, 74.1240],
30
+ 'Gujarat': [22.2587, 71.1924],
31
+ 'Jharkhand': [23.6102, 85.2799],
32
+ 'Karnataka': [15.3173, 75.7139],
33
+ 'Kerala': [10.8505, 76.2711],
34
+ 'Madhya Pradesh': [23.4734, 77.9479],
35
+ 'Maharashtra': [19.6633, 75.3202],
36
+ 'Meghalaya': [25.4670, 91.3662],
37
+ 'Mizoram': [23.1645, 92.9376],
38
+ 'Nagaland': [26.1584, 94.5624],
39
+ 'Odisha': [20.9517, 85.0985],
40
+ 'Rajasthan': [27.0238, 74.2176],
41
+ 'Tamil Nadu': [11.1271, 78.6569],
42
+ 'Telangana': [17.0220, 78.3555],
43
+ 'Tripura': [23.9408, 91.9882],
44
+ 'Uttar Pradesh': [27.2599, 79.4126],
45
+ 'Uttarakhand': [30.0668, 79.0193],
46
+ 'West Bengal': [22.9868, 87.8550],
47
+ 'Sikkim': [27.5330, 88.6139],
48
+ 'Jammu & Kashmir': [33.2778, 76.5765],
49
+ 'Punjab': [31.1471, 75.3412],
50
+ 'Haryana': [29.0588, 76.0856],
51
+ 'Himachal Pradesh': [31.1048, 77.1734],
52
+ 'Manipur': [24.6637, 93.9063]
53
+ }.get(state, [20.5937, 78.9629])
54
+
55
+ leopard_count = row[f'Leopards in {selected_year}']
56
+
57
+ if leopard_count <= 0:
58
+ continue
59
+
60
+ if leopard_count > 200:
61
+ color = 'green'
62
+ elif leopard_count > 50:
63
+ color = 'purple'
64
+ else:
65
+ color = 'orange'
66
+
67
+ bubble_size = 20
68
+
69
+ folium.CircleMarker(
70
+ location=location,
71
+ radius=bubble_size,
72
+ color=color,
73
+ fill=True,
74
+ fill_color=color,
75
+ fill_opacity=0.8
76
+ ).add_to(india_map)
77
+
78
+ folium.map.Marker(
79
+ location,
80
+ icon=folium.DivIcon(html=f'''
81
+ <div style="text-align: left; font-size: 8.5pt; font-weight: bold; width:{bubble_size * 0.4}px; color: black;">
82
+ {leopard_count:.0f}
83
+ </div>''')
84
+ ).add_to(india_map)
85
+
86
+ title_html = f'''
87
+ <h3 align="center" style="font-size:20px"><b>Leopard Count in India ({selected_year})</b></h3>
88
+ '''
89
+ india_map.get_root().html.add_child(folium.Element(title_html))
90
+
91
+ legend_html = '''
92
+ <div style="position: fixed;
93
+ bottom: 50px; left: 50px; width: 150px; height: 120px;
94
+ border:2px solid grey; z-index:9999; font-size:14px;
95
+ background-color:white; padding: 10px;">
96
+ <b>Leopard Frequency</b><br>
97
+ <i class="fa fa-circle" style="color:green"></i> > 200 Leopards<br>
98
+ <i class="fa fa-circle" style="color:purple"></i> 50-200 Leopards<br>
99
+ <i class="fa fa-circle" style="color:orange"></i> < 50 Leopards<br>
100
+ </div>
101
+ '''
102
+ india_map.get_root().html.add_child(folium.Element(legend_html))
103
+
104
+ st.components.v1.html(india_map._repr_html_(), height=700)
105
+
106
+ selected_state = st.selectbox('Select a State', df['State'].unique())
107
+
108
+ state_data = df[df['State'] == selected_state]
109
+
110
+ # Reshape the DataFrame
111
+ state_data = state_data.melt(id_vars=['State'], var_name='Year', value_name='Leopard Count')
112
+ state_data['Year'] = state_data['Year'].str.extract(r'(\d{4})').astype(int)
113
+
114
+ line_fig = px.line(state_data, x='Year', y='Leopard Count',
115
+ title=f'Leopard Population Over Time in {selected_state}')
116
+ bar_fig = px.bar(state_data, x='Year', y='Leopard Count', title=f'Leopard Population Count in {selected_state}')
117
+
118
+ col1, col2 = st.columns(2)
119
+
120
+ with col1:
121
+ st.plotly_chart(line_fig)
122
+
123
+ with col2:
124
+ st.plotly_chart(bar_fig)
125
+
126
+ st.subheader('Predict Future Leopard Counts')
127
+ future_year = st.number_input('Enter Future Year (2025 and onwards)', min_value=2025, step=1)
128
+
129
+ # Add a button to start the prediction
130
+ if st.button('Start Prediction'):
131
+ if future_year >= 2025:
132
+ future_data = []
133
+ for state in df['State'].unique():
134
+ state_df = df[df['State'] == state]
135
+ state_df = state_df.melt(id_vars=['State'], var_name='Year', value_name='Leopard Count')
136
+ state_df['Year'] = state_df['Year'].str.extract(r'(\d{4})').astype(int)
137
+ state_df = state_df.rename(columns={'Year': 'ds', 'Leopard Count': 'y'})
138
+ state_df['ds'] = pd.to_datetime(state_df['ds'], format='%Y') # Ensure correct date format
139
+
140
+ # Use Prophet for forecasting
141
+ model = Prophet()
142
+ state_df = state_df[['ds', 'y']]
143
+ model.fit(state_df)
144
+
145
+ future = pd.DataFrame({'ds': pd.date_range(start='2023-01-01', periods=future_year - 2022, freq='Y')})
146
+ forecast = model.predict(future)
147
+
148
+ # Ensure forecast is not empty
149
+ if forecast['yhat'].size > 0:
150
+ future_leopard_count = abs(
151
+ forecast['yhat'].iloc[-1]) # Use absolute value to handle negative predictions
152
+ else:
153
+ future_leopard_count = 0 # Default value if forecast is empty
154
+
155
+ # Only append data if the leopard count is greater than zero
156
+ if future_leopard_count > 0:
157
+ future_data.append(
158
+ {'State': state, 'Year': future_year, 'Predicted Leopard Count': future_leopard_count})
159
+
160
+ future_df = pd.DataFrame(future_data)
161
+
162
+ # Create a map for the future predicted leopard counts
163
+ future_map = folium.Map(location=[17.5937, 82.9629], zoom_start=5, width=1300, height=800)
164
+
165
+ for i, row in future_df.iterrows():
166
+ state = row['State']
167
+ location = {
168
+ 'Andhra Pradesh': [15.9129, 79.7400],
169
+ 'Arunachal Pradesh': [27.1137, 93.6054],
170
+ 'Assam': [26.2006, 92.9376],
171
+ 'Bihar': [25.0961, 85.3131],
172
+ 'Chhattisgarh': [21.2787, 81.8661],
173
+ 'Goa': [15.2993, 74.1240],
174
+ 'Gujarat': [22.2587, 71.1924],
175
+ 'Jharkhand': [23.6102, 85.2799],
176
+ 'Karnataka': [15.3173, 75.7139],
177
+ 'Kerala': [10.8505, 76.2711],
178
+ 'Madhya Pradesh': [23.4734, 77.9479],
179
+ 'Maharashtra': [19.6633, 75.3202],
180
+ 'Meghalaya': [25.4670, 91.3662],
181
+ 'Mizoram': [23.1645, 92.9376],
182
+ 'Nagaland': [26.1584, 94.5624],
183
+ 'Odisha': [20.9517, 85.0985],
184
+ 'Rajasthan': [27.0238, 74.2176],
185
+ 'Tamil Nadu': [11.1271, 78.6569],
186
+ 'Telangana': [17.0220, 78.3555],
187
+ 'Tripura': [23.9408, 91.9882],
188
+ 'Uttar Pradesh': [27.2599, 79.4126],
189
+ 'Uttarakhand': [30.0668, 79.0193],
190
+ 'West Bengal': [22.9868, 87.8550],
191
+ 'Sikkim': [27.5330, 88.6139],
192
+ 'Jammu & Kashmir': [33.2778, 76.5765],
193
+ 'Punjab': [31.1471, 75.3412],
194
+ 'Haryana': [29.0588, 76.0856],
195
+ 'Himachal Pradesh': [31.1048, 77.1734],
196
+ 'Manipur': [24.6637, 93.9063]
197
+ }.get(state, [20.5937, 78.9629])
198
+
199
+ leopard_count = row['Predicted Leopard Count']
200
+
201
+ if leopard_count <= 0:
202
+ continue
203
+
204
+ if leopard_count > 200:
205
+ color = 'green'
206
+ elif leopard_count > 50:
207
+ color = 'purple'
208
+ else:
209
+ color = 'orange'
210
+
211
+ bubble_size = 20
212
+
213
+ folium.CircleMarker(
214
+ location=location,
215
+ radius=bubble_size,
216
+ color=color,
217
+ fill=True,
218
+ fill_color=color,
219
+ fill_opacity=0.8
220
+ ).add_to(future_map)
221
+
222
+ folium.map.Marker(
223
+ location,
224
+ icon=folium.DivIcon(html=f'''
225
+ <div style="text-align: left; font-size: 8.5pt; font-weight: bold; width:{bubble_size * 0.4}px; color: black;">
226
+ {leopard_count:.0f}
227
+ </div>''')
228
+ ).add_to(future_map)
229
+
230
+ title_html = f'''
231
+ <h3 align="center" style="font-size:20px"><b>Predicted Leopard Count in India ({future_year})</b></h3>
232
+ '''
233
+ future_map.get_root().html.add_child(folium.Element(title_html))
234
+
235
+ legend_html = '''
236
+ <div style="position: fixed;
237
+ bottom: 50px; left: 50px; width: 150px; height: 120px;
238
+ border:2px solid grey; z-index:9999; font-size:14px;
239
+ background-color:white; padding: 10px;">
240
+ <b>Leopard Frequency</b><br>
241
+ <i class="fa fa-circle" style="color:blue"></i> > 200 Leopards<br>
242
+ <i class="fa fa-circle" style="color:purple"></i> 50-200 Leopards<br>
243
+ <i class="fa fa-circle" style="color:orange"></i> < 50 Leopards<br>
244
+ </div>
245
+ '''
246
+ future_map.get_root().html.add_child(folium.Element(legend_html))
247
+
248
+ st.components.v1.html(future_map._repr_html_(), height=900)
249
+
250
+ else:
251
+ st.error("Please enter a year greater than or equal to 2025.")
leopard_historic_data.csv ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ State,Leopards in 2006,Leopards in 2010,Leopards in 2014,Leopards in 2018,Leopards in 2024
2
+ Andhra Pradesh,89,120,134,320,343
3
+ Arunachal Pradesh,1,2,5,20,27
4
+ Assam,100,150,180,200,324
5
+ Bihar,5,10,25,40,25
6
+ Chhattisgarh,250,260,270,480,447
7
+ Goa,5,7,15,30,0
8
+ Gujarat,500,600,1100,1300,1355
9
+ Jharkhand,5,10,20,30,29
10
+ Karnataka,789,686,1245,1456,1131
11
+ Kerala,200,500,600,650,472
12
+ Madhya Pradesh,300,500,1000,2000,1817
13
+ Maharashtra,400,600,1000,1400,908
14
+ Meghalaya,1,2,5,10,0
15
+ Mizoram,2,3,7,8,0
16
+ Nagaland,1,2,4,6,0
17
+ Odisha,600,700,750,800,345
18
+ Rajasthan,60,70,80,100,194
19
+ Tamil Nadu,800,900,950,1000,815
20
+ Telangana,2,5,10,20,268
21
+ Tripura,2,3,4,5,0
22
+ Uttar Pradesh,220,250,270,300,194
23
+ Uttarakhand,800,1000,1200,1500,703
24
+ West Bengal,30,50,80,100,233
25
+ Sikkim,10,20,30,40,0
26
+ Jammu & Kashmir,2,3,5,7,0
27
+ Punjab,2,5,8,10,0
28
+ Haryana,3,5,6,8,0
29
+ Himachal Pradesh,2,3,5,7,0
30
+ Manipur,2,4,5,7,0
tiger_historic_data.xlsx ADDED
Binary file (10.9 kB). View file
 
tigers.py ADDED
@@ -0,0 +1,249 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import folium
3
+ import plotly.express as px
4
+ from prophet import Prophet
5
+ import streamlit as st
6
+
7
+ def tigers_page():
8
+ st.markdown(
9
+ '<h1 style="text-align: center; color: skyblue; font-weight: bold;">Tiger Monitoring in India</h1>',
10
+ unsafe_allow_html=True)
11
+
12
+ df = pd.read_excel('tiger_historic_data.xlsx')
13
+
14
+ # Add a select box for year selection
15
+ selected_year = st.selectbox('Select Year', ['2006', '2010', '2014', '2018', '2022'])
16
+
17
+ # Create a map centered around India
18
+ india_map = folium.Map(location=[17.5937, 82.9629], zoom_start=5, width=1300, height=800)
19
+
20
+ # Add bubble markers for each state based on the selected year
21
+ for i, row in df.iterrows():
22
+ state = row['State']
23
+ location = {
24
+ 'Andhra Pradesh': [15.9129, 79.7400],
25
+ 'Arunachal Pradesh': [27.1137, 93.6054],
26
+ 'Assam': [26.2006, 92.9376],
27
+ 'Bihar': [25.0961, 85.3131],
28
+ 'Chhattisgarh': [21.2787, 81.8661],
29
+ 'Goa': [15.2993, 74.1240],
30
+ 'Gujarat': [22.2587, 71.1924],
31
+ 'Jharkhand': [23.6102, 85.2799],
32
+ 'Karnataka': [15.3173, 75.7139],
33
+ 'Kerala': [10.8505, 76.2711],
34
+ 'Madhya Pradesh': [23.4734, 77.9479],
35
+ 'Maharashtra': [19.6633, 75.3202],
36
+ 'Meghalaya': [25.4670, 91.3662],
37
+ 'Mizoram': [23.1645, 92.9376],
38
+ 'Nagaland': [26.1584, 94.5624],
39
+ 'Odisha': [20.9517, 85.0985],
40
+ 'Rajasthan': [27.0238, 74.2176],
41
+ 'Tamil Nadu': [11.1271, 78.6569],
42
+ 'Telangana': [17.0220, 78.3555],
43
+ 'Tripura': [23.9408, 91.9882],
44
+ 'Uttar Pradesh': [27.2599, 79.4126],
45
+ 'Uttarakhand': [30.0668, 79.0193],
46
+ 'West Bengal': [22.9868, 87.8550],
47
+ 'Sikkim': [27.5330, 88.6139],
48
+ 'Jammu & Kashmir': [33.2778, 76.5765],
49
+ 'Punjab': [31.1471, 75.3412],
50
+ 'Haryana': [29.0588, 76.0856],
51
+ 'Himachal Pradesh': [31.1048, 77.1734],
52
+ 'Manipur': [24.6637, 93.9063]
53
+ }.get(state, [20.5937, 78.9629])
54
+
55
+ tiger_count = row[f'Tigers in {selected_year}']
56
+
57
+ if tiger_count <= 0:
58
+ continue
59
+
60
+ if tiger_count > 200:
61
+ color = 'green'
62
+ elif tiger_count > 50:
63
+ color = 'yellow'
64
+ else:
65
+ color = 'red'
66
+
67
+ bubble_size = 20
68
+
69
+ folium.CircleMarker(
70
+ location=location,
71
+ radius=bubble_size,
72
+ color=color,
73
+ fill=True,
74
+ fill_color=color,
75
+ fill_opacity=0.8
76
+ ).add_to(india_map)
77
+
78
+ folium.map.Marker(
79
+ location,
80
+ icon=folium.DivIcon(html=f'''
81
+ <div style="text-align: left; font-size: 10pt; font-weight: bold; width:{bubble_size * 2}px; color: black;">
82
+ {tiger_count:.0f}
83
+ </div>''')
84
+ ).add_to(india_map)
85
+
86
+ title_html = f'''
87
+ <h3 align="center" style="font-size:20px"><b>Tiger Count in India ({selected_year})</b></h3>
88
+ '''
89
+ india_map.get_root().html.add_child(folium.Element(title_html))
90
+
91
+ legend_html = '''
92
+ <div style="position: fixed;
93
+ bottom: 50px; left: 50px; width: 150px; height: 120px;
94
+ border:2px solid grey; z-index:9999; font-size:14px;
95
+ background-color:white; padding: 10px;">
96
+ <b>Tiger Frequency</b><br>
97
+ <i class="fa fa-circle" style="color:green"></i> > 200 Tigers<br>
98
+ <i class="fa fa-circle" style="color:yellow"></i> 50-200 Tigers<br>
99
+ <i class="fa fa-circle" style="color:red"></i> < 50 Tigers<br>
100
+ </div>
101
+ '''
102
+ india_map.get_root().html.add_child(folium.Element(legend_html))
103
+
104
+ st.components.v1.html(india_map._repr_html_(), height=700)
105
+
106
+ selected_state = st.selectbox('Select a State', df['State'].unique())
107
+
108
+ state_data = df[df['State'] == selected_state]
109
+
110
+ # Reshape the DataFrame
111
+ state_data = state_data.melt(id_vars=['State'], var_name='Year', value_name='Tiger Count')
112
+ state_data['Year'] = state_data['Year'].str.extract(r'(\d{4})').astype(int)
113
+
114
+ line_fig = px.line(state_data, x='Year', y='Tiger Count', title=f'Tiger Population Over Time in {selected_state}')
115
+ bar_fig = px.bar(state_data, x='Year', y='Tiger Count', title=f'Tiger Population Count in {selected_state}')
116
+
117
+ col1, col2 = st.columns(2)
118
+
119
+ with col1:
120
+ st.plotly_chart(line_fig)
121
+
122
+ with col2:
123
+ st.plotly_chart(bar_fig)
124
+
125
+ st.subheader('Predict Future Tiger Counts')
126
+ future_year = st.number_input('Enter Future Year (2025 and onwards)', min_value=2025, step=1)
127
+
128
+ # Add a button to start the prediction
129
+ if st.button('Start Prediction'):
130
+ if future_year >= 2025:
131
+ future_data = []
132
+ for state in df['State'].unique():
133
+ state_df = df[df['State'] == state]
134
+ state_df = state_df.melt(id_vars=['State'], var_name='Year', value_name='Tiger Count')
135
+ state_df['Year'] = state_df['Year'].str.extract(r'(\d{4})').astype(int)
136
+ state_df = state_df.rename(columns={'Year': 'ds', 'Tiger Count': 'y'})
137
+ state_df['ds'] = pd.to_datetime(state_df['ds'], format='%Y') # Ensure correct date format
138
+
139
+ # Use Prophet for forecasting
140
+ model = Prophet()
141
+ state_df = state_df[['ds', 'y']]
142
+ model.fit(state_df)
143
+
144
+ future = pd.DataFrame({'ds': pd.date_range(start='2023-01-01', periods=future_year - 2022, freq='Y')})
145
+ forecast = model.predict(future)
146
+
147
+ # Ensure forecast is not empty
148
+ if forecast['yhat'].size > 0:
149
+ future_tiger_count = abs(
150
+ forecast['yhat'].iloc[-1]) # Use absolute value to handle negative predictions
151
+ else:
152
+ future_tiger_count = 0 # Default value if forecast is empty
153
+
154
+ # Only append data if the tiger count is greater than zero
155
+ if future_tiger_count > 0:
156
+ future_data.append(
157
+ {'State': state, 'Year': future_year, 'Predicted Tiger Count': future_tiger_count})
158
+
159
+ future_df = pd.DataFrame(future_data)
160
+
161
+ # Map for predicted tiger counts
162
+ pred_map = folium.Map(location=[17.5937, 82.9629], zoom_start=5, width=1300, height=800)
163
+
164
+ for i, row in future_df.iterrows():
165
+ state = row['State']
166
+ location = {
167
+ 'Andhra Pradesh': [15.9129, 79.7400],
168
+ 'Arunachal Pradesh': [27.1137, 93.6054],
169
+ 'Assam': [26.2006, 92.9376],
170
+ 'Bihar': [25.0961, 85.3131],
171
+ 'Chhattisgarh': [21.2787, 81.8661],
172
+ 'Goa': [15.2993, 74.1240],
173
+ 'Gujarat': [22.2587, 71.1924],
174
+ 'Jharkhand': [23.6102, 85.2799],
175
+ 'Karnataka': [15.3173, 75.7139],
176
+ 'Kerala': [10.8505, 76.2711],
177
+ 'Madhya Pradesh': [23.4734, 77.9479],
178
+ 'Maharashtra': [19.6633, 75.3202],
179
+ 'Meghalaya': [25.4670, 91.3662],
180
+ 'Mizoram': [23.1645, 92.9376],
181
+ 'Nagaland': [26.1584, 94.5624],
182
+ 'Odisha': [20.9517, 85.0985],
183
+ 'Rajasthan': [27.0238, 74.2176],
184
+ 'Tamil Nadu': [11.1271, 78.6569],
185
+ 'Telangana': [17.0220, 78.3555],
186
+ 'Tripura': [23.9408, 91.9882],
187
+ 'Uttar Pradesh': [27.2599, 79.4126],
188
+ 'Uttarakhand': [30.0668, 79.0193],
189
+ 'West Bengal': [22.9868, 87.8550],
190
+ 'Sikkim': [27.5330, 88.6139],
191
+ 'Jammu & Kashmir': [33.2778, 76.5765],
192
+ 'Punjab': [31.1471, 75.3412],
193
+ 'Haryana': [29.0588, 76.0856],
194
+ 'Himachal Pradesh': [31.1048, 77.1734],
195
+ 'Manipur': [24.6637, 93.9063]
196
+ }.get(state, [20.5937, 78.9629])
197
+
198
+ predicted_count = row['Predicted Tiger Count']
199
+
200
+ if predicted_count <= 0:
201
+ continue
202
+
203
+ if predicted_count > 200:
204
+ color = 'green'
205
+ elif predicted_count > 50:
206
+ color = 'yellow'
207
+ else:
208
+ color = 'red'
209
+
210
+ bubble_size = 20
211
+
212
+ folium.CircleMarker(
213
+ location=location,
214
+ radius=bubble_size,
215
+ color=color,
216
+ fill=True,
217
+ fill_color=color,
218
+ fill_opacity=0.8
219
+ ).add_to(pred_map)
220
+
221
+ folium.map.Marker(
222
+ location,
223
+ icon=folium.DivIcon(html=f'''
224
+ <div style="text-align: left; font-size: 9pt; font-weight: bold; width:{bubble_size * 0.4}px; color: black;">
225
+ {predicted_count:.0f}
226
+ </div>''')
227
+ ).add_to(pred_map)
228
+
229
+ title_html = f'''
230
+ <h3 align="center" style="font-size:20px"><b>Predicted Tiger Count in India ({future_year})</b></h3>
231
+ '''
232
+ pred_map.get_root().html.add_child(folium.Element(title_html))
233
+
234
+ legend_html = '''
235
+ <div style="position: fixed;
236
+ bottom: 50px; left: 50px; width: 150px; height: 120px;
237
+ border:2px solid grey; z-index:9999; font-size:14px;
238
+ background-color:white; padding: 10px;">
239
+ <b>Tiger Frequency</b><br>
240
+ <i class="fa fa-circle" style="color:green"></i> > 200 Tigers<br>
241
+ <i class="fa fa-circle" style="color:yellow"></i> 50-200 Tigers<br>
242
+ <i class="fa fa-circle" style="color:red"></i> < 50 Tigers<br>
243
+ </div>
244
+ '''
245
+ pred_map.get_root().html.add_child(folium.Element(legend_html))
246
+
247
+ st.components.v1.html(pred_map._repr_html_(), height=800)
248
+ else:
249
+ st.error("Please enter a year greater than or equal to 2025.")