Sanjayraju30 commited on
Commit
f823761
Β·
verified Β·
1 Parent(s): 82990f2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +257 -72
app.py CHANGED
@@ -1,82 +1,267 @@
 
 
 
 
1
  import streamlit as st
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  import pandas as pd
3
- import folium
4
- from streamlit_folium import st_folium
5
- from folium.plugins import HeatMap
6
- import random
7
 
8
- # ---- Simulated Smart Pole Data ----
9
- AREAS = {
10
- "Hyderabad": [17.4036, 78.5247],
11
- "Ballari": [15.1468, 76.9237],
12
- "Kurnool": [15.8281, 78.0373],
13
- "Gadwal": [16.2315, 77.7965]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  }
15
 
16
- def generate_poles(site, lat, lon, count=12):
17
- data = []
18
- for i in range(count):
19
- lat_offset = random.uniform(-0.002, 0.002)
20
- lon_offset = random.uniform(-0.002, 0.002)
21
- energy = round(random.uniform(20, 100), 2)
22
- wind = round(random.uniform(0, 20), 2)
23
- sensor = round(random.uniform(0, 1), 2)
24
- alert = random.choice(["Normal", "Alert"])
25
- data.append({
26
- "Site": site,
27
- "Pole ID": f"{site[:3].upper()}-{i+1:03}",
28
- "Latitude": lat + lat_offset,
29
- "Longitude": lon + lon_offset,
30
- "Energy": energy,
31
- "Wind": wind,
32
- "Sensor": sensor,
33
- "Alert": alert
 
 
 
 
 
 
 
 
 
34
  })
35
- return data
36
 
37
- # Generate full dataset
38
- poles_data = []
39
- for area, coords in AREAS.items():
40
- poles_data.extend(generate_poles(area, coords[0], coords[1]))
 
41
 
42
- df = pd.DataFrame(poles_data)
43
 
44
  # ---- Streamlit UI ----
45
- st.set_page_config(layout="wide")
46
- st.title("🌐 Hugging Face Compatible Solar Pole Heatmap")
47
-
48
- # ---- Create Folium Map with Esri Satellite ----
49
- center = [16.5, 77.5]
50
- m = folium.Map(location=center, zoom_start=7,
51
- tiles='https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',
52
- attr='Esri Satellite')
53
-
54
- # ---- Add HeatMap layer for energy ----
55
- heat_data = [[row["Latitude"], row["Longitude"], row["Energy"]] for _, row in df.iterrows()]
56
- HeatMap(heat_data, radius=15).add_to(m)
57
-
58
- # ---- Add Pole Markers with Alerts ----
59
- for _, row in df.iterrows():
60
- popup_html = f"""
61
- <b>Pole ID:</b> {row['Pole ID']}<br/>
62
- <b>Site:</b> {row['Site']}<br/>
63
- <b>Energy:</b> {row['Energy']}<br/>
64
- <b>Wind:</b> {row['Wind']}<br/>
65
- <b>Sensor:</b> {row['Sensor']}<br/>
66
- <b>Status:</b> {row['Alert']}
67
- """
68
-
69
- icon = folium.Icon(color="red" if row["Alert"] == "Alert" else "green", icon="info-sign")
70
- folium.Marker(
71
- location=[row["Latitude"], row["Longitude"]],
72
- popup=popup_html,
73
- icon=icon
74
- ).add_to(m)
75
-
76
- # ---- Display Map ----
77
- st.subheader("πŸ—ΊοΈ Smart Pole Satellite Heatmap")
78
- st_data = st_folium(m, width=1200, height=600)
79
-
80
- # ---- Optional: Table view
81
- with st.expander("πŸ“‹ Show Pole Data Table"):
82
- st.dataframe(df)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ You said:
3
+ import random
4
+ import pandas as pd
5
  import streamlit as st
6
+ import pydeck as pdk
7
+
8
+ # ---- Area-Specific Configuration ----
9
+ AREA_DETAILS = {
10
+ "Hyderabad": {
11
+ "coords": [17.4036, 78.5247],
12
+ "area_name": "Ramanthapur Dairy Farm",
13
+ "purpose": "Dairy Farm"
14
+ },
15
+ "Ballari": {
16
+ "coords": [15.1468, 76.9237],
17
+ "area_name": "Cowl Bazar Power Station",
18
+ "purpose": "Power Station"
19
+ },
20
+ "Gadwal": {
21
+ "coords": [16.2315, 77.7965],
22
+ "area_name": "Bheem Nagar Solar Station",
23
+ "purpose": "Solar Station"
24
+ },
25
+ "Kurnool": {
26
+ "coords": [15.8281, 78.0373],
27
+ "area_name": "Venkata Ramana Agriculture Field",
28
+ "purpose": "Agriculture Monitoring"
29
+ }
30
+ }
31
+
32
+ POLES_PER_SITE = 12
33
+
34
+ # ---- Generate Poles with Anomalies ----
35
+ def generate_open_area_poles(site_name, center_lat, center_lon, area, purpose):
36
+ poles = []
37
+ spacing = 0.0006
38
+ anomalies_options = ['None', 'Sensor Fault', 'Overheat', 'Power Surge']
39
+ anomaly_weights = [0.6, 0.2, 0.1, 0.1]
40
+
41
+ for i in range(POLES_PER_SITE):
42
+ lat = center_lat + random.uniform(-0.0002, 0.0002)
43
+ lon = center_lon + (i - POLES_PER_SITE // 2) * spacing
44
+ alert_level = random.choices(['Green', 'Yellow', 'Red'], weights=[6, 4, 2])[0]
45
+ anomaly = random.choices(anomalies_options, weights=anomaly_weights)[0]
46
+
47
+ poles.append({
48
+ "Pole ID": f"{site_name[:3].upper()}-{i+1:03}",
49
+ "Site": site_name,
50
+ "Latitude": lat,
51
+ "Longitude": lon,
52
+ "Alert Level": alert_level,
53
+ "Health Score": round(random.uniform(70, 100), 2),
54
+ "Power Status": random.choice(['Sufficient', 'Insufficient']),
55
+ "Camera Status": random.choice(['Online', 'Offline']),
56
+ "Location Area": area,
57
+ "Purpose": purpose,
58
+ "Anomalies": anomaly
59
+ })
60
+ return poles
61
+
62
+ # ---- Prepare Full DataFrame ----
63
+ all_poles = []
64
+ for site, details in AREA_DETAILS.items():
65
+ poles = generate_open_area_poles(site, *details['coords'], details['area_name'], details['purpose'])
66
+ all_poles.extend(poles)
67
+
68
+ df = pd.DataFrame(all_poles)
69
+
70
+ # ---- Streamlit UI ----
71
+ st.set_page_config(page_title="Smart Pole Visual Dashboard", layout="wide")
72
+ st.title("🌐 Smart Renewable Pole Monitoring Dashboard")
73
+
74
+ site = st.selectbox("πŸ“ Select a site location:", list(AREA_DETAILS.keys()))
75
+ selected = AREA_DETAILS[site]
76
+
77
+ # ---- Filtered View ----
78
+ filtered_df = df[df["Site"] == site]
79
+
80
+ # ---- Display Site Description ----
81
+ st.markdown(f"### πŸ“Œ Location: **{selected['area_name']}**")
82
+ st.markdown(f"πŸ”§ **Poles Purpose**: {selected['purpose']}")
83
+
84
+ # ---- KPI Metrics ----
85
+ col1, col2, col3 = st.columns(3)
86
+ col1.metric("Total Poles", POLES_PER_SITE)
87
+ col2.metric("πŸ”΄ Red Alerts", filtered_df[filtered_df["Alert Level"] == "Red"].shape[0])
88
+ col3.metric("πŸ“· Offline Cameras", filtered_df[filtered_df["Camera Status"] == "Offline"].shape[0])
89
+
90
+ # ---- Alert Level to Color ----
91
+ def alert_color(alert):
92
+ return {
93
+ "Green": [0, 255, 0, 160],
94
+ "Yellow": [255, 255, 0, 160],
95
+ "Red": [255, 0, 0, 160]
96
+ }[alert]
97
+
98
+ filtered_df = filtered_df.copy()
99
+ filtered_df["Color"] = filtered_df["Alert Level"].apply(alert_color)
100
+
101
+ # ---- Map Visualization ----
102
+ st.subheader("πŸ—ΊοΈ Pole Location & Health Status")
103
+ st.pydeck_chart(pdk.Deck(
104
+ initial_view_state=pdk.ViewState(
105
+ latitude=selected['coords'][0],
106
+ longitude=selected['coords'][1],
107
+ zoom=16.5,
108
+ pitch=45
109
+ ),
110
+ layers=[
111
+ pdk.Layer(
112
+ "ScatterplotLayer",
113
+ data=filtered_df,
114
+ get_position='[Longitude, Latitude]',
115
+ get_color='Color',
116
+ get_radius=30,
117
+ pickable=True
118
+ )
119
+ ],
120
+ tooltip={
121
+ "html": "<b>Pole ID:</b> {Pole ID}<br/>"
122
+ "<b>Location:</b> {Location Area}<br/>"
123
+ "<b>Purpose:</b> {Purpose}<br/>"
124
+ "<b>Health Score:</b> {Health Score}<br/>"
125
+ "<b>Alert Level:</b> {Alert Level}<br/>"
126
+ "<b>Camera:</b> {Camera Status}<br/>"
127
+ "<b>Power:</b> {Power Status}<br/>"
128
+ "<b>Anomaly:</b> {Anomalies}",
129
+ "style": {"color": "white", "backgroundColor": "black"}
130
+ }
131
+ ))
132
+
133
+ # ---- Data Table ----
134
+ st.subheader("πŸ“‹ Detailed Pole Information")
135
+ st.dataframe(filtered_df, use_container_width=True) import random
136
  import pandas as pd
137
+ import streamlit as st
138
+ import pydeck as pdk
 
 
139
 
140
+ # ---- Area-Specific Configuration ----
141
+ AREA_DETAILS = {
142
+ "Hyderabad": {
143
+ "coords": [17.4036, 78.5247],
144
+ "area_name": "Ramanthapur Dairy Farm",
145
+ "purpose": "Dairy Farm"
146
+ },
147
+ "Ballari": {
148
+ "coords": [15.1468, 76.9237],
149
+ "area_name": "Cowl Bazar Power Station",
150
+ "purpose": "Power Station"
151
+ },
152
+ "Gadwal": {
153
+ "coords": [16.2315, 77.7965],
154
+ "area_name": "Bheem Nagar Solar Station",
155
+ "purpose": "Solar Station"
156
+ },
157
+ "Kurnool": {
158
+ "coords": [15.8281, 78.0373],
159
+ "area_name": "Venkata Ramana Agriculture Field",
160
+ "purpose": "Agriculture Monitoring"
161
+ }
162
  }
163
 
164
+ POLES_PER_SITE = 12
165
+
166
+ # ---- Generate Poles with Anomalies ----
167
+ def generate_open_area_poles(site_name, center_lat, center_lon, area, purpose):
168
+ poles = []
169
+ spacing = 0.0006
170
+ anomalies_options = ['None', 'Sensor Fault', 'Overheat', 'Power Surge']
171
+ anomaly_weights = [0.6, 0.2, 0.1, 0.1]
172
+
173
+ for i in range(POLES_PER_SITE):
174
+ lat = center_lat + random.uniform(-0.0002, 0.0002)
175
+ lon = center_lon + (i - POLES_PER_SITE // 2) * spacing
176
+ alert_level = random.choices(['Green', 'Yellow', 'Red'], weights=[6, 4, 2])[0]
177
+ anomaly = random.choices(anomalies_options, weights=anomaly_weights)[0]
178
+
179
+ poles.append({
180
+ "Pole ID": f"{site_name[:3].upper()}-{i+1:03}",
181
+ "Site": site_name,
182
+ "Latitude": lat,
183
+ "Longitude": lon,
184
+ "Alert Level": alert_level,
185
+ "Health Score": round(random.uniform(70, 100), 2),
186
+ "Power Status": random.choice(['Sufficient', 'Insufficient']),
187
+ "Camera Status": random.choice(['Online', 'Offline']),
188
+ "Location Area": area,
189
+ "Purpose": purpose,
190
+ "Anomalies": anomaly
191
  })
192
+ return poles
193
 
194
+ # ---- Prepare Full DataFrame ----
195
+ all_poles = []
196
+ for site, details in AREA_DETAILS.items():
197
+ poles = generate_open_area_poles(site, *details['coords'], details['area_name'], details['purpose'])
198
+ all_poles.extend(poles)
199
 
200
+ df = pd.DataFrame(all_poles)
201
 
202
  # ---- Streamlit UI ----
203
+ st.set_page_config(page_title="Smart Pole Visual Dashboard", layout="wide")
204
+ st.title("🌐 Smart Renewable Pole Monitoring Dashboard")
205
+
206
+ site = st.selectbox("πŸ“ Select a site location:", list(AREA_DETAILS.keys()))
207
+ selected = AREA_DETAILS[site]
208
+
209
+ # ---- Filtered View ----
210
+ filtered_df = df[df["Site"] == site]
211
+
212
+ # ---- Display Site Description ----
213
+ st.markdown(f"### πŸ“Œ Location: **{selected['area_name']}**")
214
+ st.markdown(f"πŸ”§ **Poles Purpose**: {selected['purpose']}")
215
+
216
+ # ---- KPI Metrics ----
217
+ col1, col2, col3 = st.columns(3)
218
+ col1.metric("Total Poles", POLES_PER_SITE)
219
+ col2.metric("πŸ”΄ Red Alerts", filtered_df[filtered_df["Alert Level"] == "Red"].shape[0])
220
+ col3.metric("πŸ“· Offline Cameras", filtered_df[filtered_df["Camera Status"] == "Offline"].shape[0])
221
+
222
+ # ---- Alert Level to Color ----
223
+ def alert_color(alert):
224
+ return {
225
+ "Green": [0, 255, 0, 160],
226
+ "Yellow": [255, 255, 0, 160],
227
+ "Red": [255, 0, 0, 160]
228
+ }[alert]
229
+
230
+ filtered_df = filtered_df.copy()
231
+ filtered_df["Color"] = filtered_df["Alert Level"].apply(alert_color)
232
+
233
+ # ---- Map Visualization ----
234
+ st.subheader("πŸ—ΊοΈ Pole Location & Health Status")
235
+ st.pydeck_chart(pdk.Deck(
236
+ initial_view_state=pdk.ViewState(
237
+ latitude=selected['coords'][0],
238
+ longitude=selected['coords'][1],
239
+ zoom=16.5,
240
+ pitch=45
241
+ ),
242
+ layers=[
243
+ pdk.Layer(
244
+ "ScatterplotLayer",
245
+ data=filtered_df,
246
+ get_position='[Longitude, Latitude]',
247
+ get_color='Color',
248
+ get_radius=30,
249
+ pickable=True
250
+ )
251
+ ],
252
+ tooltip={
253
+ "html": "<b>Pole ID:</b> {Pole ID}<br/>"
254
+ "<b>Location:</b> {Location Area}<br/>"
255
+ "<b>Purpose:</b> {Purpose}<br/>"
256
+ "<b>Health Score:</b> {Health Score}<br/>"
257
+ "<b>Alert Level:</b> {Alert Level}<br/>"
258
+ "<b>Camera:</b> {Camera Status}<br/>"
259
+ "<b>Power:</b> {Power Status}<br/>"
260
+ "<b>Anomaly:</b> {Anomalies}",
261
+ "style": {"color": "white", "backgroundColor": "black"}
262
+ }
263
+ ))
264
+
265
+ # ---- Data Table ----
266
+ st.subheader("πŸ“‹ Detailed Pole Information")
267
+ st.dataframe(filtered_df, use_container_width=True)