Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,134 +1,82 @@
|
|
1 |
-
import random
|
2 |
-
import pandas as pd
|
3 |
import streamlit as st
|
4 |
-
import
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
# ----
|
7 |
-
|
8 |
-
"Hyderabad":
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
},
|
13 |
-
"Ballari": {
|
14 |
-
"coords": [15.1468, 76.9237],
|
15 |
-
"area_name": "Cowl Bazar Power Station",
|
16 |
-
"purpose": "Power Station"
|
17 |
-
},
|
18 |
-
"Gadwal": {
|
19 |
-
"coords": [16.2315, 77.7965],
|
20 |
-
"area_name": "Bheem Nagar Solar Station",
|
21 |
-
"purpose": "Solar Station"
|
22 |
-
},
|
23 |
-
"Kurnool": {
|
24 |
-
"coords": [15.8281, 78.0373],
|
25 |
-
"area_name": "Venkata Ramana Agriculture Field",
|
26 |
-
"purpose": "Agriculture Monitoring"
|
27 |
-
}
|
28 |
}
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
"
|
47 |
-
"
|
48 |
-
"Latitude": lat,
|
49 |
-
"Longitude": lon,
|
50 |
-
"Alert Level": alert_level,
|
51 |
-
"Health Score": round(random.uniform(70, 100), 2),
|
52 |
-
"Power Status": random.choice(['Sufficient', 'Insufficient']),
|
53 |
-
"Camera Status": random.choice(['Online', 'Offline']),
|
54 |
-
"Location Area": area,
|
55 |
-
"Purpose": purpose,
|
56 |
-
"Anomalies": anomaly
|
57 |
})
|
58 |
-
return
|
59 |
|
60 |
-
#
|
61 |
-
|
62 |
-
for
|
63 |
-
|
64 |
-
all_poles.extend(poles)
|
65 |
|
66 |
-
df = pd.DataFrame(
|
67 |
|
68 |
# ---- Streamlit UI ----
|
69 |
-
st.set_page_config(
|
70 |
-
st.title("🌐
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
# ----
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
# ----
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
st.
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
),
|
108 |
-
layers=[
|
109 |
-
pdk.Layer(
|
110 |
-
"ScatterplotLayer",
|
111 |
-
data=filtered_df,
|
112 |
-
get_position='[Longitude, Latitude]',
|
113 |
-
get_color='Color',
|
114 |
-
get_radius=30,
|
115 |
-
pickable=True
|
116 |
-
)
|
117 |
-
],
|
118 |
-
tooltip={
|
119 |
-
"html": "<b>Pole ID:</b> {Pole ID}<br/>"
|
120 |
-
"<b>Location:</b> {Location Area}<br/>"
|
121 |
-
"<b>Purpose:</b> {Purpose}<br/>"
|
122 |
-
"<b>Health Score:</b> {Health Score}<br/>"
|
123 |
-
"<b>Alert Level:</b> {Alert Level}<br/>"
|
124 |
-
"<b>Camera:</b> {Camera Status}<br/>"
|
125 |
-
"<b>Power:</b> {Power Status}<br/>"
|
126 |
-
"<b>Anomaly:</b> {Anomalies}",
|
127 |
-
"style": {"color": "white", "backgroundColor": "black"}
|
128 |
-
}
|
129 |
-
))
|
130 |
-
|
131 |
-
# ---- Data Table ----
|
132 |
-
st.subheader("📋 Detailed Pole Information")
|
133 |
-
st.dataframe(filtered_df, use_container_width=True)
|
134 |
-
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|